2012-08-08 65 views
1

我正在嘗試龍捲風框架。但是我發現龍捲風在壓力測試(使用多機械化)30秒後經常失敗。我在多機械化中使用10個線程,並運行100秒,大約500個請求/秒。 30秒後失效率約爲15%。整個測試大約100秒![在這裏輸入圖片描述] [1]。根據統計數據,我意識到,失敗可能是由於0.2秒後的超時。我搜索了幾種方法來增加網絡上的超時時間,但沒有任何效果。下面如何增加龍捲風的超時時間

的是我的龍捲風代碼:

import tornado.ioloop 
import tornado.web 

class MainHandler(tornado.web.RequestHandler): 
    @tornado.web.asynchronous 
    def get(self): 
     self.write("Hello, world") 
     self.finish() 

application = tornado.web.Application([ 
    (r"/", MainHandler), 
]) 

if __name__ == "__main__": 
    application.listen(8000) 
    tornado.ioloop.IOLoop.instance().start() 

這裏是我的多機械化測試腳本:

import requests 
import random 
import time 

class Transaction(object): 
    def __init__(self): 
     pass 
    def run(self): 
     r = requests.get('http://127.0.0.1:8000') 
     output = r.raw.read() 
     assert(r.status_code == 200) 
     return output 

if __name__ == '__main__': 
    trans = Transaction() 
    trans.run() 
    print trans.custom_timers 

以下是我從multimech運行得到了錯誤消息

Traceback (most recent call last): 
    File "././test_scripts/v_user.py", line 12, in run 
    r = requests.get('http://127.0.0.1:8000') 
    File "/Library/Python/2.7/site-packages/requests/api.py", line 54, in get 
    return request('get', url, **kwargs) 
    File "/Library/Python/2.7/site-packages/requests/safe_mode.py", line 37, in wrapped 
    return function(method, url, **kwargs) 
    File "/Library/Python/2.7/site-packages/requests/api.py", line 42, in request 
    return s.request(method=method, url=url, **kwargs) 
    File "/Library/Python/2.7/site-packages/requests/sessions.py", line 230, in request 
    r.send(prefetch=prefetch) 
    File "/Library/Python/2.7/site-packages/requests/models.py", line 603, in send 
    timeout=self.timeout, 
    File "/Library/Python/2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 415, in urlopen 
    body=body, headers=headers) 
    File "/Library/Python/2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 267, in _make_request 
    conn.request(method, url, **httplib_request_kw) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 941, in request 
    self._send_request(method, url, body, headers) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 975, in _send_request 
    self.endheaders(body) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 937, in endheaders 
    self._send_output(message_body) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 797, in _send_output 
    self.send(msg) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 759, in send 
    self.connect() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 740, in connect 
     self.timeout, self.source_address) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 571, in create_connection 
    raise err 
error: [Errno 49] Can't assign requested address 
+0

那麼,你每秒發送5,000個請求? – 2012-08-08 01:53:01

+0

如果您需要每秒處理5000個請求,您將需要更多的後端。加載時間> 30秒的頁面更糟糕,404的 – 2012-08-08 02:34:22

+0

我的Mac上每秒有大約500個請求。多機械化捕獲的錯誤是Socket.error。 – Jimmy 2012-08-08 10:12:43

回答

0

要回答你如何更改龍捲風超時的問題,你需要修改龍捲風的bind_socket函數灰來設定超時:http://www.tornadoweb.org/documentation/_modules/tornado/netutil.html

sock.setblocking(0) 
sock.bind(sockaddr) 
sock.listen(backlog) 
sockets.append(sock) 

變化的第一行至sock.setblocking(1)。根據文檔:http://docs.python.org/library/socket.html#socket.socket.settimeout

設置無的超時套接字操作上 s.settimeout(無)禁用超時相當於s.setblocking(1)。

但是,正如評論中所建議的,我認爲你應該看看分配負載。

+0

我試過了你的建議,並增加了httpserver上的處理器。但它仍然在30秒後約15%(每秒約500個請求) – Jimmy 2012-08-09 02:06:26

+0

嗨,具體的錯誤代碼和消息是什麼? – 2012-08-09 02:21:26

+0

順便說一句,我試圖使用sock.listen(999999999999),似乎有助於將故障率降低到5%。但失敗發生在30秒左右。之後,沒有更多的失敗發生。我不知道背後發生了什麼。 – Jimmy 2012-08-13 05:10:19