This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add some docs for node cluster
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## Cluster | ||
|
||
A single instance of Node runs in a single thread. To take advantage of | ||
multi-core systems the user will sometimes want to launch a cluster of Node | ||
processes to handle the load. | ||
|
||
By starting node with the `cluster` argument, Node will detect the number of | ||
CPUs on the machine and start that many processes. For example suppose we | ||
had a simple HTTP server in server.js: | ||
|
||
require('http').createServer(function(req, res) { | ||
res.writeHead(200); | ||
res.end('hello world\n'); | ||
}).listen(8000); | ||
|
||
If we start it like this | ||
|
||
% node cluster server.js | ||
Detected 2 cpus | ||
Worker 2438 online | ||
Worker 2437 online | ||
|
||
Node will automatically share port 8000 between the multiple instances. |