1、测试在大并发的请求mutex的时候,系统的性能
2、测试环境,虚拟机4线程,PC服务器96线程
-
root@pm1:/root# cat /proc/cpuinfo |grep "model name"
-
model name : Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz
-
model name : Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz
-
model name : Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz
-
model name : Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz
-
[root@ ~]# cat /proc/cpuinfo |grep "model name"
-
model name : Intel(R) Xeon(R) CPU E7-4860 v2 @ 2.60GHz
-
model name : Intel(R) Xeon(R) CPU E7-4860 v2 @ 2.60GHz
-
model name : Intel(R) Xeon(R) CPU E7-4860 v2 @ 2.60GHz
-
model name : Intel(R) Xeon(R) CPU E7-4860 v2 @ 2.60GHz
-
model name : Intel(R) Xeon(R) CPU E7-4860 v2 @ 2.60GHz
-
................................................
3、运行测试
虚拟机环境使用最大4线程
-
root@pm1:/root# sysbench --test=mutex --num-threads=4 --mutex-num=2000 --mutex-locks=10000 --mutex-loops=5000 run
-
sysbench 0.5: multi-threaded system evaluation benchmark
-
-
Running the test with following options:
-
Number of threads: 4
-
Random number generator seed is 0 and will be ignored
-
-
-
Threads
-
-
-
General statistics:
-
total time: 0.0060s
-
total number of events: 4
-
total time taken by event execution: 0.0144s
-
response time:
-
min: 0.72ms
-
avg: 3.61ms
-
max: 5.75ms
-
approx. 95 percentile: 5.75ms
-
-
Threads fairness:
-
events (avg/stddev): 1.0000/0.00
-
execution time (avg/stddev): 0.0036/0.00
PC服务器使用4线程
-
[root@ ~]# sysbench --test=mutex --num-threads=4 --mutex-num=2000 --mutex-locks=10000 --mutex-loops=5000 run
-
sysbench 0.5: multi-threaded system evaluation benchmark
-
-
Running the test with following options:
-
Number of threads: 4
-
Random number generator seed is 0 and will be ignored
-
-
-
Threads
-
-
-
General statistics:
-
total time: 0.0210s
-
total number of events: 4
-
total time taken by event execution: 0.0819s
-
response time:
-
min: 19.42ms
-
avg: 20.49ms
-
max: 20.93ms
-
approx. 95 percentile: 20.94ms
-
-
Threads fairness:
-
events (avg/stddev): 1.0000/0.00
-
execution time (avg/stddev): 0.0205/0.00
对比上面的结果,mutex跟线程数的多少没有关系,而是与CPU主频有关系
下面在看一组96线程的mutex竞争
-
[root@ ~]# sysbench --test=mutex --num-threads=96 --mutex-num=2000 --mutex-locks=10000 --mutex-loops=5000 run
-
sysbench 0.5: multi-threaded system evaluation benchmark
-
-
Running the test with following options:
-
Number of threads: 96
-
Random number generator seed is 0 and will be ignored
-
-
-
Threads
-
-
-
General statistics:
-
total time: 0.5325s
-
total number of events: 96
-
total time taken by event execution: 48.1514s
-
response time:
-
min: 428.05ms
-
avg: 501.58ms
-
max: 532.18ms
-
approx. 95 percentile: 530.29ms
-
-
Threads fairness:
-
events (avg/stddev): 1.0000/0.00
-
execution time (avg/stddev): 0.5016/0.02
用满线程数测试mutex反而更慢了,也就是说mutex的竞争与线程是没有关系的
在看下系统CPU信息,是4个物理CPU,12核,96线程的机器
-
[root@ ~]# grep "core id" /proc/cpuinfo | sort -u | wc -l
-
12
-
[root@ ~]# grep "physical id" /proc/cpuinfo | sort -u | wc -l
-
4
-
[root@ ~]# grep "processor" /proc/cpuinfo | sort -u | wc -l
-
96
综上,mutex请求的性能与CPU主频及物理CPU个数有关
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12219480/viewspace-1749359/
,如需转载,请注明出处,否则将追究法律责任。