1. 程式人生 > >9、高效能web架構之壓力測試

9、高效能web架構之壓力測試

使用ab進行對web伺服器壓力測試:

  • 前言:

當我們部署完一臺web伺服器之後,想要知道的這臺伺服器的效能。就要知道他的吞吐率和響應時間分別是多少,怎麼看呢?那就需要對它進行壓力測試。

1)吞吐率/響應時間:requests/sec;

2)壓力測試:使用ab工具進行測試;

   前置條件:支援多少使用者,支援多少訪問,支援多少併發。

   約定:a、1使用者--》1請求。b、測試多次的平均值。c、測試時儘量選擇只執行單web程序做測試。d、場景,就是資源大小。

   測試時:總共請求多少次。併發多少。

二、準備環境:

1、首先我們來配置壓力測試的web頁面:

[

[email protected] ~]# vi /usr/local/httpd/conf/httpd.conf  //主配置檔案新增下面這幾行

<Location /server-status>

SetHandler server-status

#    Order deny,allow

#    Deny from all

#    Allow from 192.168.10.106

</Location>

注意:需要強調的是,使用者開啟狀態,注意設定Allow From,以免造成敏感資訊的洩漏。

2、訪問一下http://192.168.10.106/server-status:

  1. ab使用的安裝包:

[[email protected] ~]# rpm -qa httpd-tools  //沒有則安裝

[[email protected] ~]# yum -y install httpd-tools

[[email protected] ~]# rpm -qa httpd-tools

httpd-tools-2.4.6-80.el7.centos.1.x86_64

[[email protected] ~]#

[[email protected] ~]# ab --help   //不懂使用就help

ab: wrong number of arguments

Usage: ab [options] [http[s]://]hostname[:port]/path

Options are:

    -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 benchmarking

                    This implies -n 50000

    -s timeout      Seconds to max. wait for each response

                    Default 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 attributes

                    are a colon separated username and password.

    -P attribute    Add Basic Proxy Authentication, the attributes

                    are 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

    -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)

三、進行測試:

1、ab的測試:

[[email protected] ~]# ab -n 10000 -c 100 http://192.168.10.106:80/

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.106 (be patient)

Completed 1000 requests

Completed 2000 requests

Completed 3000 requests

Completed 4000 requests

Completed 5000 requests

Completed 6000 requests

Completed 7000 requests

Completed 8000 requests

Completed 9000 requests

Completed 10000 requests

Finished 10000 requests

Server Software:        Apache/2.4.34 《=====apache版本

Server Hostname:        192.168.10.106《=====主機名稱

Server Port:            80 《====埠

Document Path:          /

Document Length:        381 bytes

Concurrency Level:      100 《=======併發

Time taken for tests:   0.793 seconds 《====所以請求完所花費的時間

Complete requests:      10000 《=====總請求數

Failed requests:        0 《===========失敗的請求數

Write errors:           0

Non-2xx responses:      10000

Total transferred:      6080000 bytes 《======所有響應資料正文的總和(包括響應頭)

HTML transferred:       3810000 bytes 《=======所有響應資料正文的總和(不包括響應頭)

Requests per second:    12607.96 [#/sec] (mean)《=====吞吐率(所有的請求除花費的時間10000/0.793)

Time per request:       7.931 [ms] (mean)《====平均使用者請求等待時間

Time per request:    0.079 [ms] (mean, across all concurrent requests)《===平均請求處理時間

Transfer rate:          7485.97 [Kbytes/sec] received 《===每秒從伺服器獲取的長度

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    1   0.3      1       3

Processing:     3    7   2.1      7      23

Waiting:        1    6   2.0      6      22

Total:          3    8   2.1      8      25

Percentage of the requests served within a certain time (ms)

  50%      8

  66%      8

  75%      8

  80%      8

  90%      9

  95%     11

  98%     12

  99%     25

 100%     25 (longest request)

注意:-n代表總請求數,-c代表併發。

2、為了看到效果,我們將頁面調大再測試:

[[email protected] ~]# vi /usr/local/httpd/htdocs/aaa/index.html    //多條件幾行內容

<h1>aaa.server.com</h1>

<h1>aaa.server.com</h1>

<h1>aaa.server.com</h1>

<h1>aaa.server.com</h1>

<h1>aaa.server.com</h1>

<h1>aaa.server.com</h1>

[[email protected] ~]# ll /usr/local/httpd/htdocs/aaa/index.html

-rw-r--r-- 1 root root 2424 Aug 21 03:25 /usr/local/httpd/htdocs/aaa/index.html

[[email protected] ~]# ab -n 10000 -c 100 http://192.168.10.106:80/  《==併發100

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.106 (be patient)

Completed 1000 requests

Completed 2000 requests

Completed 3000 requests

Completed 4000 requests

Completed 5000 requests

Completed 6000 requests

Completed 7000 requests

Completed 8000 requests

Completed 9000 requests

Completed 10000 requests

Finished 10000 requests

Server Software:        Apache/2.4.34

Server Hostname:        192.168.10.106

Server Port:            80

Document Path:          /

Document Length:        381 bytes

Concurrency Level:      100

Time taken for tests:   0.808 seconds

Complete requests:      10000

Failed requests:        0

Write errors:           0

Non-2xx responses:      10000

Total transferred:      6080000 bytes

HTML transferred:       3810000 bytes

Requests per second:    12372.69 [#/sec] (mean)

Time per request:       8.082 [ms] (mean)

Time per request:       0.081 [ms] (mean, across all concurrent requests)

Transfer rate:          7346.28 [Kbytes/sec] received

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    1   1.9      1      24

Processing:     4    7   1.2      7      18

Waiting:        2    6   1.1      6      18

Total:          5    8   2.7      8      37

Percentage of the requests served within a certain time (ms)

  50%      8

  66%      8

  75%      8

  80%      8

  90%      8

  95%      8

  98%     14

  99%     26

 100%     37 (longest request)

[[email protected] ~]# ab -n 10000 -c 150 http://192.168.10.106:80/  《==併發150

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.106 (be patient)

Completed 1000 requests

Completed 2000 requests

Completed 3000 requests

Completed 4000 requests

Completed 5000 requests

Completed 6000 requests

Completed 7000 requests

Completed 8000 requests

Completed 9000 requests

Completed 10000 requests

Finished 10000 requests

Server Software:        Apache/2.4.34

Server Hostname:        192.168.10.106

Server Port:            80

Document Path:          /

Document Length:        381 bytes

Concurrency Level:      150

Time taken for tests:   0.854 seconds

Complete requests:      10000

Failed requests:        0

Write errors:           0

Non-2xx responses:      10000

Total transferred:      6080000 bytes

HTML transferred:       3810000 bytes

Requests per second:    11707.87 [#/sec] (mean)

Time per request:       12.812 [ms] (mean)

Time per request:       0.085 [ms] (mean, across all concurrent requests)

Transfer rate:          6951.55 [Kbytes/sec] received

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    2   1.4      1      21

Processing:     3   11  18.2      9     210

Waiting:        1   10  18.1      8     208

Total:          4   12  18.2     10     211

Percentage of the requests served within a certain time (ms)

  50%     10

  66%     10

  75%     10

  80%     11

  90%     12

  95%     13

  98%     24

  99%     35

 100%    211 (longest request)

[[email protected] ~]# ab -n 10000 -c 80 http://192.168.10.106:80/  《==併發80

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.106 (be patient)

Completed 1000 requests

Completed 2000 requests

Completed 3000 requests

Completed 4000 requests

Completed 5000 requests

Completed 6000 requests

Completed 7000 requests

Completed 8000 requests

Completed 9000 requests

Completed 10000 requests

Finished 10000 requests

Server Software:        Apache/2.4.34

Server Hostname:        192.168.10.106

Server Port:            80

Document Path:          /

Document Length:        381 bytes

Concurrency Level:      80

Time taken for tests:   0.776 seconds

Complete requests:      10000

Failed requests:        0

Write errors:           0

Non-2xx responses:      10000

Total transferred:      6080000 bytes

HTML transferred:       3810000 bytes

Requests per second:    12890.88 [#/sec] (mean)

Time per request:       6.206 [ms] (mean)

Time per request:       0.078 [ms] (mean, across all concurrent requests)

Transfer rate:          7653.96 [Kbytes/sec] received

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    1   0.4      1       6

Processing:     4    5   1.0      5      14

Waiting:        1    5   0.9      4      14

Total:          5    6   1.3      6      19

WARNING: The median and mean for the waiting time are not within a normal deviation

        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)

  50%      6

  66%      6

  75%      6

  80%      6

  90%      7

  95%      7

  98%     11

  99%     12

 100%     19 (longest request)

Apache測試:

請求     併發      吞吐率    相應時間

10000    100       12372     8.082

10000    100       12616     7.926

10000    100       12724     7.859

10000    150       11707     12.812

10000    150       11871     12.635

10000    150       11783     12.730

10000    80        12890     6.206

10000    80        12565     6.367

10000    80        12985     6.161

10000    200        11766    116.997

10000    200        12050    16.597

10000    200        11926    16.770

因為要環境一模一樣,所以把apache的index.html檔案cp過來:

[[email protected] ~]# cp /usr/local/httpd/htdocs/aaa/index.html /usr/local/nginx/html/index.html

cp: overwrite 鈥usr/local/nginx/html/index.html鈥 y

[[email protected] ~]# ll /usr/local/nginx/html/index.html

-rwxr-xr-x 1 root root 2424 Aug 21 04:43 /usr/local/nginx/html/index.html

一樣使用ab測試,因為nginx的埠改成了8080,所以:

[[email protected] ~]# ab -n 10000 -c 150 http://192.168.10.106:8080/

[[email protected] ~]# ab -n 10000 -c 200 http://192.168.10.106:8080/

請求     併發      吞吐率    相應時間

10000    80         20249     3.951

10000    80         20143     3.972

10000    80         19286     4.148

10000    100        19992     5.002

10000    100        20019     4.995

10000    100        19855     5.036

10000    150        16237     9.238

10000    150        15759     9.518

10000    150        15906     9.430

10000    200        15643     12.785

10000    200        16163     12.373

10000    200        15607     12.814

通過以上的方法可以看出apache和nginx的區別吧,也可以看出該伺服器的吞吐量和響應時間在那個數值比較適合,那個數值相差比較大。相差大,說明到該數值已經到了伺服器的效能瓶頸(數值再增加,數值相差更大)。同時我們也可以通過此方法進行效能調優,看看調優的方法是否有用。這裡就不一一介紹,具體還需要自己去探索實踐。

相關推薦

9高效能web架構壓力測試

使用ab進行對web伺服器壓力測試: 前言: 當我們部署完一臺web伺服器之後,想要知道的這臺伺服器的效能。就要知道他的吞吐率和響應時間分別是多少,怎麼看呢?那就需要對它進行壓力測試。 1)吞吐率/響應時間:requests/sec; 2)壓力測試:使用ab工具進行

2高效能web架構DNS負載均衡(LVS-DR+keepalived實現DNS和web輪詢)

LVS-DR+keepalived+DNS實現DNS高可用性: 一、介紹: 結合上一章的DNS主從複製,按現在大多數公司的需求是滿足不了的。DNS配置雖然簡單易用,但是它在網路中起到了主導作用。 如果客戶端設定的這臺首選DNS伺服器剛好宕機,即使客戶端還設定了備用DNS

13高效能web架構用Codis實現Redis分散式叢集

通過codis實現redis叢集 Codis 是一個分散式 Redis 解決方案, 對於上層的應用來說, 連線到 Codis Proxy 和連線原生的 Redis Server 沒有明顯的區別 (不支援的命令列表https://github.com/CodisLabs/

6高效能web架構Apche虛擬主機配置

構建web虛擬主機: 一、前言: 虛擬web主機指的是在同一臺伺服器中執行多個web站點,其中的每一個站點實際上並不獨立佔用整個伺服器。因此被稱為“虛擬的”web主機,通過虛擬web主機服務可以充分利用伺服器的硬體資源,從而大大降低了網站構建及執行成本。 使用htt

12高效能web架構redis介紹與使用

Redis 簡介 Redis 是完全開源免費的,遵守BSD協議,是一個高效能的key-value資料庫。 Redis 與其他 key - value 快取產品有以下三個特點: Redis支援資料的持久化,可以將記憶體中的資料儲存在磁碟中,重啟的時候可以再次載入進行使用。

7高效能web架構Apche使用虛擬主機實現反向代理

Apache反向代理: 前言介紹:    反向代理(Reverse Proxy)方式是指以代理伺服器來接受internet上的連線請求,然後將請求轉發給內部網路上的伺服器,並將從伺服器上得到的結果返回給internet上請求連線的客戶端,此時代理伺服器對外就表現為一個

11高效能web架構tomcat安全管理規範

Tomcat的常用安全管理規範: 如何修改tomcat的預設路徑: 1、主配置檔案是server.xml ,如何修改tomcat預設訪問路徑: a、建立jsp目錄和index.jsp頁面: [[email protected] ~]# mkdir

高效能web 架構redis 快取叢集

redis 叢集 介紹 redis是一個key-value記憶體資料庫。它支援儲存的value型別包括字串、list(連結串列)、set(集合)、有序集合和hash(雜湊型別)。這些資料型別都支援push/pop、add/remove, redis支援各種不同方式的排序

高效能web 架構 mysql 讀寫分離

高效能web架構主要保證程式的高可用性和高併發性. 高可用就是 保證程式在99.99%的情況下可以使用,不會因為單機節點故障整體崩潰.  高併發說到底也是為了高可用服務.保證在大量併發的時候服務不會宕機. 高效能web架構主要體現在以下方面 資料庫讀寫分離,因為大

Web性能壓力測試工具WebBench詳解

.com benchmark for tool pro soft sce 測試的 壓力 PS:在運維工作中,壓力測試是一項很重要的工作。比如在一個網站上線之前,能承受多大訪問量、在大訪問量情況下性能怎樣,這些數據指標好壞將會直接影響用戶體驗。但是,在壓力測試中存在一個共性

Web伺服器效能/壓力測試工具http_loadwebbenchabSiege使用教程

一、http_load 程式非常小,解壓後也不到100K http_load以並行複用的方式執行,用以測試web伺服器的吞吐量與負載。但是它不同於大多數壓力測試工 具,它可以以一個單一的程序執行,一般不會把客戶機搞死。還可以測試HTTPS類的網站請求。 命令格式

(轉) Web伺服器效能/壓力測試工具http_loadwebbenchabSiege使用教程

一、http_load 程式非常小,解壓後也不到100K http_load以並行複用的方式執行,用以測試web伺服器的吞吐量與負載。但是它不同於大多數壓力測試工 具,它可以以一個單一的程序執行,一般不會把客戶機搞死。還可以測試HTTPS類的網站請求。 命令格式:ht

[轉]Web伺服器效能/壓力測試工具http_loadwebbenchabSiege使用教程

一、http_load 程式非常小,解壓後也不到100K http_load以並行複用的方式執行,用以測試web伺服器的吞吐量與負載。但是它不同於大多數壓力測試工 具,它可以以一個單一的程序執行,一般不會把客戶機搞死。還可以測試HTTPS類的網站請求。 命令格式:http

9ABPZero系列教程拼多多賣家工具 拼團提醒類庫封裝

int 測試類 一個 exists 中長款 returns fun 資料 cor   本篇開始正式做功能,我在開發拼團提醒之前,拼多多並沒有放出拼團人數不足就提醒賣家的功能。 有這個想法主要來源於朋友的抱怨,我想這應該是大部分賣家的心聲吧。 經過分析,拿到了幾個api,

使用ab對web服務進行壓力測試

服務器 時間限制 pac 0.10 字節 -s 重復 最小 傳輸速率 ab  需要先安裝httpd -A auth-username:密碼 向服務器提供BASIC認證憑證。用戶名和密碼由一個單獨分隔 -c並發 一次執行的多個請求數。默認是一次一個請求。 -C cookie-

Web性能壓力測試工具——Siege

ren 它的 install 參數 2.7 求100 under 網址 led   最近需要對Istio裏的bookinfo進行分析,老是手去刷新太慢了,就找了個自動點的工具——Siege   Siege是一款開源的壓力測試工具,設計用於評估WEB應用在壓力下的承受能力。可

Jmeter壓力測試總結

bsp -s lin 壓力測試 在線 median 並發用戶 執行 strong 一、基本概念 1.線程組N:代表一定數量的並發用戶,所謂並發就是指同一時刻訪問發送請求的用戶。線程組就是模擬並發用戶訪問。 2.Ramp-Up Period(in seconds):建立所有線

9CentOS7 安裝Docker擴充套件(通過埠連線容器)

通過埠連線容器   Docker容器從一開始就設計用來執行服務。在大多數情況下,會是一種HTTP服務或其它。其中很大一部分是通過瀏覽器訪問的Web服務。 這會導致一個問題。如果你有多個執行在它們內部環境的80埠上的Docker容器,它們不能都通過你機器上的80埠訪問。下一次技術點將

企業架構研究總結(9)——聯邦企業架構CIO委員會的企業架構實施指南(下)

開發基線企業架構       在開發基線企業架構這一過程中,各個企業或組織需要根據已經確定的架構目標、範圍和所採用的架構框架對當前自身的狀態進行各種製品的開發,這既包括針對核心架構製品的開發,也包括對支援性架構製品的開發,同時還包括針對其他由於特定需求而單獨定義的架構製品(

Web伺服器效能壓力測試工具

一、http_load 程式非常小,解壓後也不到100K http_load以並行複用的方式執行,用以測試web伺服器的吞吐量與負載。 但是它不同於大多數壓力測試工具,它可以以一個單一的程序執行,一般不會把客戶機搞死。 還可以測試HTTPS類的網站請求。 下載地址:h