標籤: Siege

網站壓力測試-Siege

No Comments

https://www.joedog.org/

使用 Siege,Ubuntu repositories 找得到/有維護。使用簡單,不失參考價值。

Siege 安裝與設定

  • sudo apt update
  • sudo apt install siege
  • 直接執行 siege waterfalls.ddns.net
  • 等待執行結束後,會自動在 $HOME 下建立 .siege folder。其內有兩個檔案,siege.conf,urls.txt
  • 我們接著設定 siege.conf 如下,簡明的設定就不多加說明:
  • logging = true
  • logfile = ${HOME}/.siege/siege.log
  • 預設是只讀取網頁 HEAD info,這邊改成讀取完整頁面:
  • gmethod = GET
  • 同時允許幾位使用者讀取網頁,預設是 25,使用者可自行調配
  • concurrent = 50
  • 設定測試時間 3 分鐘
  • time = 3M
  • 如一開頭我們的執行,Siege 預設只會讀取所指定的該頁面,並不會再深入頁面的連結(第二層或更深層),因此,我們將需把所有想要參與測試的頁面都明白指定出來(例如所有 post /文章),只要把所有指定網址列出放到以下指定的檔案內即可。
  • file = ${HOME}/.siege/urls.txt
  • 編輯完成存檔離開。更深入的功能再請讀者自行探索。
  • 接著直接執行 siege 即可
  • 以下是筆者的執行結果
Lifting the server siege...
Transactions:		       20026 hits
Availability:		       95.93 %
Elapsed time:		      179.21 secs
Data transferred:	      627.28 MB
Response time:		        0.44 secs
Transaction rate:	      111.75 trans/sec
Throughput:		        3.50 MB/sec
Concurrency:		       49.33
Successful transactions:       20026
Failed transactions:	         849
Longest transaction:	       11.12
Shortest transaction:	        0.00
 
LOG FILE: /home/ken/.siege/siege.log
You can disable this log file notification by editing
/home/ken/.siege/siege.conf and changing 'show-logfile' to false.

如何抓取所有文章的連結網址

  • 使用外掛 Export All URLs
  • 安裝完成啟用後,會在“設定”選項內出現 “Export All URLs”,點擊之,並如下圖點選後,按 Export Now

  • 會出現如下提示,點選提示後,會下載下來,請到下載目錄查看。
  • Data exported successfully! Click here to Download.
  • 我們在下載目錄下開啟終端機,cat 看看,會有如下形式的資料:
URLs
,https://waterfalls.ddns.net/2019/12/19/caddyfile-%e7%9a%84%e5%9b%9b%e7%a8%ae%e4%bd%bf%e7%94%a8%e6%83%85%e5%a2%83/,
,https://waterfalls.ddns.net/2020/01/09/git-%e7%94%a8%e6%b3%95/,
,https://waterfalls.ddns.net/2020/01/07/nfs-%e7%b6%b2%e8%b7%af%e6%aa%94%e6%a1%88%e7%b3%bb%e7%b5%b1/,
,https://waterfalls.ddns.net/2019/12/19/virtualbox-port-forwarding/,
  • 我們發現第一行是 URLs,其它行是若以逗號為分隔的話是網址在第二個欄位。
  • 我們可善用已懂得使用的工具來(土法煉鋼)取出第二個欄位,順便排個序,假設檔名是 1.CSV:
  • grep , 1.CSV | sort | cut -d’,’ -f2 > 2.txt(注意單引號),結果如下:
https://waterfalls.ddns.net/2019/11/23/hello-world/
https://waterfalls.ddns.net/2019/11/27/wordpress-%e7%9a%84%e5%82%99%e4%bb%bd%e8%88%87%e9%82%84%e5%8e%9f/
https://waterfalls.ddns.net/2019/11/30/%e5%ae%89%e8%a3%9d%e4%bc%ba%e6%9c%8d%e5%99%a8-%ef%bc%8d-lcmp/
https://waterfalls.ddns.net/2019/11/30/%e5%ae%89%e8%a3%9d-mariadb/
https://waterfalls.ddns.net/2019/11/30/%e5%ae%89%e8%a3%9d-php/

將此結果附加至urls.txt 即成。
cat 2.txt >> $HOME/.siege/urls.txt。往後欲修改或追加也可直接使用 gedit。

補充:若想要把輸出的編碼過的 URL 結果解碼/轉成中文,那麼就如下下法:
grep , 1.CSV | sort | cut -d’,’ -f2 | php -R ‘echo(urldecode($argn).”\n”);’ > 2.txt(注意單雙引號)
結果如下:

https://waterfalls.ddns.net/2019/11/23/hello-world/
https://waterfalls.ddns.net/2019/11/27/wordpress-的備份與還原/
https://waterfalls.ddns.net/2019/11/30/安裝伺服器---lcmp/
https://waterfalls.ddns.net/2019/11/30/安裝-mariadb/
https://waterfalls.ddns.net/2019/11/30/安裝-php/
  • 2020/0721 補充:此外掛已移至工具選單內。另外 CSV 格式稍有不同,可將”grep 逗號“改成”grep http“,並將 cut 的欄位從 2 改成 3。若知該行義便可自行調試。
  • 參考資料
  • https://www.linode.com/docs/tools-reference/tools/load-testing-with-siege/
  • https://techbeacon.com/app-dev-testing/web-performance-testing-top-12-free-open-source-tools-consider
  • https://stackoverflow.com/questions/340564/best-way-to-stress-test-a-website
  • https://locust.io/
  • https://www.shuzhiduo.com/A/obzb8a0Q5E/
  • 此主題跟 proxy 可能關聯性不大,但 proxy 有正反向之別並與速度或安全性有關,故將查到的資訊列下供以後運用。
  • https://www.shuzhiduo.com/A/MAzAQAXpz9/
  • https://tinyproxy.github.io/
  • https://isabelcmdcosta.medium.com/how-i-set-up-tinyproxy-as-a-forward-proxy-and-reverse-proxy-2a5dc1ed64e4
  • https://guidedhacking.com/threads/how-to-install-tinyproxy-forward-proxy-for-xenforo.13372/
  • https://www.freeproxylists.net/zh/
PHP Code Snippets Powered By : XYZScripts.com