Commit 43a9d71
committed
http: reduce per-request server overhead
Eliminate per-request work that is invariant or redundant on the server
response path:
- end(chunk) issued a second, empty socket.write whose only purpose was
to carry the finish callback, paying a full Writable pass and an
extra cork-queue entry per response. When the header block is already
rendered and the framing is final (no chunked trailer, no strict
content-length accounting), the finish callback rides the body write
itself; writes complete in order, so the observable finish timing is
unchanged.
- The response options bag and the pending-data callback only depend on
the connection, not the request: allocate them once per socket and
reuse them for every response on a keep-alive connection.
- The response close listener is a no-op unless a response is attached
(socket._httpMessage guard), so it is installed once per socket
instead of paying the add/removeListener pair per response.
- Status lines for default reason phrases are cached per status code,
and the Keep-Alive header line is memoized per (timeout, max)
configuration.
Measured with a CPU-per-request harness (fresh process per sample,
25x600k-request interleaved samples, Welch t-test) on a keep-alive
hello-world server: +7.34% requests per CPU-second (p=2.0e-14), and
about +6.4% requests/sec under autocannon. All test/parallel http and
https tests pass.
Assisted-by: Grok
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>1 parent 85c887a commit 43a9d71
2 files changed
Lines changed: 91 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
544 | 551 | | |
545 | | - | |
| 552 | + | |
546 | 553 | | |
547 | 554 | | |
548 | 555 | | |
| |||
930 | 937 | | |
931 | 938 | | |
932 | 939 | | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
933 | 944 | | |
934 | 945 | | |
935 | 946 | | |
| |||
1140 | 1151 | | |
1141 | 1152 | | |
1142 | 1153 | | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
1143 | 1165 | | |
1144 | 1166 | | |
1145 | 1167 | | |
| |||
1152 | 1174 | | |
1153 | 1175 | | |
1154 | 1176 | | |
1155 | | - | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
1156 | 1191 | | |
1157 | 1192 | | |
1158 | 1193 | | |
| |||
1178 | 1213 | | |
1179 | 1214 | | |
1180 | 1215 | | |
1181 | | - | |
| 1216 | + | |
| 1217 | + | |
1182 | 1218 | | |
1183 | | - | |
1184 | | - | |
1185 | | - | |
1186 | | - | |
1187 | | - | |
1188 | | - | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
1189 | 1226 | | |
1190 | 1227 | | |
1191 | 1228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| |||
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
189 | 194 | | |
190 | 195 | | |
191 | 196 | | |
| |||
298 | 303 | | |
299 | 304 | | |
300 | 305 | | |
301 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
302 | 314 | | |
303 | 315 | | |
304 | 316 | | |
305 | 317 | | |
306 | 318 | | |
307 | 319 | | |
308 | 320 | | |
309 | | - | |
310 | 321 | | |
311 | 322 | | |
312 | 323 | | |
| |||
467 | 478 | | |
468 | 479 | | |
469 | 480 | | |
470 | | - | |
| 481 | + | |
| 482 | + | |
471 | 483 | | |
472 | 484 | | |
473 | | - | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
474 | 495 | | |
475 | 496 | | |
476 | 497 | | |
| |||
810 | 831 | | |
811 | 832 | | |
812 | 833 | | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
813 | 838 | | |
814 | 839 | | |
815 | 840 | | |
| |||
1280 | 1305 | | |
1281 | 1306 | | |
1282 | 1307 | | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
1288 | 1318 | | |
1289 | 1319 | | |
1290 | | - | |
1291 | | - | |
| 1320 | + | |
| 1321 | + | |
1292 | 1322 | | |
1293 | 1323 | | |
1294 | 1324 | | |
| |||
0 commit comments