sezaru

sezaru

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!

Showing Posts 1 to 2

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.

sezaru

sezaru OP

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!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews