1.在Mac中配置Apache
1.1 啓動Apache,打開終端
sudo apachectl -v
如下顯示Apache的版本
sudo apachectl start
這樣Apache就啓動了。
打開瀏覽器地址欄輸入 :
http://localhost
可以看到內容爲“It works!”的頁面。
表示工作正常。
1.2 設置虛擬端終機
打開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 [email protected]
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 [email protected]
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 後面的是併發數
2.1 Requests per second 吞吐率
計算公式:總請求數/處理完成這些請求數所花費的時間,即
Request per second=Complete requests/Time taken for tests
2.2 Concurrency Level 併發用戶數
要注意區分這個概念和併發連接數之間的區別,一個用戶可能同時會產生多個會話,也即連接數。在HTTP/1.1下,IE7支持兩個併發連接,IE8支持6個併發連接,FireFox3支持4個併發連接,所以相應的,我們的併發用戶數就得除以這個基數。
2.3 Time per request 用戶平均請求等待時間
計算公式:處理完成所有請求數所花費的時間/(總請求數/併發用戶數),即:
Time per request=Time taken for tests/(Complete requests/Concurrency Level)
2.4 Time per request:across all concurrent requests 服務器平均請求等待時間
計算公式:處理完成所有請求數所花費的時間/總請求數,即:
Time taken for/testsComplete requests