{"id":19579792,"url":"https://github.com/abo/websocket-benchmarking","last_synced_at":"2025-02-26T12:13:23.372Z","repository":{"id":137069402,"uuid":"26942852","full_name":"abo/websocket-benchmarking","owner":"abo","description":"NodeJS Websocket Benchmarking","archived":false,"fork":false,"pushed_at":"2014-11-28T07:03:33.000Z","size":284,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-09T04:58:43.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-21T02:56:48.000Z","updated_at":"2014-11-28T07:03:33.000Z","dependencies_parsed_at":"2023-03-12T18:00:39.366Z","dependency_job_id":null,"html_url":"https://github.com/abo/websocket-benchmarking","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abo%2Fwebsocket-benchmarking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abo%2Fwebsocket-benchmarking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abo%2Fwebsocket-benchmarking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abo%2Fwebsocket-benchmarking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abo","download_url":"https://codeload.github.com/abo/websocket-benchmarking/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240849058,"owners_count":19867617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T07:19:09.176Z","updated_at":"2025-02-26T12:13:23.306Z","avatar_url":"https://github.com/abo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"websocket-benchmarking\n======================\n\nNodeJS Websocket Benchmarking\n\n## Socket.IO(On MAC OS X)\n\n* 配置 App, Nginx\n\n  ```\n    cd socket.io/chat1\n    npm install\n    cd socket.io/chat2\n    npm install\n  ```\n\n  nginx.conf 修改:\n  由于测试时所有 client 都在本机, 而当前稳定版 nginx(1.6.2) 负载均衡算法不包含generic hash, 按 ip_hash 分配会导致所有请求都发到同一个后端节点, 所以需要安装upsteam-hash-module, 按 hash($remote_addr.$remote_port) 负载均衡.\n  \n  upstream 使用 unix socket地址 (unix:/tmp/chat1.socket) 能减少 local ip port 的使用(系统配置中 net.inet.ip.portrange的设置 )\n\n  ```\n    worker_processes  4;\n    ...\n    events {\n        worker_connections  65535;\n    }\n\n    http {\n        ...\n        upstream app {\n            hash $remote_addr.$remote_port;\n            #server 127.0.0.1:3000;\n            #server 127.0.0.1:3001;\n            server unix:/tmp/chat1.socket;\n            server unix:/tmp/chat2.socket;\n        }\n        map $http_connection $upgrade_requested {\n            default upgrade;\n            '' close;\n        }\n        ...\n        server{\n            ...\n            location / {\n                proxy_buffering off;\n                proxy_read_timeout 86400s;\n                proxy_send_timeout 86400s;\n\n                proxy_set_header Upgrade $http_upgrade;\n                proxy_set_header Connection \"upgrade\";\n                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n                proxy_set_header Host $host;\n                proxy_http_version 1.1;\n                proxy_pass http://app;\n                root   html;\n                index  index.html index.htm;\n            }\n            ...\n        }\n        ...\n    }\n\n  ```\n\n\n* 修改 websocket-bench\n\n  websocket-bench中依赖版本策略会导致socket.io-client连接方式(transport) fall back到polling, 而不是websocket, 此外，依赖策略导致使用engine.io-client较低版本, 所以需要修改依赖版本及源码\n\n  ```\n  npm install -g websocket-bench\n\n  ```\n\n  修改 websocket-bench 中依赖库的版本\n\n  ```\n  \"socket.io-client\": \"~1.2.0\",\n  \"engine.io-client\": \"~1.4.2\",\n  \"socket.io\": \"~1.2.0\",\n  ```\n\n  修改 websocket-bench 源码(lib/workers/socketioworker.js L20)\n\n  ```\n  var client = io.connect(this.server, {'transports': ['websocket'], 'force new connection' : true});\n  ```\n\n  ```\n  cd {npm global dir}/websocket-bench\n  npm install\n  ```\n\n* 系统参数调整\n  最大打开文件数，本地ip端口范围等\n\n  ```\n  sudo sysctl -w kern.maxfiles=1048600\n  sudo sysctl -w kern.maxfilesperproc=1048576\n  sudo sysctl -w net.inet.ip.portrange.first=10240\n  ulimit -S -n 1048576\n  ```\n\n* 启动 App, Nginx (均需要调整ulimit)\n\n  ```\n  redis-server\n  cd socket.io/chat1\n  node .\n  cd socket.io/chat2\n  node .\n  chmod 666 /tmp/chat1.socket\n  chmod 666 /tmp/chat1.socket\n  sudo nginx\n  ```\n\n* 启动 websocket-bench\n\n  ```\n  websocket-bench -a 100000 -c 100 -g generator.js -m 1 -k -v http://localhost:80\n  ```\n\n\n## SocketCluster\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabo%2Fwebsocket-benchmarking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabo%2Fwebsocket-benchmarking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabo%2Fwebsocket-benchmarking/lists"}