由於最近公司線上node項目出一些不穩定的狀況,考慮在這方面能不能作進一步的優化,既然要作優化首先要知道問題出在哪裏?node
由於暫沒法定位是node層問題仍是api層出現問題,因爲在開發環境小併發量程序運行都是很穩定的,後面考慮使用一些壓力工具去驗證在高併發的時候線上的問題,這裏我首選siege來作壓力測試。api
一:安裝併發
我這裏使用的系統是FreeBSD,包請自行下載:http://download.joedog.org/siege/siege-latest.tar.gzapp
tar zxvf siege-latest.tar.gz cd siege-3.0.9 ./configure make & make install
很快就安裝完畢了socket
查看一下配置文件高併發
/usr/local/siege/bin/siege -c
CURRENT SIEGE CONFIGURATION
Mozilla/5.0 (unknown-x86_64-freebsd10.0) Siege/3.0.9
Edit the resource file to change the settings.
----------------------------------------------
version: 3.0.9
verbose: true
quiet: false
debug: false
protocol: HTTP/1.1
get method: HEAD
connection: close
concurrent users: 15
time to run: n/a
repetitions: 100
socket timeout: 30
accept-encoding: gzip
delay: 1 sec
internet simulation: false
benchmark mode: false
failures until abort: 1024
named URL: http://matouapp.ymatou.com/forymatouapp/home
URLs file: /etc/urls.txt
logging: true
log file: /var/siege.log
resource file: /root/.siegerc
timestamped output: false
comma separated output: false
allow redirects: true
allow zero byte data: true
allow chunked encoding: true
upload unique files: true工具
2、使用 測試
參數介紹: transactions:處理的請求數 Availability: 成功率 Elapsed Time:須要多少時間 Data transferred :傳輸了多少字節 Response time: 響應時間 Transaction rate:平均每秒完成多少次處理 (表示後臺的處理速度) Throughput:平均每秒傳輸速度 Concurrency:最高併發量 Successful transactions :成功的處理數
Failed transactions:失敗的處理數
Longest transactions:傳輸最長的時間
Shortest transactions:傳輸最短的時間
50個用戶(每次併發量,不是每秒併發量)重複10 共產生 50 *10= 500個請求 (默認:GET)優化
/usr/local/siege/bin/siege -c 50 -r 10 http://matouapp.ymatou.com/forymatouapp/homeui
執行結果: