补充知识:
  查看CPU核数的方法
  查看物理cpu个数
  grep "physical id" /proc/cpuinfo | sort -u | wc -l
  查看核心数量
  grep "core id" /proc/cpuinfo | sort -u | wc -l
  查看线程数量
  grep "processor" /proc/cpuinfo | sort -u | wc -l
  在sysbench的测试中,--num-threads取值为"线程数量"即可,再大的值没有什么意义,对测试结果也没有什么影响。
  3.2 线程(thread)测试
  测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用。
  sysbench --test=threads --num-threads=64 run
  下面是输出结果:

 

Number of threads: 64
Doing thread subsystem performance test
Thread yields per test: 1000 Locks used: 8
Threads started!
Done.
Test execution summary:
total time: 4.5845s
total number of events: 10000
total time taken by event execution: 291.9995
per-request statistics:
min: 0.76ms
avg: 29.20ms
max: 152.71ms
approx. 95 percentile: 71.11ms
Threads fairness:
events (avg/stddev): 156.2500/5.81
execution time (avg/stddev): 4.5625/0.02

  说实话,我也不怎么会分析这个测试结果,网上搜了半天也没有搜到,几乎所有的资料都是简单的罗列出测试结果, 也不告诉我们应该怎么分析,实在是太不照顾新手了。 我自己是通过(total time:)判断线程调度的性能的,下面是我在服务器上运行这个测试的输出:

 

Number of threads: 64
Doing thread subsystem performance test
Thread yields per test: 1000 Locks used: 8
Threads started!
Done.
Test execution summary:
total time: 2.4829s
total number of events: 10000
total time taken by event execution: 157.3468
per-request statistics:
min: 0.21ms
avg: 15.73ms
max: 166.69ms
approx. 95 percentile: 119.14ms
Threads fairness:
events (avg/stddev): 156.2500/22.25
execution time (avg/stddev): 2.4585/0.02

  可以看到total time 比在我自己电脑上少了一半,服务器的线程调度肯定比普通电脑快多了。

  3.3 互斥锁(mutex)
  测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁。
  sysbench --test=mutex --num-threads=16 --mutex-num=2048
  --mutex-locks=1000000 --mutex-loops=5000 run
  输出结果如下:

 

Number of threads: 16
Doing mutex performance test
Threads started!
Done.
Test execution summary:
total time: 3.6123s
total number of events: 16
total time taken by event execution: 57.6636
per-request statistics:
min: 3580.79ms
avg: 3603.98ms
max: 3610.94ms
approx. 95 percentile: 10000000.00ms
Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 3.6040/0.01