sezaru

sezaru

Process pool with custom availability logic

I have a GenServer (I will call it A) that I connect to a external source (Actually it is a WebSockex process since I connect using websocket) and provide an API to communicate with that source.

A normal API call for A would be something like subscribe_to_channel(channel, callback) which means that it would subscribe that connection to a specific channel and pass all messages from that channel to the callback.

This works great, but the external source limits the number of channel subscriptions to a certain number per connection, let’s say 10. So, after 10 calls to subscribe_to_channel with specific channels, I would need to create a new A process with a new connection and use it to subscribe to new channels.

I was thinking in how to automatize this, what comes to mind is something like poolboy, where I can tell it to initialize like 5 A processes in a pool (and, as result, 5 websocket connections to the external source) and let it handle the subscribe_to_channel calls.

The idea is that A would have another method called available_subscriptions which returns the number of available subscriptions this process can handle. So, for example, if A have 1 channel subscribed, then available_subscriptions will return 9, for 2 channels, it will return 8, and so on.

From that, poolboy could check that function and decide to send the subscribe call to the process in the pool with the least subscriptions currently.

Now, as far as I know, I don’t think I can configure a behavior like that in poolboy, so my question is, is there any library that implements something like that? Or do I need to implement my custom pool with the above described logic?

Thanks!

Marked As Solved

tty

tty

AFAIK with poolboy you are on your own and have to implement your custom pooler. Process poolers and message queues are the two most commonly (re)written applications in Erlang/Elixir. Welcome to the club!

At last count we have 4 different implementations of process pooling in our production code. Yes, 4.

Last Post!

sezaru

sezaru

Yeah, I guess you are right, I will need to implement a custom pool for that.
I tried to find some library in Hex to do that without success.

Thanks for the heads up!

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

We're in Beta

About us Mission Statement