91亚洲精华国内精华精华液_国产高清在线精品一区不卡_精品特级一级毛片免费观看_欧美日韩中文制服有码_亚洲精品无码你懂的网站369

PS:網(wǎng)站和API接口性能壓力測試是性能調(diào)優(yōu)過程中必不可少的一環(huán)。只有讓服務(wù)器處在高壓情況下才能真正體現(xiàn)出各種設(shè)置所暴露的問題。Apache中有個自帶的,名為ab的程序,可以對Apache或其它類型的服務(wù)器進行網(wǎng)站訪問壓力測試。

ApacheBench命令原理:

ab命令會創(chuàng)建很多的并發(fā)訪問線程,模擬多個訪問者同時對某一URL地址進行訪問。它的測試目標(biāo)是基于URL的,因此,既可以用來測試Apache的負(fù)載壓力,也可以測試nginx、lighthttp、tomcat、IIS等其它Web服務(wù)器的壓力。

ab命令對發(fā)出負(fù)載的計算機要求很低,既不會占用很高CPU,也不會占用很多內(nèi)存,但卻會給目標(biāo)服務(wù)器造成巨大的負(fù)載,其原理類似CC攻擊。自己測試使用也須注意,否則一次上太多的負(fù)載,可能造成目標(biāo)服務(wù)器因資源耗完,嚴(yán)重時甚至導(dǎo)致死機。

ApacheBench參數(shù)說明

    格式:ab [options] [http://]hostname[:port]/path
    參數(shù)說明:
    -n requests Number of requests to perform
    //在測試會話中所執(zhí)行的請求個數(shù)(本次測試總共要訪問頁面的次數(shù))。默認(rèn)時,僅執(zhí)行一個請求。
    -c concurrency Number of multiple requests to make
    //一次產(chǎn)生的請求個數(shù)(并發(fā)數(shù))。默認(rèn)是一次一個。
    -t timelimit Seconds to max. wait for responses
    //測試所進行的最大秒數(shù)。其內(nèi)部隱含值是-n 50000。它可以使對服務(wù)器的測試限制在一個固定的總時間以內(nèi)。默認(rèn)時,沒有時間限制。
    -p postfile File containing data to POST
    //包含了需要POST的數(shù)據(jù)的文件,文件格式如“p1=1&p2=2”.使用方法是 -p 111.txt 。 (配合-T)
    -T content-type Content-type header for POSTing
    //POST數(shù)據(jù)所使用的Content-type頭信息,如 -T “application/x-www-form-urlencoded” 。 (配合-p)
    -v verbosity How much troubleshooting info to print
    //設(shè)置顯示信息的詳細(xì)程度 – 4或更大值會顯示頭信息, 3或更大值可以顯示響應(yīng)代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號并退出。
    -w Print out results in HTML tables
    //以HTML表的格式輸出結(jié)果。默認(rèn)時,它是白色背景的兩列寬度的一張表。
    -i Use HEAD instead of GET
    // 執(zhí)行HEAD請求,而不是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. -C “c1=1234,c2=2,c3=3” (repeatable)
    //-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數(shù)對。此參數(shù)可以重復(fù),用逗號分割。
    提示:可以借助session實現(xiàn)原理傳遞 JSESSIONID參數(shù), 實現(xiàn)保持會話的功能,如
    -C ” c1=1234,c2=2,c3=3, JSESSIONID=FF056CD16DA9D71CB131C1D56F0319F8″ 。
    -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.
    //-P proxy-auth-username:password 對一個中轉(zhuǎn)代理提供BASIC認(rèn)證信任。用戶名和密碼由一個:隔開,并以base64編碼形式發(fā)送。無論服務(wù)器是否需要(即, 是否發(fā)送了401認(rèn)證需求代碼),此字符串都會被發(fā)送。
    -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.
    -g filename Output collected data to gnuplot format file.
    -e filename Output CSV file with percentages served
    -h Display usage information (this message)
    //-attributes 設(shè)置屬性的字符串. 缺陷程序中有各種靜態(tài)聲明的固定長度的緩沖區(qū)。另外,對命令行參數(shù)、服務(wù)器的響應(yīng)頭和其他外部輸入的解析也很簡單,這可能會有不良后果。它沒有完整地實現(xiàn) HTTP/1.x; 僅接受某些’預(yù)想’的響應(yīng)格式。 strstr(3)的頻繁使用可能會帶來性能問題,即你可能是在測試ab而不是服務(wù)器的性能。

    參數(shù)很多,一般我們用 -c 和 -n 參數(shù)就可以了。例如:

    # ab -c 5000 -n 600 http://127.0.0.1/index.php

ApacheBench用法詳解:

在Linux系統(tǒng),一般安裝好Apache后可以直接執(zhí)行;
# ab -n 4000 -c 1000 http://www.ha97.com/

如果是Win系統(tǒng)下,打開cmd命令行窗口,cd到apache安裝目錄的bin目錄下;

-n后面的4000代表總共發(fā)出4000個請求;-c后面的1000表示采用1000個并發(fā)(模擬1000個人同時訪問),后面的網(wǎng)址表示測試的目標(biāo)URL。

稍等一會得到類似如下顯示結(jié)果:

 



結(jié)果分析:

    This is ApacheBench, Version 2.3
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/

    Benchmarking 192.168.80.157 (be patient)
    Completed 400 requests
    Completed 800 requests
    Completed 1200 requests
    Completed 1600 requests
    Completed 2000 requests
    Completed 2400 requests
    Completed 2800 requests
    Completed 3200 requests
    Completed 3600 requests
    Completed 4000 requests
    Finished 4000 requests

    Server Software: Apache/2.2.15
    Server Hostname: 192.168.80.157
    Server Port: 80

    Document Path: /phpinfo.php
    #測試的頁面
    Document Length: 50797 bytes
    #頁面大小

    Concurrency Level: 1000
    #測試的并發(fā)數(shù)
    Time taken for tests: 11.846 seconds
    #整個測試持續(xù)的時間
    Complete requests: 4000
    #完成的請求數(shù)量
    Failed requests: 0
    #失敗的請求數(shù)量
    Write errors: 0
    Total transferred: 204586997 bytes
    #整個過程中的網(wǎng)絡(luò)傳輸量
    HTML transferred: 203479961 bytes
    #整個過程中的HTML內(nèi)容傳輸量
    Requests per second: 337.67 [#/sec] (mean)
    #最重要的指標(biāo)之一,相當(dāng)于LR中的每秒事務(wù)數(shù),后面括號中的mean表示這是一個平均值
    Time per request: 2961.449 [ms] (mean)
    #最重要的指標(biāo)之二,相當(dāng)于LR中的平均事務(wù)響應(yīng)時間,后面括號中的mean表示這是一個平均值
    Time per request: 2.961 [ms] (mean, across all concurrent requests)
    #每個連接請求實際運行時間的平均值
    Transfer rate: 16866.07 [Kbytes/sec] received
    #平均每秒網(wǎng)絡(luò)上的流量,可以幫助排除是否存在網(wǎng)絡(luò)流量過大導(dǎo)致響應(yīng)時間延長的問題
    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 0 483 1773.5 11 9052
    Processing: 2 556 1459.1 255 11763
    Waiting: 1 515 1459.8 220 11756
    Total: 139 1039 2296.6 275 11843
    #網(wǎng)絡(luò)上消耗的時間的分解,各項數(shù)據(jù)的具體算法還不是很清楚

    Percentage of the requests served within a certain time (ms)
    50% 275
    66% 298
    75% 328
    80% 373
    90% 3260
    95% 9075
    98% 9267
    99% 11713
    100% 11843 (longest request)
    #整個場景中所有請求的響應(yīng)情況。在場景中每個請求都有一個響應(yīng)時間,其中50%的用戶響應(yīng)時間小于275毫秒,66%的用戶響應(yīng)時間小于298毫秒,最大的響應(yīng)時間小于11843毫秒。對于并發(fā)請求,cpu實際上并不是同時處理的,而是按照每個請求獲得的時間片逐個輪轉(zhuǎn)處理的,所以基本上第一個Time per request時間約等于第二個Time per request時間乘以并發(fā)請求數(shù)。

總結(jié):在遠(yuǎn)程對web服務(wù)器進行壓力測試,往往效果不理想(因為網(wǎng)絡(luò)延時過大),建議使用內(nèi)網(wǎng)的另一臺或者多臺服務(wù)器通過內(nèi)網(wǎng)進行測試,這樣得出的數(shù)據(jù),準(zhǔn)確度會高很多。如果只有單獨的一臺服務(wù)器,可以直接本地測試,比遠(yuǎn)程測試效果要準(zhǔn)確。

穩(wěn)定

產(chǎn)品高可用性高并發(fā)

貼心

項目群及時溝通

專業(yè)

產(chǎn)品經(jīng)理1v1支持

快速

MVP模式小步快跑

承諾

我們選擇聲譽

堅持

10年專注高端品質(zhì)開發(fā)
  • 返回頂部