CPU utilization of Node.js on Amazon EC2

后端 未结 5 1614
Happy的楠姐
Happy的楠姐 2021-02-04 02:31

Seeing as how node is single threaded, If I have node server running on an amazon EC2 instance with 4 EC2 Compute units will it run any faster / handle more load than if I have

5条回答
  •  灰色年华
    2021-02-04 02:59

    If I have node server running on an amazon EC2 instance with 4 EC2 Compute units will it run any faster / handle more load than if I have 2 EC2 Compute units?

    No, if you are using node.js in a server capacity you will only have access to a single core.

    var http = require('http');
        http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end('Hello World\n');
    }).listen(1337, "127.0.0.1");
    console.log('Server running at http://127.0.0.1:1337/');
    

    Spawns a single listener, that doesn't mean only a single connection though. Node.js breaks conventional thought that way. The Event Loop will not block connections unless you code improperly. This post helps to explain the event loop and how important it is to understand it. Took me a while to really 'get' the implications.

    Does CPU utilization on amazon require a program to be multithreaded to fully use all resources?

    Yes, properly configured apache/nginx will take advantage of multi-cpu configurations. node.js servers are being developed that will also take advantage of these kind of configurations.

提交回复
热议问题