caddyhttp: Optimize logs using zap's WithLazy()#6590
Conversation
a3e02df to
d380731
Compare
|
We could possible do the same in |
|
That's very interesting -- thanks for submitting this PR! I second Francis' question, but I think this LGTM either way. |
|
I can look into |
|
Okay, doing it in increments sounds reasonable. I'll merge this, but before I do, why does cloning the request make it faster? That seems counterintuitive. (I wonder if we should comment next to that line, either a link to this PR or a brief explanation) |
|
Cloning the request is faster than json encoding the request and cloning the logger. But yeah it seems counterintuitive, I'll add a comment. |
mholt
left a comment
There was a problem hiding this comment.
Thank you! Looking forward to seeing if this works well in any other places.
After #6541 I realized that using zap's WithLazy() for the error logger was still much more efficient even if we are cloning the request. Originally I wanted to try using this originalRequest, which is made for logging but just gives a shallow copy without request headers. Instead, using request.Clone() gives a deep copy that just omits the request body.
This makes a simple request about 7% more efficient:
wrk -t 4 -c 200 -d 60 http://localhost(20 cores Docker Ubuntu WSL)With() ~205.000 RPS
WithLazy() ~219.000 RPS
Flamegraph

With()Flamegraph

WithLazy()andCopy()Note that this will make the case where an error is logged about 1% slower since we are doing an additional
request.Clone()