dashbitco / nimble_pool

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

Feature Request: Be able to introspect pool state/telemetry #37

Closed aselder closed 1 year ago

aselder commented 1 year ago

It would be nice to be able to get some telemetry from NimblePool.

In particular, it would be nice to be able to track pool utilization (# checkout/ #available) and time spent waiting for a resource.

josevalim commented 1 year ago

Hi @aselder!

The information on checkout/available can be done on top of NimblePool. Especially because we keep resources as a queue, so we would need to keep a counter ourselves, so I would rather leave this decision to users. Wait time can also be computed on client by measuring the time before calling checkout and effectively checking out.

The only measurement that would need to be provided is the idle timeout, which we could improve NimblePool to send it downstream. Perhaps by allowing a three arity function on checkout, the third element being metadata (this one could also be emulated but it is quite more annoying to do so and it is information we already track).

oliveigah commented 1 year ago

I'm currently working to implement something like this on Finch https://github.com/sneako/finch/issues/183.

I think the only feature we will need to implement on the nimble pool side is a new callback for pool termination.

Because we need to clear all the metrics state when the pool is terminated.

If this makes sense to you I can implement it here. What you think @josevalim?

josevalim commented 1 year ago

I will gladly accept terminate_pool callback :)

josevalim commented 1 year ago

Closing this for now. If there is an interest on idle_timeout, please open up an issue, but now that I think about it, even it could be calculated. :)