Can you limit the number of processes N|Solid uses? - node.js

Is there is a way to limit the number of processes(in a single cluster on a single machine) that N|Solid can start?

Using cluster module generally should use one child process per core, though that depends external factors, such as what else the system is doing. A spin up of 20 processes sounds like an issue, looks like cluster code is failing the master check and start masters and children.
We can use all nsolid built-in tools to debug your implementation/configuration. Please let us know

Related

NodeJS Monitoring Website (Worker Threads?/Multi Process?)

I am doing small project of application that will monitor some servers.
It will base on telnet port check, ping, and also it will use libraries to connect directly to databases (MSSQL, Oracle, MySQL) to check their status.
I wonder what will be the best effective solution for this idea, currently with around 30 servers it works quite smooth, around 2.5sec to check status for all of them (running async). However I am worried that in the future with more servers it might get worse. Hence thinking about using some alternative like Worker Threads maybe? or some multi processing? Any ideas? Everything is happening in internal network so I do not expect huge latency.
Thank you in advance.
Have you ever tried the PM2 cluster mode:
https://pm2.keymetrics.io/docs/usage/cluster-mode/
The telnet stuff is TCP, which Node.js does very well using OS-level networking events. The connections to databases can vary. In the case of Oracle, you'll likely be using the node-oracledb. Those are SQL*Net connections that rely on the OCI libs and Node.js' thread pool. The thread pool defaults to four threads, but you can grow it up to 128 per Node.js process. See this doc for info:
https://oracle.github.io/node-oracledb/doc/api.html#-143-connections-threads-and-parallelism
Having said all that, other than increasing the size of the thread pool, I wouldn't recommend you make any changes. Why fight fires before they're burning? No need to over-engineer things. You're getting acceptable performance given the current number of servers you have.
How many servers do you plan to add in, say, 5 years? What's the difference in timing if you run the status checks for half of the servers vs all of them? Perhaps you could use that kind of data to make an educated guess as to where things would go.
As you add new ones, keep track of the total time to check the status. Is it slipping? If so, look into where the time is being spent and write the solution that will help.

How to fix NodeJS underutilizing CPU Cores?

According to this page Go vs Node.js, Node.js is not showing to be taking full advantage of CPU cores when running cpu-intensive code.
If I use virtualization and simply add more Node.js instances, will I achieve the same performance as Go? I suppose there still will be overheads and one won't be able to achieve the same performance.
Multiple processes will do. For 4 cpus/threads you need 4 Node.js processes to make use of them. That requires a workload that can be split between processes though.
Node.js provides the Cluster module to distribute socket connections between multiple worker processes which may help in some workloads, but I doubt this would help any of the benchmark workloads.
You need to install Cluster module of nodejs in order to take full advantage of CPU cores when running cpu-intensive code.
Node.js is indeed a single threaded process. However, you can make use of clustering to spawn multiple workers on multiple cores.
If you are not using PM2 for spawning the app, please consider using it. PM2 makes spawning workers on multiple cores super easy.
pm2 start app.js -i max
This command will spawn workers on each available core.
Also, note that if you are using session/sockets then you might face some problems because of clustering.

Strategies for scale a nodeJS application?

I have an app in NodeJS.
Recently we have been getting a lot more traffic (this is a new experience for me) and so I have been running into the "EMFILE: too many open files" error that is caused when a single process tries to open more files than the filesystem allows.
I have increased this limit, so we are good for now. However I'm not sure how long this solution will last...
I am wondering: What are other commonly used options for scaling a Node Application that is getting increasing amounts of traffic? (specifically with a mind to the open files limit problem.)
The PM2 process manager which allows clustering catches my eye (am I correct in understanding that every instance of the application requires it's own core -- ie you can't run 4 instances on a single core?). Are there any other techniques that are regularly used?
Thanks (in advance)
PM2 is a simple solution when you want to run more than one instance of Node, another common alternative is the cluster module http://nodejs.org/api/cluster.html Keep in mind, that you will need to configure another http server such as Nginx to reverse proxy your user requests to your Node processes.
You can run any number of Node processes, regardless of the amount of cores. But since each node process is a single thread, and each core can execute a single thread a time, the optimal configuration is when the number of cores match the number of Node processes. If the number of Node processes is greater than the number of cores, under load, you will experience reduced performance due to redundant context switches your processor will have to perform.

Node.js cluster module: sharing cores with other processes without overlap

Suppose I have a 16 core machine and I want a Node.js webserver to use 8 cores, and I want a Java REST/API server to use the other 8. The idea being that Node would be making API calls over localhost, even though the API server may handle requests coming from elsewhere.
I'm using Node's cluster module to accomplish this; basically, doing cluster.fork() 8x. I assume Java has its own ways of utilizing X cores, but others are writing that piece of software.
Is there anything I need to do, from a node perspective, to ensure that my code doesn't run on any of the same cores Java is running on? It seems simple enough to run fork() n/2 times, where n = numCpus, and if that's all I need to worry about, great, but I wanted to ask this question to make sure I'm not missing something important.
It is up the the kernel scheduler to manage this, but you can potentially give the kernel some hints by setting the processor affinity. For example, on linux, you might be able to use taskset to set process affinity for each of the started processes.

worker queue for nodejs?

I am in the process of beginning to write a worker queue for node using node's cluster API and mongoose.
I noticed that a lot of libs exist that already do this but using redis and forking. Is there a good reason to fork versus using the cluster API?
edit and now i also find this: https://github.com/xk/node-threads-a-gogo -- too many options!
I would rather not add redis to the mix since I already use mongo. Also, my requirements are very loose, I would like persistence but could go without it for the first version.
Part two of the question:
What are the most stable/used nodejs worker queue libs out there today?
Wanted to follow up on this. My solution ended up being a roll your own cluster impl where some of my cluster workers are dedicated job workers (ie they just have code to work on jobs).
I use agenda for job scheduling.
Cron type jobs are scheduled by the cluster master. The rest of the jobs are created in the non-worker clusters as they are needed. (verification emails etc)
Before that I was using kue but dropped it because the rest of my app uses mongodb and I didnt like having to use redis just for job scheduling.
Have u tried https://github.com/rvagg/node-worker-farm?
It is very light weight and doesn't require a separate server.
I personally am partial to cluster-master.
https://github.com/isaacs/cluster-master
The reason I like cluster master is because it does very little besides add in logic for forking your process, and give you the ability to manage the number of process you're running, and a little bit of logging/recovery to boot! I find overly bloated process management libraries tend to be unstable, and sometimes even slow things down.
This library will be good for you if the following are true:
Your module is largely asynchronous
You don't have a huge amount of different types of events triggering
The events that fire have small amounts of work to do, but you have lots of similar events firing(things like web servers)
The reason for the above list, is the reason why threads-a-gogo may be good for you, for the opposite reasons. If you have a few spots in your code, where there is a lot of work to do within your event loop, something like threads-a-gogo that launches a "thread" specifically for this work is awesome, because you aren't determining ahead of time how many workers to spawn, but rather spawning them to do work when needed. Note: this can also be bad if there is the potential for a lot of them to spawn, if you start launching too many processes things can actually bog down, but I digress.
To summarize, if your module is largely asynchronous already, what you really want is a worker pool. To minimize the down time when your process is not listening for events, and to maximize the amount of processor you can use. Unless you have a very busy syncronous call, a single node event loop will have troubles taking advantage of even a single core of a processor. Under this circumstance, you are best off with cluster-master. What I recommend is doing a little benchmarking, and see how much of a single core your program can use under the "worst case scenario". Let's say this is 33% of one core. If you have a quad core machine, you then tell cluster master to launch you 12 workers.
Hope this helped!

Resources