LockedJsonResponse: Release early if possible#3760
Conversation
Release the json buffer lock as soon as we've finished serializing. This should slightly reduce the number of lock collisions as the response class isn't destructed until after the last packet is ack'd.
70664a4 to
c789d80
Compare
|
Apologies for the incorrect initial push, I grabbed the wrong version of this commit. |
|
One question: Is it really necessary to release buffer lock early? |
|
I don't have exact numbers, but it's a couple of round trip times -- it can be 10s of ms. (Data goes out, ack comes back, fin goes out, fin-ack comes back). If a second request comes in and the lock is contended, then we hit a minimum of 1s retry delay, which really hurts. (This is not the same as the lock delay - a 503 response has a minimum 1s backoff delay.) This was happening routinely during my local tests when a browser tried to send out multiple requests in parallel during initial page load. The biggest impact of this patch is on requests that can be served in a single outbound packet buffer (eg <1k); in that case, the lock is released before the callback even exits, as the first packet is sent in the |
Release the json buffer lock as soon as we've finished serializing. This should slightly reduce the number of lock collisions by releasing sooner - the response class isn't destructed until after the last packet is ack'd.