服务器性能,数据库压测工具sysbench

sysbench@TOC

服务器性能,数据库压测工具sysbench

安装sysbench

  1. sudo apt -y install sysbench;
    sysbench --help命令执行成功表示安装成功
  2. 下载测试脚本;
    wget https://github.com/akopytov/sysbench/archive/1.0.15.zip
    如果命令执行不成功,可以把网址用浏览器打开,浏览器会自动下载

测试命令

往mysql写入数据:sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-db=test --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=4000 --mysql-user=root --mysql-password= --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 prepare

执行压测:sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-db=test --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=4000 --mysql-user=root --mysql-password= --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 run >> …/mysql_sysbench_10.log

清理数据:sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 --mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock cleanup

测试结果:
Running the test with following options:
Number of threads: 1
Report intermediate results every 10 second(s)
Initializing random number generator from current time

Initializing worker threads…

Threads started!

[ 10s ] thds: 1 tps: 27.38 qps: 548.75 (r/w/o: 384.38/109.51/54.85) lat (ms,95%): 116.80 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 1 tps: 56.84 qps: 1136.70 (r/w/o: 795.69/227.34/113.67) lat (ms,95%): 23.10 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 1 tps: 60.70 qps: 1214.74 (r/w/o: 850.13/243.21/121.40) lat (ms,95%): 24.38 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 1 tps: 49.60 qps: 991.31 (r/w/o: 694.11/198.00/99.20) lat (ms,95%): 31.94 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 1 tps: 60.00 qps: 1199.21 (r/w/o: 839.20/240.00/120.00) lat (ms,95%): 22.28 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 1 tps: 55.70 qps: 1114.97 (r/w/o: 780.78/222.79/111.40) lat (ms,95%): 28.16 err/s: 0.00 reconn/s: 0.00
[ 70s ] thds: 1 tps: 56.40 qps: 1127.82 (r/w/o: 789.42/225.60/112.80) lat (ms,95%): 26.20 err/s: 0.00 reconn/s: 0.00
[ 80s ] thds: 1 tps: 61.20 qps: 1223.96 (r/w/o: 856.77/244.79/122.40) lat (ms,95%): 20.00 err/s: 0.00 reconn/s: 0.00
[ 90s ] thds: 1 tps: 44.20 qps: 884.22 (r/w/o: 619.01/176.80/88.40) lat (ms,95%): 30.81 err/s: 0.00 reconn/s: 0.00
[ 100s ] thds: 1 tps: 54.10 qps: 1081.98 (r/w/o: 757.39/216.40/108.20) lat (ms,95%): 24.83 err/s: 0.00 reconn/s: 0.00
[ 110s ] thds: 1 tps: 55.70 qps: 1114.01 (r/w/o: 779.80/222.80/111.40) lat (ms,95%): 22.69 err/s: 0.00 reconn/s: 0.00
[ 120s ] thds: 1 tps: 58.50 qps: 1169.97 (r/w/o: 818.98/233.99/117.00) lat (ms,95%): 23.52 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 89656
write: 25616
other: 12808
total: 128080
transactions: 6404 (53.36 per sec.)
queries: 128080 (1067.25 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)

General statistics:
total time: 120.0077s
total number of events: 6404

Latency (ms):
min: 11.86
avg: 18.73
max: 619.98
95th percentile: 26.20
sum: 119955.66

Threads fairness:
events (avg/stddev): 6404.0000/0.00
execution time (avg/stddev): 119.9557/0.00

sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3)

生成csv对比文件
线程数+qps : cat mysql_sysbench_*.log | egrep " cat|threads:|queries:" | tr -d “\n” | sed ‘s/Number of threads: /\n/g’ | sed ‘s/[/\n/g’ | sed ‘s/[A-Za-z/]{1,}: //g’| sed ‘s/ .//g’ | awk {'print $1 KaTeX parse error: Expected 'EOF', got '}' at position 3: 3'}̲ | sed 's/(/,/g…’ |sed ‘1i threads,cstat_on_qps’ > cstat_on_qps.csv

线程数+qps+耗时 : cat mysql_sysbench_*.log | egrep " cat|threads:|queries:|percentile:" | tr -d “\n” | sed ‘s/Number of threads: /\n/g’ | sed ‘s/[/\n/g’ | sed ‘s/[A-Za-z/]{1,}😕/g’| sed ‘s/ .//g’ | awk {'print $1 $3 $5 KaTeX parse error: Expected 'EOF', got '}' at position 3: 7'}̲| sed 's/(/,/g'…’ |sed ‘1i threads,cstat_on_qps,costtime’

脚本使用简介: /******************************************************************************** void tcc_tell_user(long len,const char *fmt,...) void tcc_init_stochastic() int tcc_produce_stochastic(int a,int b) tcc_sscanf tcc_sprintf tcc_strcpy tcc_strcmp tcc_strstr tcc_strcat tcc_memcpy tcc_memcmp tcc_memset tcc_strlen tcc_malloc tcc_free *********************************************************************************/ void get_hex_string(unsigned char *in_dat,int in_len,char *ou_hex) { int i; char *t=(char*)tcc_malloc(8); ou_hex[0]=0; for(i=0;i<in_len;i++) { if(i%0x04==0 && i!=0) tcc_strcat(ou_hex," "); if(i%0x10==0 && i!=0) tcc_strcat(ou_hex,"\n"); tcc_sprintf(t,"X ",in_dat[i]); tcc_strcat(ou_hex,t); } tcc_free(t); } void msg_init() { // tcc_init_stochastic(); } void *msg_short_connect_form_data(long t,long s,long c,long *len) { char *data=(char*)tcc_malloc(128); *len=128; *(long*)(data+0x00)=128; *(long*)(data+0x04)=1; *(long*)(data+0x08)=0; *(long*)(data+0x0C)=0; int n=tcc_produce_stochastic(100,50000); tcc_sprintf(data+0x10,"hello%d",n); tcc_strcpy(data+0x20,"123456"); return data; } int msg_short_connect_recv_data(long s,long c,void *dat,long len) { unsigned char *ou_dat=(unsigned char*)tcc_malloc(5120); get_hex_string(dat,len,ou_dat); tcc_tell_user(5120,"s:%d c:%d len:%d\n%s\n\n",s,c,len,ou_dat); tcc_free(ou_dat); return 1; } void *msg_long_connect_form_data(long op,long s,long c,long *len) { char *data=(char*)tcc_malloc(128); *len=128; *(long*)(data+0x00)=128; *(long*)(data+0x04)=1; *(long*)(data+0x08)=0; *(long*)(data+0x0C)=0; int n=tcc_produce_stochastic(100,50000); tcc_sprintf(data+0x10,"hello%d",n); tcc_strcpy(data+0x20,"123456"); return data; } int msg_long_connect_recv_data(long s,long c,void *dat,long len) { unsigned char *ou_dat=(unsigned char*)tcc_malloc(5120); get_hex_string(dat,len,ou_dat); tcc_tell_user(5120,"s:%d c:%d len:%d\n%s\n\n",s,c,len,ou_dat); tcc_free(ou_dat); return 1; } void msg_free_data(void *arg) { tcc_free(arg); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值