PM2 Cluster Mode Load Balancing Discrepancy on Windows

Open
#5,713 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
javascript, node.js
Domain
backend, devops

Research direction

Start with the provided index.js Express reproduction on Windows and run it with pm2 start index.js -i 4, then compare the returned process IDs across parallel requests. Trace PM2's cluster-mode load-balancing entry point and verify that requests are distributed across the four instances as they are on Linux.

Written by the indexing model from the issue text.

Description

What's going wrong?

When utilizing PM2 in cluster mode on Windows servers, we observe a significant discrepancy in load balancing behavior compared to its behaviour on Linux. Unlike the expected round-robin load balancing on Linux, all incoming requests are directed to a single instance of the application on Windows,

How could we reproduce this issue?

On windows create a nodejs app that prints instance id. index.js:
`const express = require('express');
const process = require('process');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
const instanceInfo = {
message: 'Hello, this is Express app!',
instanceId: process.pid,
};
res.json(instanceInfo);
});

app.listen(port, () => {
console.log(Server is running on port ${port} with PID ${process.pid});
});`

Start multiple instances using pm2
pm2 start index.js.js -i 4

Call this API parallelly in multiple tabs. You will always get same instance id.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Unitech/pm2

All issues in Unitech/pm2

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.