Out of boredom, I have started testing the performance of Docker Swarm vs Node.js cluster. I approached this with the expectation that the added overhead of Docker, with round-robin load balancer, will make the application slower. The machine I am running all the tests is an Intel i7 11700k running Linux 5.13.0-23 (Ubuntu), all defaults, and all tests are executed using node 17 Here are the results:
- single service instance: 9742.37 trans/sec
- 16 service instances: 27033.33 trans/sec
- single node application: 12418.70 trans/sec
- clustered node application: 18290.21 trans/sec
Frankly speaking, I didn't expect Docker Swarm to be faster. It's not only easier to use Docker Swarm (the code is exactly the same as for a single-threaded system), but is also very much more performant! Looks like a single-threaded application running as node.js process directly on top of the operating system is faster, but then the clustering makes it somewhat slower. Anyone knows why that is?
You can check the demo code here