-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid multiple wrapping #19
Comments
300ns overhead doesn't seem like a big deal to me in the context of an http requests. You'd need a program that is serving 3.3M requests/second to waste 1 CPU core with this overhead. Anyway, I'm not against getting rid of this overhead, I just don't have a lot of time right now to review your patch 😢. Could you explain your motivation for this optimization a little more? Did you find this overhead to be problematic in a real world situation? If this patch is just for the fun of optimization, I think the requirements would be that it doesn't break any existing usage of the API. Is this the case for your PR? I wasn't sure based on the PR description. |
You're right, but the allocations add up and have knock-on effects. We're not quite at the 1Mio RPS just yet, but we can already feel the effects on GC and latency that 7 allocations per request can have. It's definitely not a make-or-break thing, but it's measurable.
Kinda: we operate a video CDN, and we're trying to squeeze a bit more performance out of our edge services. When profiling these services this double-wrap case is one of the things that caught our eye and we thought it might be worth addressing.
I can only imagine one case where this change might change people's metrics:
Without this PR, both metrics would show different values. With this PR, both metrics would show the same values. |
Since it's possible to have multiple uses of httpsnoop in a project, coming from different imported modules (e.g. when using server-timing), it's also possible to end up wrapping a
ResponseWriter
multiple times. This is not ideal because it has a sensible performance impact:(these benchmarks were made after switching
httptest.NewServer
for directh.ServeHTTP
calls, in order to avoid the unrelated overhead of the server; see #20 )Ideally we'd return the same
Metrics
instance when re-wrapping an already wrappedResponseWriter
.In case we explicitly want to measure at two different places in the middleware-chain, we'd still be able to
Unwrap
before re-wrapping.WDYT?
The text was updated successfully, but these errors were encountered: