ssl3_SendApplicationData yields the CPU between TLS records
Categories
(NSS :: Libraries, enhancement)
Tracking
(nss 3.124)
| Tracking | Status | |
|---|---|---|
| nss | --- | 3.124 |
People
(Reporter: leggert, Assigned: leggert)
References
Details
Attachments
(1 file)
ssl3_SendApplicationData yields the CPU between TLS records on every loop iteration when totalSent > 0, via PR_Sleep(PR_INTERVAL_NO_WAIT). This line has been in NSS from the beginning, to give a competing reader thread CPU time during large blocking writes. For non-blocking sockets the yield is counterproductive: it fires precisely when data is flowing freely (no backpressure), adding a gratuitous context switch per 16 KB TLS record.
Expected behavior
Non-blocking sockets skip the yield. The pendingBuf.len check at the end of the send loop already handles backpressure correctly for non-blocking sockets: if ssl3_SendRecord cannot flush all ciphertext to the kernel, it saves the remainder in pendingBuf and the loop breaks immediately — so the yield path is never reached under backpressure anyway. The yield only fires on the fast path, where it serves no purpose.
| Assignee | ||
Updated•5 months ago
|
| Assignee | ||
Comment 1•5 months ago
|
||
The yield at ssl3con.c:2874 lets a reader thread make progress during large blocking writes. For non-blocking sockets it is never needed: if the send buffer is full, ssl3_SendRecord saves the unsent ciphertext in pendingBuf and the loop breaks at the pendingBuf.len check before reaching the yield again. The yield therefore only fires when data is flowing freely — the worst time to add a gratuitous context switch. Guard it with ssl_SocketIsBlocking(ss) so non-blocking callers are unaffected.
Comment 2•5 months ago
|
||
Motivation provided by Lars here:
PR_Sleep(PR_INTERVAL_NO_WAIT) in NSS ssl3_SendApplicationData — 1.3% pf upload time.
Pushed by jschanck@mozilla.com:
https://hg.mozilla.org/projects/nss/rev/c631dbd62d9a
Skip PR_Sleep yield for non-blocking sockets in ssl3_SendApplicationData r=djackson,nss-reviewers
Updated•5 months ago
|
Description
•