Closed CIenthusiast closed 1 year ago
You can't do that with PM2, but if you handle clustering yourself then it's possible (use IPC to tell the master about connections info per worker).
It all depends on your problem. If it's just about connections limit, use max pool size so you can continue using PM2. For example; You have a limit of 200 connections, set max pool size to 50 and spawn 4 workers. Now there are 4 processes, 4 pools and the maximum number of connections is 200.
Another solution is having 1 process & 1 connection pool but running your CPU intensive tasks with node child process.
Also if you don't have CPU intensive tasks & your connections limit is small there's no need to do clustering. I got about 700 transactions per second with just 1 worker.
Thanks for clarification. I handled the Problem myself.
Currently im running a nodejs with pm2. The DB im connecting to via node-jdbc has a max connections limit. However there a several products that need connections aswell so i have to make sure my node (in clustermode through pm2) uses only a certain amount of connections. I could just use one dedicated connection per process but this would limit the performace. So in this case the process always opens and closes connections if needed. But since the processes are stateless and not talking to each other i dont know how many connections in total are opend.
Is there a way to find out (locally only since a SQL statement would require a new connection) how many connections are used by node-jdbc?