jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
896 stars 222 forks source link

[stress test] Connection is already closed error #195

Closed pzg250 closed 7 years ago

pzg250 commented 8 years ago

Hi, when I run the stress test. It came out errors as bellow. But If I set counter to 100 then the there is no error any more. And I had changed the ulimit to 2048, but stll got errors when run stress test by counter 1000. My computer is Mac 10.11.4. I think maybe connections related problem, but I don't know. Any suggestions ?

server run command: uwsgi --http :9090 --virtualenv /Users/majorguo/workspace/py3env/ --gevent 1000 --http-websockets --module wsgi --workers 2 --max-requests 1000

stress test code:

def test_simple():  
    def listen_on_websocket(closure):  
        ws = create_connection(closure['websocket_url'])  
        assert ws.connected  
        result = ws.recv()  
        print '+',  
        tools.eq_(result, 'Hello, World')  
        ws.close()  
        tools.eq_(ws.connected, False)  
        closure['counter'] -= 1                                                               

websocket_url = 'ws://127.0.0.1:9090/ws/foobar?publish-broadcast'                         
ws = create_connection(websocket_url)                                                     
assert ws.connected                                                                       
ws.send('Hello, World')                                                                   

the receivers

closure = {                                                                               
    'websocket_url': 'ws://127.0.0.1:9090/ws/foobar?subscribe-broadcast',                 
    'counter': 1000,                                                                      
}                                                                                         
clients = [gevent.spawn(listen_on_websocket, closure) for _ in range(0, closure['counter'])]  
gevent.joinall(clients, timeout=5)  
ws.close()  
tools.eq_(ws.connected, False)  
tools.eq_(closure['counter'], 0)  
test_simple() 

error code:

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/gevent/greenlet.py", line 327, in run
    result = self._run(_self.args, *_self.kwargs)
  File "test_uwsgi_gevent.py", line 12, in listen_on_websocket
    ws = create_connection(closure['websocket_url'])
  File "/Library/Python/2.7/site-packages/websocket/_core.py", line 489, in create_connection
    websock.connect(url, *_options)
  File "/Library/Python/2.7/site-packages/websocket/_core.py", line 219, in connect
    self.handshake_response = handshake(self.sock, *addrs, *_options)
  File "/Library/Python/2.7/site-packages/websocket/_handshake.py", line 67, in handshake
    status, resp = _get_resp_headers(sock)
  File "/Library/Python/2.7/site-packages/websocket/_handshake.py", line 121, in _get_resp_headers
    status, resp_headers = read_headers(sock)
  File "/Library/Python/2.7/site-packages/websocket/_http.py", line 211, in read_headers
    line = recv_line(sock)
  File "/Library/Python/2.7/site-packages/websocket/_socket.py", line 97, in recv_line
    c = recv(sock, 1)
  File "/Library/Python/2.7/site-packages/websocket/_socket.py", line 89, in recv
    raise WebSocketConnectionClosedException("Connection is already closed.")
WebSocketConnectionClosedException: Connection is already closed.
<Greenlet at 0x110ab75f0: listen_on_websocket({'counter': 561, 'websocket_url': 'ws://127.0.0.1:)> failed with WebSocketConnectionClosedException
- \+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  Traceback (most recent call last):
  File "test_uwsgi_gevent.py", line 41, in <module>
    test_simple()
  File "test_uwsgi_gevent.py", line 36, in test_simple
    tools.eq_(closure['counter'], 0)
  File "/Library/Python/2.7/site-packages/nose/tools/trivial.py", line 29, in eq_
    raise AssertionError(msg or "%r != %r" % (a, b))
  AssertionError: 561 != 0
Fitblip commented 8 years ago

@pzg250 can you please fix the formatting for your code?

https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet

pzg250 commented 7 years ago

close this issue since this is too long ago. I will investigate a little more in the future.