记MySQL使用UDF自动同步memcached的效率

数据库 MySQL
MySQL可以使用mysql-udf-http进行效率测试 ,这次不使用rest架构,而是使用:libmemcached和memcached_functions_mysql,测试版本是:libmemcached-0.34.tar.gz和memcached_functions_mysql-0.9.tar.gz

MySQL可以使用MySQL的mysql-udf-http进行效率测试 ,这次不使用rest架构,而是使用:libmemcached和memcached_functions_mysql,测试版本是:libmemcached-0.34.tar.gz和memcached_functions_mysql-0.9.tar.gz,其它版本配对都有问题,我安装测试过有问题的版本有:

  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. 下安装有错误  
  4. memcached_functions_mysql-0.10在:  
  5. libmemcached-0.42\下安装有错误  
  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\下安装有错误 

MySQL测试版本:5.1.55,操作系统Centos5.4 64bit,内存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. 再运行一下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> 

遇到问题:

  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#

导出所有memcache内容:

使用:memcached-hack.zip

效率测试:

插入:

  1. <?php  
  2.     include_once("gettime.php");  
  3.  
  4.     $btime = getmicrotime();  
  5.     $i = 0;   
  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.     $local_db_sel = mysql_select_db("test"$local_db);  
  15.     mysql_query("set names utf8"$local_db);  
  16.         while ( $i < 1000) {  
  17.         $re_sql = "insert into urls (id,url) values ($i, 'www.gongchang.com')";  
  18.         $res = mysql_query($re_sql$local_db);  
  19.                 $i++;  
  20.         }   
  21.     mysql_close($local_db);  
  22.     $etime = getmicrotime();  
  23.     $runTime = round($etime - $btime, 4);  
  24.     echo "runTime: ".$runTime."\r\n";  
  25. ?> 

1000条,插入时间:runTime: 1.4072

删除:

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

删除1000条,运行时间:runTime: 1.5534

结论:每秒query大概650条记录,比上次的mysql-udf-http快多了

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

【编辑推荐】

  1. MySQL中创建及优化索引组织结构的思路
  2. 微博 请问你是怎么优化数据库的?
  3. MySQL技巧:结合相关参数 做好Limit优化
  4. MySQL数据库的优化(下)MySQL数据库的高可用架构方案
  5. MySQL数据库的优化(上)单机MySQL数据库的优化

 

责任编辑:艾婧 来源: sunss的博客
相关推荐

2011-06-20 10:35:29

MySQL

2011-09-15 09:33:20

自动监控MySQL同步

2021-08-27 10:21:43

SubSync开源

2021-03-31 07:39:18

pythonHIVEUDF函数

2010-05-19 10:22:07

2011-03-22 09:07:13

Nagios监控memcached

2012-05-10 10:20:04

memcached缓存

2010-05-31 16:46:40

2023-05-31 08:56:24

2023-04-13 12:00:00

MySQLSQL线程

2023-08-29 07:22:06

MySQL数据工具故障恢复

2010-05-31 14:32:44

SVN自动同步

2023-11-27 18:01:17

MySQL技巧

2011-06-28 08:32:40

MySQL慢查询日志

2021-09-02 10:44:28

物联网制造自动化人工智能

2011-08-02 18:19:01

2011-07-27 17:22:10

mysql极限测试索引

2011-04-14 11:14:21

OracleNoSQLMySQL

2009-06-28 22:55:00

SAN惠普存储

2022-08-18 08:24:19

Mysql数据库
点赞
收藏

51CTO技术栈公众号