一,安裝ab:
1,安裝
root@lhdpc:~# apt-get install httpd-tools
2,查看安裝的路徑
root@lhdpc:~# whereis ab ab: /usr/bin/ab /usr/share/man/man1/ab.1.gz
3,查看ab的版本:
root@lhdpc:~# ab -V This is ApacheBench, Version 2.3 <$Revision: 1879490 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
說明:劉宏締的架構森林是一個專注架構的博客,
網站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/05/29/ubuntu21-10-linux-an-zhuang-he-shi-yong-ab-apachebench/
對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
說明:作者:劉宏締 郵箱: 371125307@qq.com
二,測試效果
例子:10個並發,總數100次訪問
liuhongdi@lhdpc:/data/php/admapi/app$ ab -c 10 -n 100 http://192.168.219.6:8000/goods/detail?goodsid=12323 This is ApacheBench, Version 2.3 <$Revision: 1879490 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.219.6 (be patient).....done Server Software: nginx/1.18.0 Server Hostname: 192.168.219.6 Server Port: 8000 Document Path: /goods/detail?goodsid=12323 Document Length: 37 bytes Concurrency Level: 10 Time taken for tests: 0.059 seconds Complete requests: 10 Failed requests: 7 (Connect: 0, Receive: 0, Length: 7, Exceptions: 0) Total transferred: 2276 bytes HTML transferred: 496 bytes Requests per second: 169.79 [#/sec] (mean) Time per request: 58.897 [ms] (mean) Time per request: 5.890 [ms] (mean, across all concurrent requests) Transfer rate: 37.74 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 0.5 1 2 Processing: 12 26 11.0 25 44 Waiting: 11 26 11.2 25 44 Total: 13 27 10.9 26 45 Percentage of the requests served within a certain time (ms) 50% 26 66% 29 75% 37 80% 42 90% 45 95% 45 98% 45 99% 45 100% 45 (longest request)
三,查看linux的版本:
root@lhdpc:~# more /etc/os-release PRETTY_NAME="Ubuntu 21.10" NAME="Ubuntu" VERSION_ID="21.10" VERSION="21.10 (Impish Indri)" VERSION_CODENAME=impish ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=impish