{"id":18593493,"url":"https://github.com/syed007hassan/nodejs-performance","last_synced_at":"2025-05-16T10:34:42.186Z","repository":{"id":159975796,"uuid":"601534404","full_name":"Syed007Hassan/NodeJs-Performance","owner":"Syed007Hassan","description":"Maximizing the performance of NodeJs using clustering, performing load balancing using PM2, and understanding how worker threads vs cluster works.","archived":false,"fork":false,"pushed_at":"2023-02-14T17:36:13.000Z","size":71,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T21:46:33.121Z","etag":null,"topics":["availability","clustering","load-balancer","pma","zero-downtime"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Syed007Hassan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-14T09:18:40.000Z","updated_at":"2023-02-14T17:40:08.000Z","dependencies_parsed_at":"2023-05-07T03:05:32.657Z","dependency_job_id":null,"html_url":"https://github.com/Syed007Hassan/NodeJs-Performance","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/Syed007Hassan%2FNodeJs-Performance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Syed007Hassan%2FNodeJs-Performance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Syed007Hassan%2FNodeJs-Performance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Syed007Hassan%2FNodeJs-Performance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Syed007Hassan","download_url":"https://codeload.github.com/Syed007Hassan/NodeJs-Performance/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254513223,"owners_count":22083531,"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":["availability","clustering","load-balancer","pma","zero-downtime"],"created_at":"2024-11-07T01:12:43.367Z","updated_at":"2025-05-16T10:34:42.176Z","avatar_url":"https://github.com/Syed007Hassan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NodeJs-Performance\n\n* [Maximizing Cluster Perfromance ](https://github.com/Syed007Hassan/NodeJs-Performance/tree/69dabf9ae8c2f96e53baee4f383aff521882e357):\n  Using the amount of logical cores available on a system, increasing the performance of web servers so that the response time can be lesser when multiple requests are being made. A module that is responsible for providing cluster related API is called a cluster. It's NodeJS inbuilt module. Cluster uses single master(parent) process and many worker(child) process. See below diagram to know more…\n  \u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://www.sysleaf.com/static/133a45ee56a5f63eb9f85182af914996/a6906/nodejs-cluster-arch.png\"\u003e\n\u003c/p\u003e\n\n* [Load Balancing using PM2 (Process Manager)](https://pm2.keymetrics.io/docs/usage/quick-start/): It is a runtime process management and monitoring tool with a built-in load balancer for NodeJS applications which makes managing them easier on production. \n- This could be installed globally on the system, using the following command:\n\n```\n   npm i pm2 -g\n```\n\n- How to use:\nThe best thing about PM2 is easiness. Some of the basic commands for using PM2 are following one:\n\n- To Start:\nThe following command will start an application. \n```\npm2 start server.js\n```\n![image](https://user-images.githubusercontent.com/104893311/218752419-cb5a06ab-300b-4eb6-8483-c20a507a1c66.png)\n\n8 instances shows the max number of logical cores available in a system.\n\n- To Stop an Application/Process:\n```\npm2 stop pid or App-name\n```\n\n- To Restart an Application/Process:\nRestart will kill and start an application\n```\npm2 restart pid or App-name\n```\n\n- To Reload an Application/Process:\nAs opposed to restart, which kills and restarts the process, reload achieves a 0-second-downtime reload.\n```\npm2 reload pid or App-name\n```\n\n- To Delete an Application/Process:\n```\npm2 delete pid or App-name\n```\n\n- To effect “All” Applications/Processes:\n'All' attribute will affect every process and application.\n```\npm2 reload all\n```\n\n- To Monitor:\n```\npm2 monit\n```\n\n   ![Screenshot 2023-02-14 171203](https://user-images.githubusercontent.com/104893311/218751697-c5730607-8f75-4a04-bf5d-397777b13224.png)\n\n\n- To View Logs:\n```\npm2 logs\n```\n#### Worker Threads VS Cluster\n  \nCluster\n- Each process has it’s own memory with it’s own Node (v8) instance\n- One process is launched on each CPU\n\nWorker Thread\n- One process total\n- Each worker will have its own instance of V8 and Event Loop\n- Shares memory with other threads\n\n \u003cp align=\"center\"\u003e\n \u003cimg src=\"https://user-images.githubusercontent.com/104893311/218793390-ee614551-49e5-4779-9958-213d7c36e52a.png\"\u003e\n \n \u003cimg src=\"https://user-images.githubusercontent.com/104893311/218793994-9415f1c3-51d8-4b07-8f2c-1719fe25802a.png\"\u003e\n\u003c/p\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyed007hassan%2Fnodejs-performance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyed007hassan%2Fnodejs-performance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyed007hassan%2Fnodejs-performance/lists"}