Skip to content

Conversation

@willmmiles
Copy link
Member

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.

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.
@willmmiles willmmiles force-pushed the json-response-early-unlock branch from 70664a4 to c789d80 Compare February 15, 2024 00:37
@willmmiles
Copy link
Member Author

Apologies for the incorrect initial push, I grabbed the wrong version of this commit.

@blazoncek
Copy link
Contributor

One question: Is it really necessary to release buffer lock early?
And: What's the time difference? I wouldn't expect it to be more than a few 100us earlier.

@willmmiles
Copy link
Member Author

willmmiles commented Feb 19, 2024

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 send call. This eliminates the possiblity of contention altogether, dramatically improving responsiveness.

@blazoncek blazoncek merged commit f8c48ef into wled:0_15 Mar 2, 2024
@willmmiles willmmiles deleted the json-response-early-unlock branch March 16, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants