Closed Bug 2032389 Opened 5 months ago Closed 5 months ago

ssl3_SendApplicationData yields the CPU between TLS records

Categories

(NSS :: Libraries, enhancement)

enhancement

Tracking

(nss 3.124)

RESOLVED FIXED
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: nobody → leggert
See Also: → 127740

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.

Motivation provided by Lars here:

PR_Sleep(PR_INTERVAL_NO_WAIT) in NSS ssl3_SendApplicationData — 1.3% pf upload time.

See Also: → 1979985

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

Status: NEW → RESOLVED
Closed: 5 months ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: