使用ab测试工具+top命令查看服务器负载状态

ab测试工具

单独安装Apache-tools


yum -y install httpd-tools


ab -n 10000 -c 100 https://baidu.com/   #表示同时100个客户端请求10000次 url地址最后 /不可省

查看结果

usr/bin/ab
[root@iZwz94xp1kwkcai596bmwcZ ~]# ab -n 10000 -c 100 https://baidu.com/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking baidu.com (be patient)
Completed 1000 requests    #完成的请求数
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        bfe/1.0.8.18    #百度的负债均衡,负责转发
Server Hostname:        baidu.com
Server Port:            443                    #ssl 默认端口
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128

Document Path:          /      #请求地址
Document Length:        161 bytes

Concurrency Level:      100
Time taken for tests:   102.108 seconds
Complete requests:      10000    #完成请求总数
Failed requests:        0                #失败请求总数
Write errors:           0                  
Non-2xx responses:      10000
Total transferred:      3520000 bytes
HTML transferred:       1610000 bytes
Requests per second:    97.94 [#/sec] (mean)    #QPS并发数,数值越高,性能越强大
Time per request:       1021.077 [ms] (mean)
Time per request:       10.211 [ms] (mean, across all concurrent requests)
Transfer rate:          33.67 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      113  737 2808.6    127   94247
Processing:    37   61 283.1     39   24128
Waiting:       37   61 283.1     38   24128
Total:        150  797 2845.3    174   94285

Percentage of the requests served within a certain time (ms)
  50%    174
  66%    402
  75%    630
  80%    648
  90%   1156
  95%   2096
  98%   4173
  99%  10180
 100%  94285 (longest request)

在做ab压力测试时,我们使用top命令查看服务器的状态

top
top - 18:18:07 up 1 day,  7:38,  1 user,  load average: 0.00, 0.01, 0.05
Tasks:  92 total,   1 running,  91 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.3 sy,  0.0 ni, 99.0 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1016396 total,    68024 free,   448668 used,   499704 buff/cache
KiB Swap:  1049596 total,  1049596 free,        0 used.   393776 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                          
  432 root      20   0  742068  20736   5844 S  0.7  2.0   2:19.34 CmsGoAgent.linu                  
    1 root      20   0   43312   3236   2020 S  0.0  0.3   0:01.73 systemd                          
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd                         
    3 root      20   0       0      0      0 S  0.0  0.0   0:02.20 ksoftirqd/0                      
    5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H                     
    6 root      20   0       0      0      0 S  0.0  0.0   0:00.91 kworker/u2:0                     
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0                      
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh                           
    9 root      20   0       0      0      0 S  0.0  0.0   0:13.83 rcu_sched                        
   10 root      rt   0       0      0      0 S  0.0  0.0   0:00.45 watchdog/0                       
   12 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs                        
   13 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns                            
   14 root      20   0       0      0      0 S  0.0  0.0   0:00.02 khungtaskd                       
   15 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback                        
   16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd                      
   17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset                           
   18 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kblockd                          
   19 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 md                               
   25 root      20   0       0      0      0 S  0.0  0.0   0:00.32 kswapd0                          
   26 root      25   5       0      0      0 S  0.0  0.0   0:00.00 ksmd                             
   27 root      39  19       0      0      0 S  0.0  0.0   0:00.44 khugepaged                       
   28 root      20   0       0      0      0 S  0.0  0.0   0:00.00 fsnotify_mark

参数说明

total 进程总数
running 正在运行的进程数
sleeping 睡眠的进程数
stopped 停止的进程数
zombie 僵尸进程数
Cpu(s): 
0.3% us 用户空间占用CPU百分比
1.0% sy 内核空间占用CPU百分比
0.0% ni 用户进程空间内改变过优先级的进程占用CPU百分比
98.7% id 空闲CPU百分比
0.0% wa 等待输入输出的CPU时间百分比
0.0%hi:硬件CPU中断占用百分比
0.0%si:软中断占用百分比
0.0%st:虚拟机占用百分比

总结:
影响服务器性能的原因很多,但是提升性能最基本可以做的有几点:
1、一个服务器只运行单一的服务,比如说,单独服务器运行PHP,单独服务器运行mysql、单独服务器运行Nginx或负载均衡。
2、服务器分布式
3、使用多线程

你可能感兴趣的:(使用ab测试工具+top命令查看服务器负载状态)