mirror of
https://github.com/imputnet/cobalt.git
synced 2026-07-31 10:04:07 -05:00
[GH-ISSUE #1480] Using Node.js's built-in load-balancer in cluster mode for better distribution requests among workers #30551
Reference in New Issue
Block a user
Originally created by @firsturdiev on GitHub (Dec 9, 2025).
Original GitHub issue: https://github.com/imputnet/cobalt/issues/1480
bug description
Currently cobalt uses OS-level port-binding method for workers, in that way OS handles distribution of incoming requests among workers. But due to some OS-scheduling problems, it becomes very unbalanced, even node.js official warns about this:
But in another (default) method, node.js itself handles distribution in round-robin fashion with some minor latency in much reliable way.
The main reason of spawning multiple workers in cobalt is benefiting from equal distribution of requests so in this case using node.js built-in method rather than OS-level port binding looks right approach.
Open to discuss more about this by technical side
source
cobalt's code
@firsturdiev commented on GitHub (Dec 9, 2025):
I'm in wait-mode of sending pull-request to fix this (just some lines of code), if repo owners interested in this approach of workers. I myself used this method for my own cobalt instance and results were significant
@dumbmoron commented on GitHub (Dec 9, 2025):
Do you have any benchmarks/stats?
SO_REUSEPORTafaik should be very efficient, and does not suffer from what is described in OP (it should be actually more efficient thannode:clusterbalancing, because it does not rely on Node IPC).@firsturdiev commented on GitHub (Dec 9, 2025):
Don't have benchmarks currently, but after reading about this on nodejs offical docs, I switched to built-in method, latency difference wasn't noticiable, and distibution was very equal (i checked manually with printing worker index next to each request log).
Will share with benchmark test video/proofs soon. Maybe you can also test it manually,
@firsturdiev commented on GitHub (Dec 9, 2025):
Also one bottleneck about SO_REUSEPORT is that it uses it's own hashing mechanism (ip + client info) for distributing, not round-robin