{"id":14978169,"url":"https://github.com/socketio/socket.io-sample-playbook","last_synced_at":"2025-08-07T00:43:24.488Z","repository":{"id":65978744,"uuid":"541469083","full_name":"socketio/socket.io-sample-playbook","owner":"socketio","description":"This repository contains an Ansible playbook to set up a basic Socket.IO application.","archived":false,"fork":false,"pushed_at":"2022-09-26T09:13:32.000Z","size":12,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-29T01:01:43.247Z","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":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/socketio.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":"2022-09-26T07:53:05.000Z","updated_at":"2023-08-20T22:03:33.000Z","dependencies_parsed_at":"2023-02-19T19:31:03.057Z","dependency_job_id":null,"html_url":"https://github.com/socketio/socket.io-sample-playbook","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/socketio%2Fsocket.io-sample-playbook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-sample-playbook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-sample-playbook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-sample-playbook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/socketio","download_url":"https://codeload.github.com/socketio/socket.io-sample-playbook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219869249,"owners_count":16555572,"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-09-24T13:56:58.751Z","updated_at":"2024-10-07T10:17:29.678Z","avatar_url":"https://github.com/socketio.png","language":"JavaScript","readme":"# Socket.IO Ansible playbook\n\nThis repository contains an Ansible playbook to set up a basic Socket.IO application.\n\n- [Usage](#usage)\n- [How to deploy on AWS](#how-to-deploy-on-aws)\n- [Architecture](#architecture)\n- [Notes](#notes)\n  - [Scaling](#scaling)\n\n## Usage\n\n```\n# test the connection to the server (localhost)\n$ make I=local ping\n\n# install the Node.js application\n$ make I=local install\n```\n\n## How to deploy on AWS\n\n- clone this repository\n\n```\n$ git clone git@github.com:socketio/socket.io-sample-playbook.git\n```\n\n- create an EC2 instance with the [AWS console](https://aws.amazon.com/console/)\n\n- create a `dev` inventory file with the following content:\n\n```\napp01 ansible_host=\u003cpublic IP address of your instance\u003e ansible_user=ubuntu ansible_ssh_private_key_file=\u003cprivate key file\u003e\n\n[app]\napp01\n```\n\nReference: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html\n\n- and then run\n\n```\n$ make I=dev install\n```\n\nYou can then check the status of your application on the instance:\n\n```\n$ ssh ubuntu@\u003cpublic IP address of your instance\u003e\n\n$ service my-app status\n● my-app.service - A sample Socket.IO application\n     Loaded: loaded (/etc/systemd/system/my-app.service; enabled; vendor preset: enabled)\n     Active: active (running)\n   Main PID: 437 (node)\n      Tasks: 22 (limit: 1143)\n     Memory: 68.9M\n        CPU: 414ms\n     CGroup: /system.slice/my-app.service\n             ├─437 /usr/bin/node /apps/my-app/src/index.js\n             └─712 /usr/bin/node /apps/my-app/src/index.js\n\n$ sudo tail /var/log/my-app/app.log\n\n2022-09-26T09:06:42.422Z Worker 712: 0 connected client(s)\n2022-09-26T09:06:47.427Z Worker 712: 0 connected client(s)\n2022-09-26T09:06:52.433Z Worker 712: 0 connected client(s)\n2022-09-26T09:06:57.432Z Worker 712: 0 connected client(s)\n2022-09-26T09:07:02.438Z Worker 712: 0 connected client(s)\n```\n\n## Architecture\n\n```\n/apps/\n└── my-app\n    ├── package.json\n    ├── package-lock.json\n    └── src\n        └── index.js\n\n# application logs\n/var/log/my-app/\n└── app.log\n\n# nginx configuration\n/etc/nginx/conf.d/my-app.conf\n\n# increase the number of available local ports\n/etc/sysctl.d/net.ipv4.ip_local_port_range.conf\n\n# increase the nofile limits for the runner user\n/etc/security/limits.d/my-app-limits.conf\n```\n\n## Notes\n\n### Scaling\n\nThe application uses the Node.js built-in [`cluster`](https://nodejs.org/api/cluster.html) module to create one worker per core.\n\nWhen using multiple Socket.IO servers, one needs to:\n\n- ensure that all packets of a single session reaches the same node (i.e. sticky sessions)\n\nThis is done here with the [`@socket.io/sticky`](https://github.com/socketio/socket.io-sticky) module (the load-balancing is done by the master process).\n\nWe could also have used one port per worker, and configure nginx with multiple upstream nodes:\n\n```\nupstream nodes {\n  hash $remote_addr consistent;\n\n  server localhost:3000;\n  server localhost:3001;\n  server localhost:3002;\n  # ...\n}\n```\n\n- forward packets between nodes (for broadcasting, for example when calling `io.emit()`)\n\nThis is done here with the [`@socket.io/cluster-adapter`](https://github.com/socketio/socket.io-cluster-adapter) module.\n\nIf you deploy your application on multiple servers, you will need to use another adapter, like the one based on [Redis](https://socket.io/docs/v4/redis-adapter/) or [Postgres](https://socket.io/docs/v4/postgres-adapter/).\n\nReference: https://socket.io/docs/v4/using-multiple-nodes/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketio%2Fsocket.io-sample-playbook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocketio%2Fsocket.io-sample-playbook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketio%2Fsocket.io-sample-playbook/lists"}