[英]NodeJS - how does it handles requests
Suppose you have the code below: 假设您有以下代码:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
//Computations that takes one millisecond
............
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
Questions: 问题:
Though I am new to nodejs, I will try to give some advices. 尽管我是NodeJS的新手,但我将尝试提供一些建议。
IMHO, Node doesn't handle any parallelism. 恕我直言,Node不处理任何并行性。 It is single-thread, means only 1 process, 1 thread, 1 cpu.
它是单线程的,仅意味着1个进程,1个线程,1个cpu。 All his power resides in his non-blocking way of processing by using callback functions.
他的全部权力都在于使用回调函数的非阻塞处理方式。 This makes node stay rapid without the complexity of multithread.
这使节点保持快速运行,而没有多线程的复杂性。
If a single nodejs server is not enough for your huge incoming request, think of cluster to take advantage of multi-core system : http://nodejs.org/api/cluster.html 如果单个nodejs服务器不足以满足您的巨大传入请求,请考虑集群以利用多核系统: http : //nodejs.org/api/cluster.html
Just google. 只是谷歌。 There are lots of articles on this topic.
关于此主题的文章很多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.