cloudflare / pingora

A library for building fast, reliable and evolvable network services.
Apache License 2.0
20.25k stars 1.1k forks source link

Query - how to report on number of connections in pool to upstream? #245

Closed xushichangdesmond closed 1 month ago

xushichangdesmond commented 1 month ago

Hi

It doesnt appear to me at least, that there is any way to get at internal pingora metrics including the number of connections in the pool. Is there any way to do this?

xushichangdesmond commented 1 month ago

or could we implement an optional trait for the proxy to receive pool connection callbacks for push/pop?

eaufavor commented 1 month ago

We might have the solution in place already depending on the exact problems to solve. What problems are we trying to solve here?

xushichangdesmond commented 1 month ago

So my upstream service has a soft limit on number of connections say 20000 on each upstream peer node, and I would like to be able to keep track of the number of connections open by the proxy to each upstream peer, reporting it as a metric every minute or so. Ideally I would have the number of inflight connections to each peer as well as number of connections idling in the pool for each peer. Currently i am able to keep track of number of inflight connections using the ProxyHttp trait, but I am unable to keep track of number of connections idling in the pool. Note too that this is a separate want from upstream_keepalive_pool_size configuration option. Here, all I want is to be able to determine number of open connections, not to limit it yet.

Thank you.

eaufavor commented 1 month ago

Excellent! That was something I expected.

So when you try to connect to your upstream with HttpPeer, you can put a Tracer object into it. The tracer itself can hold a Arc<AtomicUsize>. The tracing evens will be called whenever a connection is created and disconnected. From there you can access the real time number of connections (both active and in the pool idling) via a copy of the Arc<AtomicUsize>.

xushichangdesmond commented 1 month ago

sounds good. many thanks.