上一篇BLOG介绍了使用sysbench测试mysql和postgresql的simple场景.
也就是只有select的场景, 
http://blog.163.com/digoal@126/blog/static/163877040201341441042613/
本文将介绍包含复杂查询的场景, 包含如下SQL :

 INSERT INTO sbtest(k,c,pad) values(?,?,?)SELECT c from sbtest where id=$1UPDATE sbtest set k=k+? where id=$1SELECT DISTINCT c from sbtest where id between $1 and $2 order by cSELECT c from sbtest where id between $1 and $2 order by cSELECT SUM(K) from sbtest where id between $1 and $2SELECT c from sbtest where id between $1 and $2UPDATE sbtest set c=$1 where id=$2DELETE from sbtest where id=$1
但是需要先解决一个问题, 因为sysbench对pg的支持不太好, 在插入数据时使用的是sysbench产生的值, 而不是sequence.
会产生如下错误 :

[root@db-172-16-3-33 bin]# ./sysbench --max-requests=0 --max-time=60 --num-threads=16 --test=oltp --db-driver=pgsql --pgsql-host=127.0.0.1 --pgsql-port=1999 --pgsql-user=postgres --pgsql-password=postgres --pgsql-db=postgres --oltp-test-mode=complex --oltp-reconnect-mode=session run
sysbench 0.4.12:  multi-threaded system evaluation benchmarkRunning the test with following options:
Number of threads: 16Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
FATAL: query execution failed: 145040784
FATAL: database error, exiting...
Done.

日志 :

2013-05-14 16:36:31.259 CST,"postgres","postgres",13938,"127.0.0.1:23937",5191f78f.3672,3,"INSERT",2013-05-14 16:36:31 CST,7/464628,
32112157,ERROR,23505,"duplicate key value violates unique constraint ""sbtest_pkey""","Key (id)=(5014) already exists.",,,,,"INSERT
INTO sbtest values($1,0,' ','aaaaaaaaaaffffffffffrrrrrrrrrreeeeeeeeeeyyyyyyyyyy')",,"_bt_check_unique, nbtinsert.c:398",""
产生这个错误后sysbench会直接退出. 这就无法测试了.
所以需要修改一下sysbench的代码 :

vi sysbench-0.4.12/sysbench/tests/oltp/sb_oltp.c

找到

  /* Prepare the insert statement */snprintf(query, MAX_QUERY_LEN, "INSERT INTO %s values(?,0,' ',""'aaaaaaaaaaffffffffffrrrrrrrrrreeeeeeeeeeyyyyyyyyyy')",args.table_name);

改成 :

  /* Prepare the insert statement */if (args.auto_inc)snprintf(query, MAX_QUERY_LEN, "INSERT INTO %s(k,c,pad) values(0,' ',""'aaaaaaaaaaffffffffffrrrrrrrrrreeeeeeeeeeyyyyyyyyyy')",args.table_name);elsesnprintf(query, MAX_QUERY_LEN, "INSERT INTO %s values(?,0,' ',""'aaaaaaaaaaffffffffffrrrrrrrrrreeeeeeeeeeyyyyyyyyyy')",args.table_name);
然后重新编译即可.
如何编译参考 : 
http://blog.163.com/digoal@126/blog/static/16387704020134142151769/
接下来可以使用参数--oltp-auto-inc来控制选择是否使用序列.
[测试结果]
1. PostgreSQL

[root@db-172-16-3-33 bin]# ./sysbench --oltp-auto-inc=on --max-requests=0 --max-time=60 --num-threads=16 --test=oltp --db-driver=pgsql --pgsql-host=127.0.0.1 --pgsql-port=1999 --pgsql-user=postgres --pgsql-password=postgres --pgsql-db=postgres --oltp-test-mode=complex --oltp-reconnect-mode=session run
sysbench 0.4.12:  multi-threaded system evaluation benchmarkRunning the test with following options:
Number of threads: 16Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 15 times)
Done.OLTP test statistics:queries performed:read:                            4328002write:                           1545715other:                           618286total:                           6492003transactions:                        309143 (5152.10 per sec.)deadlocks:                           0      (0.00 per sec.)read/write requests:                 5873717 (97889.81 per sec.)other operations:                    618286 (10304.19 per sec.)Test execution summary:total time:                          60.0034stotal number of events:              309143total time taken by event execution: 956.5899per-request statistics:min:                                  1.34msavg:                                  3.09msmax:                                179.74msapprox.  95 percentile:               8.93msThreads fairness:events (avg/stddev):           19321.4375/325.75execution time (avg/stddev):   59.7869/0.02

2. MySQL

[root@db-172-16-3-33 bin]# ./sysbench --oltp-auto-inc=off --max-requests=0 --max-time=60 --num-threads=16 --test=oltp --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=root --mysql-db=test --oltp-test-mode=complex --oltp-reconnect-mode=session run
sysbench 0.4.12:  multi-threaded system evaluation benchmarkRunning the test with following options:
Number of threads: 16Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Not using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 15 times)
Done.OLTP test statistics:queries performed:read:                            1380960write:                           493088other:                           197237total:                           2071285transactions:                        98597  (1643.12 per sec.)deadlocks:                           43     (0.72 per sec.)read/write requests:                 1874048 (31231.08 per sec.)other operations:                    197237 (3286.96 per sec.)Test execution summary:total time:                          60.0059stotal number of events:              98597total time taken by event execution: 958.6545per-request statistics:min:                                  2.30msavg:                                  9.72msmax:                                204.51msapprox.  95 percentile:              26.08msThreads fairness:events (avg/stddev):           6162.3125/43.34execution time (avg/stddev):   59.9159/0.00

[参考]
1. Install SysBench support MySQL and PostgreSQL
http://blog.163.com/digoal@126/blog/static/16387704020134142151769/
2. USE SysBench test Mysql and PostgreSQL - 1
http://blog.163.com/digoal@126/blog/static/163877040201341441042613/
3. http://wiki.bazaar.canonical.com/DistroDownloads#CentOS.2FRHEL
4. http://www.percona.com/docs/wiki/benchmark:sysbench:olpt.lua
5. http://wiki.gentoo.org/wiki/Sysbench
6. https://launchpad.net/sysbench

USE SysBench test Mysql and PostgreSQL - 2相关推荐

  1. Install SysBench support MySQL and PostgreSQL

    [测试环境] CentOS 5.7 x64 [安装MySQL] 1. 下载Mysql Red Hat & Oracle Linux 5 (x86, 64-bit), RPM Package M ...

  2. 使用sysbench对mysql压力测试

    sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.关于这个项目的详细介绍请看:https://github.com/akopytov/sy ...

  3. 通过mysqlslap与sysbench对MySQL进行压测

    介绍 mysqlslap是mysql自带的基准测试工具,该工具查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出查询更新,给出了性能测试数据而且提供了多种引擎的性能比较. ...

  4. 使用sysbench对mysql进行基准测试

    文章目录 测试环境说明 硬件 软件 测试过程 1. 测试innodb 100w条记录的读写性能 1.1 生成100w数据 1.2 进行读写测试 1.2.1 第一次直接执行100w次读写 1.2.2 第 ...

  5. 在MySQL和PostgreSQL之外,为什么阿里要研发HybridDB数据库?

    编者按 \\ 在大数据火遍IT界之前,大家对数据信息的挖掘通常聚焦在BI(Business Intelligence)之上.BI具有着明确的分析需求,清晰地知道需要处理哪些信息,并且如何最终获得多维度 ...

  6. MySQL和PostgreSQL数据库安全配置

    shewey · 2016/05/26 16:40 0x00 MySQL和PostgreSQL安全配置 针对开源数据库MySQL和PostgreSQL的安全配置主要主要通过身份鉴别.访问控制.安全审计 ...

  7. 微软宣布MySQL和PostgreSQL的Azure数据库服务正式可用

    \ 看新闻很累?看技术新闻更累?试试下载InfoQ手机客户端,每天上下班路上听新闻,有趣还有料! \ \\ 微软宣布MySQL和PostgreSQL的Azure数据库服务正式可用.Azure将这两个开 ...

  8. golang beego orm mysql sqlite3 postgresql 模型字段 数据库类型 对应关系

    目录 MySQL Sqlite3 PostgreSQL 关系型字段 在此列出 ORM 推荐的对应数据库类型,自动建表功能也会以此为标准. 默认所有的字段都是 NOT NULL MySQL go mys ...

  9. sysbench mysql测试_使用sysbench对MySQL进行测试

    为什么要测试,测什么东西? 测试的种类非常多,测试的目的也非常多,我这里主要的目的就两个 测试MySQL的极限IO 对比不同版本MySQL,不同参数, 不同硬件,不同系统对MySQL的性能影响 为什么 ...

最新文章

  1. c语言单链表需要头结点,一个关于C语言链表头结点的问题
  2. php表单登录跳转页面跳转页面,form表单页面跳转方式提交练习
  3. c语言程序设计B试题,c语言程序设计期末试题B(含答案)Word版
  4. html jq移到出现内容,jquery操作html元素之( 获得内容和属性)
  5. java比较时间sql_如何正确比较日期 java.sql.Date
  6. 思科光传输功率查询_常见的6款40G QSFP+光模块型号介绍及应用
  7. Eclipse开发工具之崩溃和备份
  8. window 快捷键使用 + idear 编辑器使用
  9. Native Crash 分析
  10. 安卓开发笔记(二十二):读取本地(内置)html文件并实现和Javascript交互
  11. 设计模式学习笔记——桥接(Bridge)模式
  12. 微软宣布已获批:重新向华为出口软件!
  13. 互联网高并发之Hystrix实现服务隔离和降级
  14. 《『若水新闻』客户端开发教程》——07.升级新闻内容UI
  15. 力扣-240 搜索二维矩阵 II
  16. IT项目经验和难点分享
  17. LINQ Enumerable 续 II
  18. 火车票售票系统需求分析
  19. 【5G之道】第二十三章:5G无线接入
  20. Thinkpad E430C 跳过电池检测更新bios

热门文章

  1. [Java]Stack栈和Heap堆的区别(终结篇)[转]
  2. LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。...
  3. POJ-3414 Pots BFS+记忆路径
  4. SQL Server 2008中原生的分层数据类型:hierarchyid
  5. LR学习笔记三 之 界面分析
  6. [转] HOWTO:使ASP.NET网站Forms验证可以指定多个登录页面
  7. IT工程师实战英语之一
  8. 怎么改善现有网站为xhtml+CSS
  9. c语言x1=abc什么意思,c语言起步(课件)2.1
  10. python 词云_利用Python生成词云