Skip to content

Commit

Permalink
http: add comment about outputSize in res/server
Browse files Browse the repository at this point in the history
PR-URL: #3128
  • Loading branch information
indutny authored and rvagg committed Oct 5, 2015
1 parent 25e3b82 commit f638402
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ utcDate._onTimeout = function() {
function OutgoingMessage() {
Stream.call(this);

// Queue that holds all currently pending data, until the response will be
// assigned to the socket (until it will its turn in the HTTP pipeline).
this.output = [];
this.outputEncodings = [];
this.outputCallbacks = [];

// `outputSize` is an approximate measure of how much data is queued on this
// response. `_onPendingData` will be invoked to update similar global
// per-connection counter. That counter will be used to pause/unpause the
// TCP socket and HTTP Parser and thus handle the backpressure.
this.outputSize = 0;

this.writable = true;
Expand Down
4 changes: 4 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ function connectionListener(socket) {
var outgoingData = 0;

function updateOutgoingData(delta) {
// `outgoingData` is an approximate amount of bytes queued through all
// inactive responses. If more data than the high watermark is queued - we
// need to pause TCP socket/HTTP parser, and wait until the data will be
// sent to the client.
outgoingData += delta;
if (socket._paused && outgoingData < socket._writableState.highWaterMark)
return socketOnDrain();
Expand Down

0 comments on commit f638402

Please sign in to comment.