fredwu / opq

Elixir queue! A simple, in-memory queue with worker pooling and rate limiting in Elixir.
https://hex.pm/packages/opq
266 stars 8 forks source link

What's the difference between poolboy and opq? #4

Closed peterwillcn closed 6 years ago

peterwillcn commented 7 years ago

poolboy

HugoLnx commented 6 years ago

Pools help to reuse resources that are expensive to create. Like connections, or native threads. So you usually will want to use poolboy when your processes are attached to something that you want to reuse.

OPQ is built on top of GenStage's ConsumerSupervisor, which creates processes that will only do one job and die, so reuse is not a common use case for this guy.

So... when to use OPQ? Usually you will use OPQ if you have an application that has a lot of requests to do something in background. Because if your demand start to grow, instead of your hole application become unresponsive, OPQ will enqueue the requests excess to be processed later. This will buy you time to review your solution so it will not need the queue on the next time. This is part of a concept called Back-pressure which is the technique that GenStage support.

PS.: You can even use OPQ/GenStage with poolboy.

Some References Here's a great explanation of using back pressure with GenStage: https://engineering.spreedly.com/blog/how-do-i-genstage.html

And here's a sample of solution using GenStage and poolboy(with Ecto): https://blog.emerleite.com/how-elixir-helped-us-to-scale-our-video-user-profile-service-for-the-olympics-dd7fbba1ad4e

And if you want to know more about GenStage:

fredwu commented 6 years ago

Thanks @HugoLnx for the detailed explanation. 👍 ❤️