今天用apache 自帶的ab工具測試,當并發量達到1000多的時候報錯如下:
[root@aa~]# This is ApacheBench, Version 2.3 <Revision:655654>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.176 (be patient)
Completed 300 requests
Completed 600 requests
Completed 900 requests
apr_socket_recv: Connection reset by peer (104)
Total of 1085 requests completed
查看應用服務器和數據庫均未報錯,連接被重置,bingyi了以下,apr_socket_recv這個是操作系統內核的一個參數,在高并發的情況下,內核會認為系統受到了SYN flood攻擊,會發送cookies(possible SYN flooding on port 80. Sending cookies),這樣會減慢影響請求的速度,所以在應用服務武器上設置下這個參數為0禁用系統保護就可以進行大并發測試了:
# vim /etc/sysctl.conf
net.ipv4.tcp_syncookies = 0
# sysctl -p
然后就可以超過1000個并發測試了。
另附其他系統內核參數說明:
net.ipv4.tcp_syncookies = 0
#此參數是為了防止洪水攻擊的,但對于大并發系統,要禁用此設置net.ipv4.tcp_max_syn_backlog
#參數決定了SYN_RECV狀態隊列的數量,一般默認值為512或者1024,即超過這個數量,系統將不再接受新的TCP連接請求,一定程度上可以防止系統資源耗盡。可根據情況增加該值以接受更多的連接請求。net.ipv4.tcp_tw_recycle
#參數決定是否加速TIME_WAIT的sockets的回收,默認為0。net.ipv4.tcp_tw_reuse
#參數決定是否可將TIME_WAIT狀態的sockets用于新的TCP連接,默認為0。net.ipv4.tcp_max_tw_buckets
#參數決定TIME_WAIT狀態的sockets總數量,可根據連接數和系統資源需要進行設置。
另外ab中自帶參數
-r Don’t exit on socket receive errors.
可以避免并發過大出現錯誤,從而實現大并發測試,建議使用此方法。
ab 的各種參數
-n requests Number of requests to perform-c concurrency Number of multiple requests to make at a time-t timelimit Seconds to max. to spend on benchmarkingThis implies -n 50000-s timeout Seconds to max. wait for each responseDefault is 30 seconds-b windowsize Size of TCP send/receive buffer, in bytes-B address Address to bind to when making outgoing connections-p postfile File containing data to POST. Remember also to set -T-u putfile File containing data to PUT. Remember also to set -T-T content-type Content-type header to use for POST/PUT data, eg.'application/x-www-form-urlencoded'Default is 'text/plain'-v verbosity How much troubleshooting info to print-w Print out results in HTML tables-i Use HEAD instead of GET-x attributes String to insert as table attributes-y attributes String to insert as tr attributes-z attributes String to insert as td or th attributes-C attribute Add cookie, eg. 'Apache=1234'. (repeatable)-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'Inserted after all normal header lines. (repeatable)-A attribute Add Basic WWW Authentication, the attributesare a colon separated username and password.-P attribute Add Basic Proxy Authentication, the attributesare a colon separated username and password.-X proxy:port Proxyserver and port number to use-V Print version number and exit-k Use HTTP KeepAlive feature-d Do not show percentiles served table.-S Do not show confidence estimators and warnings.-q Do not show progress when doing more than 150 requests-l Accept variable document length (use this for dynamic pages)-g filename Output collected data to gnuplot format file.-e filename Output CSV file with percentages served-r Don't exit on socket receive errors.-h Display usage information (this message)-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)-f protocol Specify SSL/TLS protocol(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
- n請求執行的請求數
- c多次請求的并發數
- t限時秒到最大值。花在基準測試
這意味著- n 50000
- s超時秒到最大值。等待每個響應
默認值為30秒
- b窗口大小的TCP發送/接收緩沖區,以字節為單位
- b地址地址在發送連接時綁定
-p postfile文件,包含要發布的數據。記住也要設置- t
-u putfile文件中包含的數據。記住也要設置- t
- t內容類型的內容類型標題用于POST / PUT數據。
“應用程序/ x-www -表單- urlen編碼”
默認是“text / plain”
-v verbosity有多少故障排除信息打印
- w打印結果在HTML表
我用HEAD代替GET
- x屬性字符串作為表屬性插入
- y屬性字符串作為tr屬性插入
- z屬性字符串作為td或th屬性插入
- c屬性添加cookie。Apache = 1234。(重復)
- h屬性添加任意標題行。“接受編碼:gzip”
插入所有正常的標題行。(重復)
屬性添加基本的WWW認證,屬性
是一個冒號分隔的用戶名和密碼。
- p屬性添加基本代理身份驗證,屬性
是一個冒號分隔的用戶名和密碼。
- x代理:使用端口Proxyserver和端口號
- v打印版本號,退出
- k使用HTTP KeepAlive功能
- d不顯示百分比表。
- s不顯示置信估計者和警告。
當超過150個請求時,q沒有顯示進展
- l接受可變文檔長度(用于動態頁面)
- g文件名輸出數據到gnuplot格式文件。
- e文件名輸出CSV文件的百分比
- r不退出套接字接收錯誤。
- h顯示使用信息(此消息)
- z ciphersuite指定SSL / TLS密碼套件(見openssl密碼)
- f協議指定SSL / TLS協議
(SSL3,TLS1,TLS1.1,TLS1.2或全部)