I needed a resource pool to use with Radish for Pevensie Redis, so I've created Bath!
#Bath - a simple resource pool for Gleam!
1 messages · Page 1 of 1 (latest)
What a great name
Named after @modest minnow’s beloved former home
Looking at the impl it’s a bit brittle at the moment and will leak resources in the event of a crash or client misbehaviour
Best look at how some existing pools are implemented, there’s a lot of tricky edge cases a pool needs to handle
Yeah, it's definitely a V1 (I made it on a very short train journey). Do you have any good examples I can look at?
Yeah I'm looking at poolboy and having lots of trouble with supervisor stuff
What’s up?
Oh I just suck and don't know the proper way to do things
The code has also become a mess from my experimenting
Mostly I'm tryna figure out the best way to shut down the pool
Wdym?
Worth reading the OTP docs and one of the books before you start using OTP
If you haven’t
It’s quite a lot of stuff up-front and it’s hard to understand a lot of the why from reading code that uses it
I read a fair bit of LYSE, but a while ago
Lemme get a branch up
What I would like to have is roughly
supervisor (probably rest for 1?)
| |
| |
pool supervisor (one for one)
| | |
/ | \
/ | \
worker worker worker
I haven't gotten around to implementing the top level supervisor yet
Originally, on shutdown, I had the second level supervisor set to auto shutdown on all significant, then set all children to be significant and transient, then just sent messages to all children, but this gave me some error about child processes being unlinked
Then I kinda tried doing a top-down shutdown with exit trapping etc.
But I still need to monitor workers going down in the pool so I can add/remove them from the queue
How come there’s a shutdown API?
To close DB connections etc. if you have them in a pool
Wouldn’t that be handled by normal supervisor shutdown?
It would have to be, you can’t ask your users to always use a non-standard shutdown API because you can’t stop supervisors from shutting down anything below them
I’m very sleepy so I’m certainly misunderstanding 😴
I got up at 6.30am cycled 43km 😴😴😴
Okay, we're ready with a new release of Bath! Turns out I was overcomplicating it and turning a resource pool into a worker pool. That might be coming soon...
For now, here's...
V2!
- Switch to a builder pattern for pool configuration.
- Change the
shutdownAPI to take aforceargument instead of having a separate
force_shutdownfunction. - Improve reliability by tracking live resources and monitoring the calling process,
re-adding resources to the pool if the caller dies. - Add checkout strategies (
FIFOandLIFO). - Add resource creation strategies (
LazyandEager). - Added
child_specandfrom_subjectfunctions for creating a pool as part of a
supervision tree.
Thanks to @pearl kiln for their help debugging this release!
Bath v3 is out now, supporting the stable versions of gleam/otp and gleam/erlang!
Bath v4 adds in some new functionality for resource lifecycle management! I need this for a super secret project I'm working on 🤫
Aaaaaand 5.0 with support for named pools:
https://github.com/Pevensie/bath/releases/tag/v5.0.0
v6 of Bath has been released with a new apply_blocking function for when you want to wait for a resource to become available!
Special thanks to @daring thicket for this feature! (and for their patience while I took over a month to get this merged 😬)