希望選擇一款Web Service性能測試工具,能真實模擬大量用戶訪問網站時的請求,從而獲取服務器當前的請求處理能力(請求數/秒)。 以微信服務器為例,每個用戶用獨立的登錄token,做各種操作,比如刷消息、發消息、看朋友圈等。
希望該性能測試工具符合如下要求:
http://gatling.io/
Gatling是一款基於Scala 開發的高性能服務器性能測試工具,它主要用於對服務器進行負載等測試,並分析和測量服務器的各種性能指標。Gatling主要用於測量基於HTTP的服務器,比如Web應用程序,RESTful服務等,除此之外它擁有以下特點:
測試場景示例: http://gatling.io/docs/2.1.7/advanced_tutorial.html
object Search { val feeder = csv("search.csv").random // 1, 2 val search = exec(http("Home") .get("/")) .pause(1) .feed(feeder) // 3 .exec(http("Search") .get("/computers?f=${searchCriterion}") // 4 .check(css("a:contains('${searchComputerName}')", "href").saveAs("computerURL"))) // 5 .pause(1) .exec(http("Select") .get("${computerURL}")) // 6 .pause(1) }
統計圖:
官網很卡,真的很卡...zzz...
http://naver.github.io/ngrinder/
nGrinder是一個基於 Grinder 開發的一個非常易於管理和使用的性能測試系統。
它 是由一個controller和連接它的多個agent組成,用戶可以通過web界面管理和控制測試,以及查看測試報告,controller會把測試分 發到一個或多個agent去執行。用戶可以設置使用多個進程和線程來並發的執行該腳本,而且在同一線程中,來重復不斷的執行測試腳本,來模擬很多並發用 戶。
nGrinder的測試是基於一個python的測試腳本,用戶按照一定規則編寫測試腳本以後,controller會將腳本以及需要的其他 文件分發到agent,用Jython執行。並在執行過程中收集運行情況、響應時間、測試目標服務器的運行情況等。並保存這些數據生成運行報告,以供以後 查看。
nGrinder的一大特點就是非常容易使用,安裝也非常容易,可以做到開箱即用,測試用戶也可以很容易就開始測試任務。當然,如果想執行一些比較復雜場景的性能測試,就需要測試人員對python有一定認識。
測試場景示例: http://grinder.sourceforge.net/faq.html#simulating-users
# # testRandomise.py # import random import string class TestRandomise: def __init__(self, filename): self._users = [] infile = open(filename, "r") for line in infile.readlines(): self._users.append(string.split((line),',')) infile.close() def getUserInfo(self): "Pick a random (user, password) from the list." return random.choice(self._users) # # Test script. Originally recorded by the TCPProxy. # from testRandomise import TestRandomise tre = TestRandomise("users.txt") class TestRunner: def __call__(self): # Get user for this run. (user, passwd) = tre.getUserInfo() # ... # Use the user details to log in. tests[2002].POST('https://host:443/securityservlet', ( NVPair('functionname', 'Login'), NVPair('pagename', 'Login'), NVPair('ms_emailAddress', user), NVPair('ms_password', passwd), ))
統計圖:
http://locust.io/
Locust 是一個開源負載測試工具。使用 Python 代碼定義用戶行為,也可以仿真百萬個用戶。
Locust 是非常簡單易用,分布式,用戶負載測試工具。Locust 主要為網站或者其他系統進行負載測試,能測試出一個系統可以並發處理多少用戶。
Locust 是完全基於時間的,因此單個機器支持幾千個並發用戶。相比其他許多事件驅動的應用,Locust 不使用回調,而是使用輕量級的處理方式 gevent。
測試場景示例: http://docs.locust.io/en/latest/quickstart.html#example-locustfile-py
from locust import HttpLocust, TaskSet def login(l): l.client.post("/login", {"username":"ellen_key", "password":"education"}) def index(l): l.client.get("/") def profile(l): l.client.get("/profile") class UserBehavior(TaskSet): tasks = {index:2, profile:1} def on_start(self): login(self) class WebsiteUser(HttpLocust): task_set = UserBehavior min_wait=5000 max_wait=9000
統計圖:
因為沒有腳本能力或CLI,所以未加入比較
Locust作者對JMeter和Tsung發的牢騷:
我們研究了現有的解決方案,都不符合要求。比如Apache JMeter和Tsung。
JMeter基於UI操作,容易上手,但基本上不具備編程能力。其次JMeter基於線程,要模擬數千用戶幾乎不可能。
Tsung基於Erlang,能模擬上千用戶並易於擴展,但它基於XML的DSL,描述場景能力弱,且需要大量的數據處理才知道測試結果。
很明顯,首選的全能選手就是Gatling,Akka Actor的並發模型就是來自於並發語言的鼻祖Erlang。
如果想自己擴展性能測試工具,那麼Locust這個小而精的工具可以考慮。
nGrinder工具是韓國版微信Line開源的,並且專門開設了中文論壇,由韓國工程師回答中國開發者。但有兩個問題,一是官網太卡,其二示例都是片段不完整。