日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
記MySQL使用UDF自動(dòng)同步memcached的效率

MySQL可以使用MySQL的mysql-udf-http進(jìn)行效率測(cè)試 ,這次不使用rest架構(gòu),而是使用:libmemcached和memcached_functions_mysql,測(cè)試版本是:libmemcached-0.34.tar.gz和memcached_functions_mysql-0.9.tar.gz,其它版本配對(duì)都有問(wèn)題,我安裝測(cè)試過(guò)有問(wèn)題的版本有:

 
 
 
  1. memcached_functions_mysql-1.1在:  
  2. libmemcached-0.49\libmemcached-0.48\libmemcached-0.47\libmemcached-0.30\libmemcached-0.43\\libmemcached-0.42\  
  3. 下安裝有錯(cuò)誤  
  4. memcached_functions_mysql-0.10在:  
  5. libmemcached-0.42\下安裝有錯(cuò)誤  
  6. memcached_functions_mysql-0.8在:  
  7. libmemcached-0.49\libmemcached-0.48\libmemcached-0.47\libmemcached-0.44\libmemcached-0.43\  
  8. \libmemcached-0.42\下安裝有錯(cuò)誤 

MySQL測(cè)試版本:5.1.55,操作系統(tǒng)Centos5.4 64bit,內(nèi)存2G

安裝libmemcached-0.34和memcached_functions_mysql-0.9:

 
 
 
  1. [root@sunss24 libmemcached-0.34]#./configure \  
  2. --with-memcached=/home/memcache/bin/memcached  
  3. [root@sunss24 libmemcached-0. 34]# make  
  4. [root@sunss24 libmemcached-0. 34]# make install  
  5. 再運(yùn)行一下memstat,算成功了  
  6. [root@sunss24 ~]# ln -s /usr/local/lib/libmemcached.so.3 /usr/lib/  
  7. [root@sunss24 ~]# cd memcached_functions_mysql-0.9  
  8. [root@sunss24 memcached_functions_mysql-0.9]# ./configure \  
  9. --with-mysql=/usr/local/mysql/bin/mysql_config \  
  10. --libdir=/usr/local/mysql/lib/  
  11. [root@sunss memcached_functions_mysql-0.9]# make && make install 

安裝完成后將UDFs加載到MySQL中:

 
 
 
  1. mysql> show variables like "%plugin%";  
  2. +---------------+-----------------------------------+  
  3. | Variable_name | Value                             |  
  4. +---------------+-----------------------------------+  
  5. | plugin_dir    | /usr/local/mysql/lib/mysql/plugin |   
  6. +---------------+-----------------------------------+  
  7. 1 row in set (0.00 sec)  
  8. [root@sunss ~]# find / -name "libmemcached_functions_mysql.so" 
  9. /usr/local/mysql/lib/libmemcached_functions_mysql.so  
  10. /root/memcached_functions_mysql-0.9/src/.libs/libmemcached_functions_mysql.so  
  11. You have new mail in /var/spool/mail/root  
  12. [root@sunss ~]# cp /usr/local/mysql/lib/libmemcached_functions_mysql.so /usr/local/mysql/lib/mysql/plugin/  
  13. [root@sunss ~]# cd memcached_functions_mysql-0.9/  
  14. [root@sunss ~]#cd sql/  
  15. mysql> source install_functions.sql; 

查看各種版本:

 
 
 
  1. mysql> select memc_udf_version();  
  2. +--------------------+  
  3. | memc_udf_version() |  
  4. +--------------------+  
  5. | 0.9                |   
  6. +--------------------+  
  7. 1 row in set (0.00 sec)  
  8. mysql> select memc_libmemcached_version();  
  9. +-----------------------------+  
  10. | memc_libmemcached_version() |  
  11. +-----------------------------+  
  12. | 0.34                        |   
  13. +-----------------------------+  
  14. 1 row in set (0.00 sec)  
  15. mysql> 

遇到問(wèn)題:

 
 
 
  1. No package 'libmemcached' found  
  2. Consider adjusting the PKG_CONFIG_PATH environment variable if you  
  3. installed software in a non-standard prefix.  
  4. Alternatively, you may set the environment variables DEPS_CFLAGS  
  5. and DEPS_LIBS to avoid the need to call pkg-config.  
  6. See the pkg-config man page for more details.  

解決辦法:

 
 
 
  1. [root@sunss24 memcached_functions_mysql-0.9]# whereis pkgconfig  
  2. [root@sunss24 memcached_functions_mysql-0.9]# export \  
  3. PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig  

#p#

導(dǎo)出所有memcache內(nèi)容:

使用:memcached-hack.zip

效率測(cè)試:

插入:

 
 
 
  1.     include_once("gettime.php");  
  2.  
  3.     $btime = getmicrotime();  
  4.     $i = 0;   
  5.     $mem = new Memcache();  
  6.     $mem->addServer('192.168.0.10', 11212);  
  7.       
  8.     $local_db = mysql_connect("192.168.0.208", "sunss", "123456");  
  9.     if(!$local_db)  
  10.     {  
  11.         die('Could not connect: '.mysql_error());  
  12.     }  
  13.     $local_db_sel = mysql_select_db("test", $local_db);  
  14.     mysql_query("set names utf8", $local_db);  
  15.         while ( $i < 1000) {  
  16.         $re_sql = "insert into urls (id,url) values ($i, 'www.gongchang.com')";  
  17.         $res = mysql_query($re_sql, $local_db);  
  18.                 $i++;  
  19.         }   
  20.     mysql_close($local_db);  
  21.     $etime = getmicrotime();  
  22.     $runTime = round($etime - $btime, 4);  
  23.     echo "runTime: ".$runTime."\r\n";  
  24. ?> 

1000條,插入時(shí)間:runTime: 1.4072

刪除:

 
 
 
  1.     include_once("gettime.php");  
  2.  
  3.     $btime = getmicrotime();  
  4.     $i = 0;  
  5.       
  6.     $mem = new Memcache();  
  7.     $mem->addServer('192.168.0.10', 11212);  
  8.       
  9.     $local_db = mysql_connect("192.168.0.208", "sunss", "123456");  
  10.     if(!$local_db)  
  11.     {  
  12.         die('Could not connect: '.mysql_error());  
  13.     }  
  14.  
  15.  
  16.     $local_db_sel = mysql_select_db("test", $local_db);  
  17.     mysql_query("set names utf8", $local_db);  
  18.         while ( $i < 1000) {  
  19.         //$re_sql = "insert into urls (id,url) values ($i, 'www.gongchang.com')";  
  20.         $re_sql = "delete from urls where id=".$i;  
  21.         //echo "re_sql_1: ".$re_sql."\n";  
  22.                 $res = mysql_query($re_sql, $local_db);  
  23.                 $i++;  
  24.         }  
  25.  
  26.     mysql_close($local_db);  
  27.     $etime = getmicrotime();  
  28.     $runTime = round($etime - $btime, 4);  
  29.     echo "runTime: ".$runTime."\r\n";  
  30. ?>  

刪除1000條,運(yùn)行時(shí)間:runTime: 1.5534

結(jié)論:每秒
query大概650條記錄,比上次的mysql-udf-http快多了

 原文鏈接:http://www.cnblogs.com/sunss/archive/2011/06/07/2074435.html

【編輯推薦】

  1. MySQL中創(chuàng)建及優(yōu)化索引組織結(jié)構(gòu)的思路
  2. 微博 請(qǐng)問(wèn)你是怎么優(yōu)化數(shù)據(jù)庫(kù)的?
  3. MySQL技巧:結(jié)合相關(guān)參數(shù) 做好Limit優(yōu)化
  4. MySQL數(shù)據(jù)庫(kù)的優(yōu)化(下)MySQL數(shù)據(jù)庫(kù)的高可用架構(gòu)方案
  5. MySQL數(shù)據(jù)庫(kù)的優(yōu)化(上)單機(jī)MySQL數(shù)據(jù)庫(kù)的優(yōu)化

網(wǎng)頁(yè)標(biāo)題:記MySQL使用UDF自動(dòng)同步memcached的效率
新聞來(lái)源:http://www.dlmjj.cn/article/dppidej.html