首页 技术 正文
技术 2022年11月20日
0 收藏 641 点赞 3,875 浏览 3808 个字

  虽然经过研究发现TCMalloc不适合我们现有的游戏框架,但意外收获发现TCMalloc可以大幅度提高MYSQL 性能及内存占用,这里给出配置及测试的结果:

1.配置

关于TCMalloc的安装,在《Google perftools 安装手记(TCMalloc)》 一文中已经详细给出,下面给出将TCMalloc配置到MYSQL的步骤:

1.1 修改MySQL启动脚本(依据MySQL安装位置):

 vi /usr/local/mysql/bin/mysqld_safe
  在# executing mysqld_safe的下一行,添加:
 export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
 保存退出,并重启MySQL

1.2 依据lsof验证命令查看TCMalloc是否起效:

 # lsof |grep -i libtcmalloc.so
 如果发现以下信息,说明tcmalloc已经起效:
 mysqld     mysql  mem    REG  ,       /usr/local/lib/libtcmalloc.so.4.1.

2.性能测试工具sysbench

sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。以下操作都将以支持MySQL数据库为例进行。sourceforge已挂,下载地址:http://download.csdn.net/detail/chen19870707/8060033,安装步骤如下:

 tar zxf sysbench-0.4..tar.gz
cd sysbench-0.4.
./configure && make && make install
strip /usr/local/bin/sysbench

  选项说明参考:http://www.cnblogs.com/zhoujinyi/archive/2013/04/19/3029134.html

3.性能分析:

  数据准备:

 sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size= --max-requests= --num-threads= --mysql-host=127.0.0.1 --mysql-port= --mysql-user=root --mysql-password=root --mysql-db=test --mysql-socket=/tmp/mysql.sock prepare

  性能测试:

 sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size= --max-requests= --num-threads= --mysql-host=127.0.0.1  --mysql-port= --mysql-user=root --mysql-password=root --mysql-db=test --mysql-socket=/tmp/mysql.sock run >> report.txt

  数据清理:

 /usr/local/bin/sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size= --max-requests= --num-threads= --mysql-host=127.0.  --mysql-port= --mysql-user=root --mysql-password=root --mysql-db=test --mysql-socket=/tmp/mysql.sock cleanup

  参数说明:

 --oltp-table-size=N         测试表的记录数。默认是10000 --max-requests=N           limit for total number of requests [] #请求的最大数目。默认为10000,0代表不限制。
--max-requests=N limit for total number of requests [] #请求的最大数目。默认为10000,0代表不限制。
--num-threads=N number of threads to use [] #创建测试线程的数目。默认为1.
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=N MySQL server port []
--mysql-password=STRING MySQL password []
--mysql-db=STRING MySQL database name [sbtest]
--mysql-socket=STRING MySQL socket

  测试结果:

未使用TCMalloc

OLTP test statistics: 
    queries performed: 
        read:                            140112 
        write:                           50019 
        other:                           20008 
        total:                           210139 
    transactions:                        10000  (756.11 per sec.) 
    deadlocks:                           8      (0.60 per sec.) 
    read/write requests:                 190131 (14376.02 per sec.) 
    other operations:                    20008  (1512.83 per sec.)

Test execution summary: 
    total time:                          13.2256s 
    total number of events:              10000 
    total time taken by event execution: 211.4342 
    per-request statistics: 
         min:                                  2.96ms 
         avg:                                 21.14ms 
         max:                                423.52ms 
         approx.  95 percentile:     56.25ms

使用TCMalloc

OLTP test statistics: 
    queries performed: 
        read:                            140084 
        write:                           50017 
        other:                           20006 
        total:                           210107 
    transactions:                        10000  (862.83 per sec.) 
    deadlocks:                           6      (0.52 per sec.) 
    read/write requests:                 190101 (16402.39 per sec.) 
    other operations:                    20006  (1726.17 per sec.)

Test execution summary: 
    total time:                          11.5898s 
    total number of events:              10000 
    total time taken by event execution: 185.2397 
    per-request statistics: 
         min:                                  2.81ms 
         avg:                                 18.52ms 
         max:                                430.03ms 
         approx.  95 percentile:              36.49ms

可以看到使用TCMalloc性能明显优于未使用,这里主要原因是mysql是多线程小内存分配,TCMalloc由于每个线程均有线程缓冲区,所以对这样的小对象分配无竞争,效率非常好,可以看到TCMalloc对MYSQL优化效果不错 ,建议使用。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,040
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,526
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,374
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,154
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,787
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,869