| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,17 +6,27 @@ const PORT = common.PORT; | |||
| 6 | 6 | const bench = common.createBenchmark(main, { | |
| 7 | 7 | streams: [100, 200, 1000], | |
| 8 | 8 | length: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024], | |
| 9 | + size: [100000] | ||
| 9 | 10 | }, { flags: ['--expose-http2', '--no-warnings'] }); | |
| 10 | 11 | ||
| 11 | 12 | function main(conf) { | |
| 12 | 13 | const m = +conf.streams; | |
| 13 | 14 | const l = +conf.length; | |
| 15 | + const s = +conf.size; | ||
| 14 | 16 | const http2 = require('http2'); | |
| 15 | 17 | const server = http2.createServer(); | |
| 16 | 18 | server.on('stream', (stream) => { | |
| 17 | 19 | stream.respond(); | |
| 18 | - stream.write('ü'.repeat(l)); | ||
| 19 | - stream.end(); | ||
| 20 | + let written = 0; | ||
| 21 | + function write() { | ||
| 22 | + stream.write('ü'.repeat(s)); | ||
| 23 | + written += s; | ||
| 24 | + if (written < l) | ||
| 25 | + setImmediate(write); | ||
| 26 | + else | ||
| 27 | + stream.end(); | ||
| 28 | + } | ||
| 29 | + write(); | ||
| 20 | 30 | }); | |
| 21 | 31 | server.listen(PORT, () => { | |
| 22 | 32 | bench.http({ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -478,25 +478,54 @@ inline void Nghttp2Session::SendPendingData() { | |||
| 478 | 478 | // will not be usable. | |
| 479 | 479 | if (IsDestroying()) | |
| 480 | 480 | return; | |
| 481 | - const uint8_t* data; | ||
| 482 | - ssize_t len = 0; | ||
| 483 | - size_t ncopy = 0; | ||
| 484 | - uv_buf_t buf; | ||
| 485 | - AllocateSend(SEND_BUFFER_RECOMMENDED_SIZE, &buf); | ||
| 486 | - while (nghttp2_session_want_write(session_)) { | ||
| 487 | - len = nghttp2_session_mem_send(session_, &data); | ||
| 488 | - CHECK_GE(len, 0); // If this is less than zero, we're out of memory | ||
| 489 | - // While len is greater than 0, send a chunk | ||
| 490 | - while (len > 0) { | ||
| 491 | - ncopy = len; | ||
| 492 | - if (ncopy > buf.len) | ||
| 493 | - ncopy = buf.len; | ||
| 494 | - memcpy(buf.base, data, ncopy); | ||
| 495 | - Send(&buf, ncopy); | ||
| 496 | - len -= ncopy; | ||
| 497 | - CHECK_GE(len, 0); // This should never be less than zero | ||
| 481 | + | ||
| 482 | + uv_buf_t dest; | ||
| 483 | + AllocateSend(SEND_BUFFER_RECOMMENDED_SIZE, &dest); | ||
| 484 | + size_t destLength = 0; // amount of data stored in dest | ||
| 485 | + size_t destRemaining = dest.len; // amount space remaining in dest | ||
| 486 | + size_t destOffset = 0; // current write offset of dest | ||
| 487 | + | ||
| 488 | + const uint8_t* src; // pointer to the serialized data | ||
| 489 | + ssize_t srcLength = 0; // length of serialized data chunk | ||
| 490 | + | ||
| 491 | + // While srcLength is greater than zero | ||
| 492 | + while ((srcLength = nghttp2_session_mem_send(session_, &src)) > 0) { | ||
| 493 | + DEBUG_HTTP2("Nghttp2Session %s: nghttp2 has %d bytes to send\n", | ||
| 494 | + TypeName(), srcLength); | ||
| 495 | + size_t srcRemaining = srcLength; | ||
| 496 | + size_t srcOffset = 0; | ||
| 497 | + | ||
| 498 | + // The amount of data we have to copy is greater than the space | ||
| 499 | + // remaining. Copy what we can into the remaining space, send it, | ||
| 500 | + // the proceed with the rest. | ||
| 501 | + while (srcRemaining > destRemaining) { | ||
| 502 | + DEBUG_HTTP2("Nghttp2Session %s: pushing %d bytes to the socket\n", | ||
| 503 | + TypeName(), destRemaining); | ||
| 504 | + memcpy(dest.base + destOffset, src + srcOffset, destRemaining); | ||
| 505 | + destLength += destRemaining; | ||
| 506 | + Send(&dest, destLength); | ||
| 507 | + destOffset = 0; | ||
| 508 | + destLength = 0; | ||
| 509 | + srcRemaining -= destRemaining; | ||
| 510 | + srcOffset += destRemaining; | ||
| 511 | + destRemaining = dest.len; | ||
| 512 | + } | ||
| 513 | + | ||
| 514 | + if (srcRemaining > 0) { | ||
| 515 | + memcpy(dest.base + destOffset, src + srcOffset, srcRemaining); | ||
| 516 | + destLength += srcRemaining; | ||
| 517 | + destOffset += srcRemaining; | ||
| 518 | + destRemaining -= srcRemaining; | ||
| 519 | + srcRemaining = 0; | ||
| 520 | + srcOffset = 0; | ||
| 498 | 521 | } | |
| 499 | 522 | } | |
| 523 | + | ||
| 524 | + if (destLength > 0) { | ||
| 525 | + DEBUG_HTTP2("Nghttp2Session %s: pushing %d bytes to the socket\n", | ||
| 526 | + TypeName(), destLength); | ||
| 527 | + Send(&dest, destLength); | ||
| 528 | + } | ||
| 500 | 529 | } | |
| 501 | 530 | ||
| 502 | 531 | // Initialize the Nghttp2Session handle by creating and | |
| Back | FazBrowse Home | New Git URL |
0 commit comments