MassiveFermion
Understanding nimble_pool internals
Hi
I’ve been working on a resource pool package for gleam for some time and this is what I have right now.
Currently it accepts a pool size and a function that creates a resource(can be anything) and creates a pool size number of processes that each has a resource as the state.
Then people can use an apply function that accepts a function that acts on the resource and returns a result. apply will checkout a process, send a message to it with the function so that the process can use that function on the resource, get the result and return it to the manager process, which will checkin the process and return the result to the user.
But right now this approach does not handle the situation in which either the worker process or the user process crashes and it seems to me that I won’t be able to handle those situations and still be able to provide parallel resource usage with this approach.
So I’ve been trying to understand how nimble_pool works so that I can implement a similar approach. But I’m having a hard time following what’s going on in the code(I’m a nodejs developer by day and do BEAM stuff as side projects, so not really proficient in OTP).
The only thing I’m sure about right now, is that nimble_pool will directly give the resource to the user. It also seems like there is a timeout after which it just checks the resource in, regardless of what the user has done with it but I’m not really sure about it or anything else.
I’d appreciate any guidance about this, thanks
Most Liked
christhekeele
Note, I only recently discovered the new stdlib PartitionSupervisor but it looks like it does this exact thing for you out-of-the-box.
dimitarvp
the primary reason I wrote it is to use it to add connection pooling
Then definitely start with :poolboy because nimble_pool is much more manual and can confuse you.







