但願選擇一款Web Service性能測試工具,能真實模擬大量用戶訪問網站時的請求,從而獲取服務器當前的請求處理能力(請求數/秒)。 以微信服務器爲例,每一個用戶用獨立的登陸token,作各類操做,好比刷消息、發消息、看朋友圈等。css
但願該性能測試工具符合以下要求:html
http://gatling.io/python
Gatling是一款基於Scala 開發的高性能服務器性能測試工具,它主要用於對服務器進行負載等測試,並分析和測量服務器的各類性能指標。Gatling主要用於測量基於HTTP的服務器,好比Web應用程序,RESTful服務等,除此以外它擁有如下特色:git
測試場景示例: http://gatling.io/docs/2.1.7/advanced_tutorial.htmlgithub
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) }
統計圖: web
官網很卡,真的很卡...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), ))
統計圖: 微信
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發的牢騷:
http://my.oschina.net/u/1433482/blog/464092#OSC_h4_3
咱們研究了現有的解決方案,都不符合要求。好比Apache JMeter和Tsung。
JMeter基於UI操做,容易上手,但基本上不具有編程能力。其次JMeter基於線程,要模擬數千用戶幾乎不可能。
Tsung基於Erlang,能模擬上千用戶並易於擴展,但它基於XML的DSL,描述場景能力弱,且須要大量的數據處理才知道測試結果。
| 比較科目 | Gatling | nGrinder | Locust | | -------- | ----- | ---- | | 併發機制 | Akka Actor | Java線程 | Python gevent| | 單結點併發數量 | 待實驗 | 待實驗(官網數字:3000) | 待實驗 | | 分佈式支持 | N | agent-controller | master-slave | | 錄製腳本 | Http Proxy | TCProxy | N | | 測試腳本DSL | scala dsl | Jython/Groovy | Python | | Session支持 | Y | Y | Y | | CLI啓動測試 | gatling.sh | Y | N (須要在瀏覽器中點擊啓動測試) | | 性能測試結果統計 | Y | Y | Y | | 監控被測試服務器 | N | Y | N | | 每一個實例不一樣參數 | ★★★★★ 參數文件 | ★★★☆☆ 資源文件和線程Id | ★★☆☆☆ 變通辦法:每一個併發實例依次從參數文件中讀取 |
很明顯,首選的全能選手就是Gatling,Akka Actor的併發模型就是來自於併發語言的鼻祖Erlang。
若是想本身擴展性能測試工具,那麼Locust這個小而精的工具能夠考慮。
nGrinder工具是韓國版微信Line開源的,而且專門開設了中文論壇,由韓國工程師回答中國開發者。但有兩個問題,一是官網太卡,其二示例都是片斷不完整。
各位同窗參照上面的對比,本身各取所需吧。