实际上,restify 正在包装几个不同的包之一:spdy、http 或 https。
if (options.spdy) {
this.spdy = true;
this.server = spdy.createServer(options.spdy);
} else if ((options.cert || options.certificate) && options.key) {
this.ca = options.ca;
this.certificate = options.certificate || options.cert;
this.key = options.key;
this.passphrase = options.passphrase || null;
this.secure = true;
this.server = https.createServer({
ca: self.ca,
cert: self.certificate,
key: self.key,
passphrase: self.passphrase,
rejectUnauthorized: options.rejectUnauthorized,
requestCert: options.requestCert,
ciphers: options.ciphers
});
} else if (options.httpsServerOptions) {
this.server = https.createServer(options.httpsServerOptions);
} else {
this.server = http.createServer();
}
来源:https://github.com/restify/node-restify/blob/5.x/lib/server.js
这些包管理请求的异步性质,这些请求在restify 中作为事件处理。 The EventListener calls all listeners synchronously in the order in which they were registered.。在这种情况下,restify 是侦听器,将按照接收到的顺序处理请求。
缩放
话虽如此,像restify 这样的网络服务器通常通过在像nginx 这样的代理后面的多个进程上释放它们来扩大规模。在这种情况下,nginx 将有效地在进程之间拆分传入请求,从而使 Web 服务器能够处理更大的并发负载。
Node.js 限制
最后,请记住,这一切都受到 Node.js 行为的限制。由于应用程序在单个线程上运行,因此您可以在执行慢速同步请求时有效地阻止所有请求。
server.get('/test', function(req, res, next) {
fs.readFileSync('something.txt', ...) // blocks the other requests until done
});