dashbitco / nimble_pool

A tiny resource-pool implementation for Elixir
347 stars 20 forks source link

Add min_ready option & checkout deadline #6

Closed sneako closed 4 years ago

sneako commented 4 years ago

min_ready

When starting a pool, it will block until min_ready workers have completed their initialization, even if they have an async init callback.

When using async init callbacks, especially callbacks that take some time to complete, the pool can complete initialization before any of the workers have. By configuring min_ready, we can ensure that the pool is ready to use, while still keeping the async behaviour for when workers are removed and added later on.

deadline

Previously, workers would always be restarted when checkout! timed out, to ensure that we could not check in a worker in an unclean state. By using a deadline, we can avoid checking out a client in situations where the checkout will timeout, and therefore avoid restarting the worker

sneako commented 4 years ago

@josevalim here is the deadline PR based on this branch https://github.com/sneako/nimble_pool/pull/1

josevalim commented 4 years ago

I dropped just one tiny comment!

josevalim commented 4 years ago

Hi @sneako! I have merged the deadline code into master. We can still leave this open in case we want to merge min_ready in the future, but I am hoping we can get away with it in the lazy pool. :)

josevalim commented 4 years ago

Thank you for your contributions! :green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart:

sneako commented 4 years ago

Sounds good! Thanks for your guidance! ❤️

josevalim commented 4 years ago

Closing this as I believe we don't need min_ready for now. :)

For completeness, what we did in finch was to start the connection lazily. Therefore, if you need min_ready, you can have a process after the pool is started that checks out min_ready.