> Does anyone know a way of getting current open connections?

You might consider using https://golang.org/pkg/net/http/#Server.ConnState
for this instead of a middleware for the http.Handler. The different
connection states are documented on
https://golang.org/pkg/net/http/#ConnState and the callback should fire
each time a connection changes state (including new and closed). This
should also help distinguish between connections which are not really the
same as active requests.

On Wed, Feb 13, 2019 at 7:54 AM Dany Xu <xuletter0927loli...@gmail.com>
wrote:

> what does it means "heavy load"? if not in "heavy load", it can work ? On
> the other hand, do you want the tcp connections or the http req numbers?
> From the go package, it appears that getting the basic tcp connections in
> http.server is impossible.
>
> 在 2019年2月12日星期二 UTC+8下午10:37:52,jose.albe...@gmail.com写道:
>>
>> I was trying to get current HTTP connections in HTTP.Server. Internally
>> transport tracks it under connPerHostCount. However, I don't see a way of
>> getting this value.
>>
>> I tried this:
>>
>> type HTTPRequestMetrics struct {
>>  activeConnections int64
>>  next              http.Handler
>> }
>>
>>
>> func HTTPRequestMetricsHandler(h http.Handler) *HTTPRequestMetrics {
>>  return &HTTPRequestMetrics{next: h}
>> }
>>
>>
>> func (h *HTTPRequestMetrics) ServeHTTP(w http.ResponseWriter, r *http.
>> Request) {
>>  atomic.AddInt64(&h.activeConnections, 1)
>>  defer atomic.AddInt64(&h.activeConnections, -1)
>>
>>
>>  h.next.ServeHTTP(w, r)
>> }
>>
>>
>> But looks like defer never gets called when under heavy load (and clients
>> see connection reset by peer)
>>
>> Does anyone know a way of getting current open connections?
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Kevin Conway

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to