#Bath - a simple resource pool for Gleam!

1 messages · Page 1 of 1 (latest)

stone leaf
pearl kiln
#

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

stone leaf
pearl kiln
#

Pool boy and nimble pool

#

Pgo

#

Radix maybe?

stone leaf
pearl kiln
#

What’s up?

stone leaf
#

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

pearl kiln
#

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

stone leaf
#

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

pearl kiln
#

How come there’s a shutdown API?

stone leaf
#

To close DB connections etc. if you have them in a pool

pearl kiln
#

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 😴😴😴

stone leaf
#

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 shutdown API to take a force argument instead of having a separate
    force_shutdown function.
  • Improve reliability by tracking live resources and monitoring the calling process,
    re-adding resources to the pool if the caller dies.
  • Add checkout strategies (FIFO and LIFO).
  • Add resource creation strategies (Lazy and Eager).
  • Added child_spec and from_subject functions for creating a pool as part of a
    supervision tree.

Thanks to @pearl kiln for their help debugging this release!

https://github.com/Pevensie/bath/releases/tag/v2.0.0

GitHub

Switch to a builder pattern for pool configuration.
Change the shutdown API to take a force argument instead of having a separate
force_shutdown function.
Improve reliability by tracking live resou...

stone leaf
stone leaf
#

Bath v4 adds in some new functionality for resource lifecycle management! I need this for a super secret project I'm working on 🤫

https://github.com/Pevensie/bath/releases/tag/v4.0.0

GitHub

The function passed to bath.apply must now return a bath.Next(return) value to
indicate whether the checked-out resource should be returned to the pool or
discarded. This allows users to control th...

stone leaf
stone leaf
#

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 😬)

https://github.com/Pevensie/bath/releases/tag/v6.0.0

GitHub

Added the apply_blocking function (thanks to @jtdowney!).

New error variant, hence the breaking change.