Mac 使用ab性能測試工具

Mac 使用ab命令進行壓測

1.在Mac中配置Apacheweb

①啓動Apache,打開終端apache

sudo apachectl -v

以下顯示Apache的版本瀏覽器

sudo apachectl start

這樣Apache就啓動了。打開Safari瀏覽器地址欄輸入 「http://localhost」,能夠看到內容爲「It works!」的頁面服務器

②設置虛擬端終機併發

打開Apache的配置文件ide

sudo vi /etc/apache2/httpd.conf

在httpd.conf中找到「#Include /private/etc/apache2/extra/httpd-vhosts.conf」,去掉前面的「#」,保存並退出,去掉這一行的#意思是從/extra/httpd-vhosts.conf這個文件導入虛擬主機配置。3d

#Include /private/etc/apache2/extra/httpd-vhosts.conf

而後重啓Apacherest

sudo apachectl restart

運行以下命令:code

sudo vi /etc/apache2/extra/httpd-vhosts.conf

就打開了配置虛擬主機文件httpd-vhost.conf,配置虛擬主機了。須要注意的是該文件默認開啓了兩個做爲例子的虛擬主機:blog

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>

須要增長以下配置:

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost
    ErrorLog "/private/var/log/apache2/localhost-error_log"
    CustomLog "/private/var/log/apache2/localhost-access_log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/snandy/work"
    ServerName mysites
    ErrorLog "/private/var/log/apache2/sites-error_log"
    CustomLog "/private/var/log/apache2/sites-access_log" common
<Directory />
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order deny,allow
            Allow from all
  </Directory>
</VirtualHost>

保存並退出

:wq
sudo apachectl restart

2.配置完成以後進行壓測

ab -n 4 -c 2 https://www.baidu.com/

-n後面的是請求數

-c後面的是併發數

①Requests per second 吞吐率

計算公式:總請求數/處理完成這些請求數所花費的時間,即
Request per second=Complete requests/Time taken for tests

②Concurrency Level 併發用戶數

要注意區分這個概念和併發鏈接數之間的區別,一個用戶可能同時會產生多個會話,也即鏈接數。在HTTP/1.1下,IE7支持兩個併發鏈接,IE8支持6個併發鏈接,FireFox3支持4個併發鏈接,因此相應的,咱們的併發用戶數就得除以這個基數。

③Time per request 用戶平均請求等待時間

計算公式:處理完成全部請求數所花費的時間/(總請求數/併發用戶數),即:
Time per request=Time taken for tests/(Complete requests/Concurrency Level)

④Time per request:across all concurrent requests 服務器平均請求等待時間

計算公式:處理完成全部請求數所花費的時間/總請求數,即: Time taken for/testsComplete requests

相關文章
相關標籤/搜索