DEV Community

Matthias Hryniszak
Matthias Hryniszak

Posted on

Docker Swarm vs node.js cluster

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

Happy coding!

Top comments (0)

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay