{"action":"created","issue":{"url":"https://api.github.com/repos/jrief/django-websocket-redis/issues/110","labels_url":"https://api.github.com/repos/jrief/django-websocket-redis/issues/110/labels{/name}","comments_url":"https://api.github.com/repos/jrief/django-websocket-redis/issues/110/comments","events_url":"https://api.github.com/repos/jrief/django-websocket-redis/issues/110/events","html_url":"https://github.com/jrief/django-websocket-redis/issues/110","id":102907824,"number":110,"title":"Performace issues while doing a stress test","user":{"login":"Edke","id":115118,"avatar_url":"https://avatars.githubusercontent.com/u/115118?v=3","gravatar_id":"","url":"https://api.github.com/users/Edke","html_url":"https://github.com/Edke","followers_url":"https://api.github.com/users/Edke/followers","following_url":"https://api.github.com/users/Edke/following{/other_user}","gists_url":"https://api.github.com/users/Edke/gists{/gist_id}","starred_url":"https://api.github.com/users/Edke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Edke/subscriptions","organizations_url":"https://api.github.com/users/Edke/orgs","repos_url":"https://api.github.com/users/Edke/repos","events_url":"https://api.github.com/users/Edke/events{/privacy}","received_events_url":"https://api.github.com/users/Edke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-24T22:47:30Z","updated_at":"2015-09-08T18:59:51Z","closed_at":null,"body":"Hello Jacob.\r\n\r\nI'm trying to implement your implementation of Websockets. Before going further with implementation in current project, we are testing it in stress test to see it's performance and resources needed for i.e. 1000 concurrent connections. \r\n\r\nI created a task that simulates concurrent clients, master process forks clients that are connecting to server. Using Django's development server with runserver, stress worked quite well, seems that dev server within runserver uses treads for every new connection.\r\n\r\nMoving to production enviro I tried same with nginx and uwsgi. Tried different scenarios, but nginx with uwsgi didn't get me to even 100 stable concurrent connections. My current config follows:\r\n\r\nWe need that every single client connects to it's unique channel to get only events indented for it, therefore every forked child connects to unique channel (UUID string).\r\n\r\nWe are not able to achieve even 50 concurrent clients with 2 workers, most of them get `Error occured: Handshake status 502` when trying to connect.\r\n\r\nRaising workers of ws uWSGI to 20 can't handle 150 clients. \r\n\r\nnginx.conf:\r\n ```\r\nworker_processes 4;\r\n\r\nevents {\r\n    worker_connections 768;\r\n}\r\n\r\nhttp {\r\n    sendfile on;\r\n    tcp_nopush on;\r\n    tcp_nodelay on;\r\n    keepalive_timeout 65;\r\n    types_hash_max_size 2048;\r\n\r\n    include /etc/nginx/mime.types;\r\n    default_type application/octet-stream;\r\n    \r\n    server {\r\n        listen 8012 default_server;\r\n        charset utf-8;\r\n        client_max_body_size 20M;\r\n        sendfile on;\r\n        keepalive_timeout 0;\r\n        large_client_header_buffers 8 32k;\r\n   \r\n        location /ws/ {\r\n                proxy_http_version 1.1;\r\n                proxy_set_header Upgrade $http_upgrade;\r\n                proxy_set_header Connection \"upgrade\";\r\n                proxy_pass http://unix:/run/ws.socket;\r\n                proxy_buffers 8 32k;\r\n                proxy_buffer_size 64k;\r\n        }\r\n        \r\n        location / {\r\n            include uwsgi_params; \r\n            uwsgi_pass unix:/run/django.socket;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nuwsgi.ini for django:\r\n```\r\n[uwsgi]\r\nplugins = python2\r\nchown-socket = http:http\r\nuid = kraken\r\ngid = users\r\ncheaper = 1\r\nprocesses = 2\r\n\r\nsocket = /run/django.socket\r\nbuffer-size = 32768\r\nmaster = True\r\nbase-dir = /home/kraken/apps/proj\r\nchdir = %(base-dir)\r\nwsgi-file = core/wsgi_django.py\r\nvirtualenv =  %(base-dir)/.env\r\n```\r\n\r\nuwsgi.ini for ws:\r\n```\r\n[uwsgi]\r\nplugins = python2\r\nchown-socket = http:http\r\nuid = kraken\r\ngid = users\r\nworkers = 2\r\n\r\nhttp-socket = /run/ws.socket\r\ngevent = 1000\r\nhttp-websockets = True\r\n\r\nmaster = True\r\nbase-dir = /home/kraken/apps/proj\r\nchdir = %(base-dir)\r\nwsgi-file = core/wsgi_ws.py\r\nvirtualenv =  %(base-dir)/.env\r\n```\r\nAny guidance how to handle 1000 concurrent clients or even more ? \r\n"},"comment":{"url":"https://api.github.com/repos/jrief/django-websocket-redis/issues/comments/138670771","html_url":"https://github.com/jrief/django-websocket-redis/issues/110#issuecomment-138670771","issue_url":"https://api.github.com/repos/jrief/django-websocket-redis/issues/110","id":138670771,"user":{"login":"jrief","id":1132472,"avatar_url":"https://avatars.githubusercontent.com/u/1132472?v=3","gravatar_id":"","url":"https://api.github.com/users/jrief","html_url":"https://github.com/jrief","followers_url":"https://api.github.com/users/jrief/followers","following_url":"https://api.github.com/users/jrief/following{/other_user}","gists_url":"https://api.github.com/users/jrief/gists{/gist_id}","starred_url":"https://api.github.com/users/jrief/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrief/subscriptions","organizations_url":"https://api.github.com/users/jrief/orgs","repos_url":"https://api.github.com/users/jrief/repos","events_url":"https://api.github.com/users/jrief/events{/privacy}","received_events_url":"https://api.github.com/users/jrief/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T18:59:51Z","updated_at":"2015-09-08T18:59:51Z","body":"@htayanloo **uwsgi** is a perfect application runner which can handle websockets. Please see Roberto's notes about this.\r\n@Edke How about doing the stress test with uwsgi but without nginx. Then at least we can see who of those services is the culprit."}}