Mac 使用ab性能測試工具


Mac 使用ab命令進行壓測

1.在Mac中配置Apache

①啟動Apache,打開終端

 sudo apachectl -v

如下顯示Apache的版本

sudo apachectl start

這樣Apache就啟動了。打開Safari瀏覽器地址欄輸入 “http://localhost”,可以看到內容為“It works!”的頁面

②設置虛擬端終機

打開Apache的配置文件

sudo vi /etc/apache2/httpd.conf

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

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

然后重啟Apache

sudo apachectl restart

運行如下命令:

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

就打開了配置虛擬主機文件httpd-vhost.conf,配置虛擬主機了。需要注意的是該文件默認開啟了兩個作為例子的虛擬主機:

<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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM