Thanks!

I'm not willing close the connection on every request -- that's too painful.

I don't need an _exact_ count, but I want to be confident that my counts 
are really close.  Serializing the headers and adding the size of the body 
is the closest that I've come up with to do accurate per-request statistics.

Another idea I had is to have a custom net.Listener that outputs wrapped 
net.Conn implementations that will count the number of bytes read/written 
to it.  It would also track the list of active net.Conns.  I think it might 
be possible to associate the net.Conn with the request via the local 
address using http.LocalAddrContextKey. Then I could count just the number 
of bytes per connection and require that each connection is associated with 
a given service.  I think that would give exactly accurate per-connection 
bandwidth, but it would not give per-request bandwidth at all.

- Augusto

On Sunday, January 28, 2018 at 10:59:58 PM UTC-7, Kevin Malachowski wrote:
>
> Given TCP connection reuse I don't think the os/kernel will be able to 
> tell apart the TCP connections any better than intercepting the net.Conn 
> with a custom listener. Especially if you're using anything encrypted, 
> staying in Go is going to be necessary for you to get the sort of data you 
> need.
>
> You might be able to use your wrapped Listener strategy if you are willing 
> to set "Connection: Close" on your incoming connections. I suspect that 
> will degrade performance though. You might be able to hack together a 
> Listener which is actually able to pool http client connections yet 
> convince the http library to Close them when it is done with each request, 
> but that sounds hard to do well and would likely to tightly coupled to the 
> http package's implementation.
>
> Do you need an exact count? You could probably get a pretty good 
> estimation by just serializing the HTTP headers, counting how long that is, 
> and adding in the size of the Body.
>
>

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