简体   繁体   中英

How many concurrent database queries can node.js make?

I've heard that node.js is fast when it performs IO tasks like querying a database and because javascript is single threaded and uses event loop, it uses a lot less resources when comparing to using a separate thread whenever a concurrent database query is made. But doesn't that mean the maximum number of concurrent queries it can make is still limited by how many concurrent connections a particular database can handle? If that's the case, what are the advantages of node.js over something like vert.x, which can use multiple event loops instead of just one.

Since node.js 12 (it's available since node.js 10 as "experimental feature") you can use worker threads like you're maybe already using worker verticle with vert.x. You also have the child process with node or cluster mode .

Either ways (vert.x or node) you need to keep in mind the golden rule aka "do not block the eventloop or worker pool" and think about the size of your thread pool according to your capacity.

I think it's often better to keep you process monothreaded and to scale it as new and completely isolated instances that can be hosted on multiple places in your infrastructure or even in the same place (using docker/kubernetes/whatever or even with systemd for example). And dynamically perform the scaling according to the requests increase, your infrastructure's ability to scale and of course the size of the connections pool your database can handle.

When you're designing your application as a reactive or event-driven one (the right way to use node or vert.x) and a stateless one, it's easier to handle the scaling that way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM