Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
quic: add blockCount statistic
Browse files Browse the repository at this point in the history
Count the number of times sending stream data is blocked by
flow control

PR-URL: #213
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
jasnell committed Dec 4, 2019
1 parent 096f2da commit 55236e0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 1 deletion.
13 changes: 13 additions & 0 deletions doc/api/quic.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,19 @@ added: REPLACEME
A `BigInt` representing the total number of bidirectional streams
created for this `QuicSession`.

#### quicsession.blockCount
<!-- YAML
added: REPLACEME
-->

* Type: {BigInt}

A `BigInt` representing the total number of times the `QuicSession` has
been blocked from sending stream data due to flow control.

Such blocks indicate that transmitted stream data is not being consumed
quickly enough by the connected peer.

#### quicsession.bytesInFlight
<!-- YAML
added: REPLACEME
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const {
IDX_QUIC_SESSION_STATS_LOSS_RETRANSMIT_COUNT,
IDX_QUIC_SESSION_STATS_ACK_DELAY_RETRANSMIT_COUNT,
IDX_QUIC_SESSION_STATS_MAX_BYTES_IN_FLIGHT,
IDX_QUIC_SESSION_STATS_BLOCK_COUNT,
ERR_INVALID_REMOTE_TRANSPORT_PARAMS,
ERR_INVALID_TLS_SESSION_TICKET,
NGTCP2_PATH_VALIDATION_RESULT_FAILURE,
Expand Down Expand Up @@ -1702,6 +1703,11 @@ class QuicSession extends EventEmitter {
this[kHandle].state[IDX_QUIC_SESSION_STATE_BYTES_IN_FLIGHT] : 0;
}

get blockCount() {
return this[kHandle] ?
this[kHandle].state[IDX_QUIC_SESSION_STATS_BLOCK_COUNT] : 0;
}

get authenticated() {
// Specifically check for null. Undefined means the check has not
// been performed yet, another other value other than null means
Expand Down
1 change: 1 addition & 0 deletions src/node_quic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void Initialize(Local<Object> target,
NODE_DEFINE_CONSTANT(constants,
IDX_QUIC_SESSION_STATS_PATH_VALIDATION_FAILURE_COUNT);
NODE_DEFINE_CONSTANT(constants, IDX_QUIC_SESSION_STATS_MAX_BYTES_IN_FLIGHT);
NODE_DEFINE_CONSTANT(constants, IDX_QUIC_SESSION_STATS_BLOCK_COUNT);

NODE_DEFINE_CONSTANT(constants, IDX_HTTP3_QPACK_MAX_TABLE_CAPACITY);
NODE_DEFINE_CONSTANT(constants, IDX_HTTP3_QPACK_BLOCKED_STREAMS);
Expand Down
1 change: 1 addition & 0 deletions src/node_quic_default_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ bool DefaultApplication::SendStreamData(QuicStream* stream) {
return false;
case NGTCP2_ERR_STREAM_DATA_BLOCKED:
Debug(stream, "Stream data blocked");
Session()->StreamDataBlocked(stream->GetID());
return true;
case NGTCP2_ERR_STREAM_SHUT_WR:
Debug(stream, "Stream writable side is closed");
Expand Down
1 change: 1 addition & 0 deletions src/node_quic_http3_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ bool Http3Application::SendPendingData() {
if (nwrite < 0) {
switch (nwrite) {
case NGTCP2_ERR_STREAM_DATA_BLOCKED:
Session()->StreamDataBlocked(stream_id);
if (Session()->GetMaxDataLeft() == 0)
return true;
// Fall through
Expand Down
5 changes: 5 additions & 0 deletions src/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,11 @@ void QuicSession::RemoveListener(QuicSessionListener* listener) {
listener->previous_listener_ = nullptr;
}

void QuicSession::StreamDataBlocked(int64_t stream_id) {
// Increments the block count
IncrementStat(1, &session_stats_, &session_stats::block_count);
}

std::string QuicSession::diagnostic_name() const {
return std::string("QuicSession ") +
(IsServer() ? "Server" : "Client") +
Expand Down
9 changes: 8 additions & 1 deletion src/node_quic_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ enum QuicSessionStatsIdx : int {
IDX_QUIC_SESSION_STATS_ACK_DELAY_RETRANSMIT_COUNT,
IDX_QUIC_SESSION_STATS_PATH_VALIDATION_SUCCESS_COUNT,
IDX_QUIC_SESSION_STATS_PATH_VALIDATION_FAILURE_COUNT,
IDX_QUIC_SESSION_STATS_MAX_BYTES_IN_FLIGHT
IDX_QUIC_SESSION_STATS_MAX_BYTES_IN_FLIGHT,
IDX_QUIC_SESSION_STATS_BLOCK_COUNT,
};

class QuicSessionListener {
Expand Down Expand Up @@ -933,6 +934,9 @@ class QuicSession : public AsyncWrap,

void SetConnectionIDStrategory(ConnectionIDStrategy* strategy);

// Report that the stream data is flow control blocked
void StreamDataBlocked(int64_t stream_id);

// Tracks whether or not we are currently within an ngtcp2 callback
// function. Certain ngtcp2 APIs are not supposed to be called when
// within a callback. We use this as a gate to check.
Expand Down Expand Up @@ -1370,6 +1374,9 @@ class QuicSession : public AsyncWrap,
uint64_t path_validation_failure_count;
// The max number of in flight bytes recorded
uint64_t max_bytes_in_flight;
// The total number of times the session has been
// flow control blocked.
uint64_t block_count;
};
session_stats session_stats_{};

Expand Down

0 comments on commit 55236e0

Please sign in to comment.