I would argue that it doesn't matter. The buffers in the operating system can often substantially exceed the size of those in the Go runtime. Try using an artificially slow reader (e.g. curl --limit-rate) and you should see. Why do you care about buffering in Go vs the OS?
On Sunday, 19 November 2023 at 20:48:56 UTC Mitar wrote: > Hi! > > I would like to measure the total time of serving a request. From what > I was looking around, generally one could do that with a middleware > handler, which starts measuring time, calls ServeHTTP of the original > handler, and once ServeHTTP returns, measures the time it took. > > But I am not completely convinced that this really takes into the > account full total time of serving a request (besides time spent > inside stdlib to pass the request to my code): ServeHTTP can call > Write which buffers data to be send and return, but I would like to > also take into the account total time it took to send this data out > (at least out of the program into the kernel). Am I right that this > time might not be captured with the approach above? Is there a way to > also measure the time it takes for buffers to be written out? > > I am considering calling Flush in the middleware, before measuring the > end time. My understanding is that it would block until data is > written out. But I am not sure if that would have some other > unintended side effects? > > Maybe measuring that extra time is not important in practice? I am > thinking of trying to measure it because it might be that the client's > connection is slow (maybe by malice) and would like to have some data > on how often that is happening. > > > Mitar > > -- > https://mitar.tnode.com/ > https://twitter.com/mitar_m > https://noc.social/@mitar > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ab0d5c0b-6b86-4ea2-91d5-6fb61cf92822n%40googlegroups.com.