Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for cluster. #5

Merged
merged 2 commits into from
Apr 14, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
- Address parser (similar to Qpsmtpd::Address)
- TLS (see http://js.5sh.net/starttls.js, and http://js.5sh.net/c2s.js)
- Support for Cluster: https://github.com/learnboost/cluster instead of
multi-node
24 changes: 12 additions & 12 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var logger = require('./logger');
var config = require('./config');
var conn = require('./connection');
var os = require('os');
var multi;
try { multi = require('./multi-node') }
var cluster;
try { cluster = require('cluster') } // cluster can be installed with npm
catch (err) {
logger.logdebug("no multi-node available, running single-process");
logger.logdebug("no cluster available, running single-process");
}

var Server = exports;
Expand Down Expand Up @@ -39,15 +39,15 @@ Server.createServer = function (params) {
apply_defaults(config_data.main);

var server = net.createServer();
if (multi && config_data.main.nodes) {
// if nodes=cpus then use the count of CPUs
var nodes = config_data.main.nodes === 'cpus' ? os.cpus().length :
config_data.main.nodes;
Server.nodes = multi.listen({
port: config_data.main.port,
nodes: nodes,
listen_address: config_data.main.listen_host
}, server);
if (cluster && config_data.main.nodes) {
var c = cluster(server);
if (config_data.main.nodes !== 'cpus') {
c.set('workers', config_data.main.nodes);
}
c.set('host', config_data.main.listen_host);
c.listen(parseInt(config_data.main.port));

}
else {
server.listen(config_data.main.port, config_data.main.listen_host,
Expand Down