Skip to content

Commit

Permalink
quic: additional QuicStream tracking stats
Browse files Browse the repository at this point in the history
PR-URL: nodejs#294
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
jasnell committed Feb 3, 2020
1 parent 645b1d1 commit a41e830
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
19 changes: 19 additions & 0 deletions doc/api/quic.md
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,16 @@ added: REPLACEME

The numeric identifier of the `QuicStream`.

#### quicstream.maxAcknowledgedOffset
<!-- YAML
added: REPLACEME
-->

* Type: {BigInt}

A `BigInt` representing the highest acknowledged data offset received
for this `QuicStream`.

#### quicstream.maxExtendedOffset
<!-- YAML
added: REPLACEME
Expand All @@ -1983,6 +1993,15 @@ added: REPLACEME
A `BigInt` representing the maximum extended data offset that has been
reported to the connected peer.

#### quicstream.maxReceivedOffset
<!-- YAML
added: REPLACEME
-->

* Type: {BigInt}

A `BigInt` representing the maximum received offset for this `QuicStream`.

#### quicstream.pending
<!-- YAML
added: REPLACEME
Expand Down
12 changes: 12 additions & 0 deletions lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ const {
IDX_QUIC_STREAM_STATS_BYTES_SENT,
IDX_QUIC_STREAM_STATS_MAX_OFFSET,
IDX_QUIC_STREAM_STATS_FINAL_SIZE,
IDX_QUIC_STREAM_STATS_MAX_OFFSET_ACK,
IDX_QUIC_STREAM_STATS_MAX_OFFSET_RECV,
IDX_QUIC_SOCKET_STATS_CREATED_AT,
IDX_QUIC_SOCKET_STATS_BOUND_AT,
IDX_QUIC_SOCKET_STATS_LISTEN_AT,
Expand Down Expand Up @@ -2857,6 +2859,16 @@ class QuicStream extends Duplex {
const stats = this.#stats || this[kHandle].stats;
return stats[IDX_QUIC_STREAM_STATS_FINAL_SIZE];
}

get maxAcknowledgedOffset() {
const stats = this.#stats || this[kHandle].stats;
return stats[IDX_QUIC_STREAM_STATS_MAX_OFFSET_ACK];
}

get maxReceivedOffset() {
const stats = this.#stats || this[kHandle].stats;
return stats[IDX_QUIC_STREAM_STATS_MAX_OFFSET_RECV];
}
}

function createSocket(options) {
Expand Down
8 changes: 0 additions & 8 deletions src/quic/node_quic_stream-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ bool QuicStream::is_write_finished() const {
streambuf_.length() == 0;
}

void QuicStream::IncrementAvailableOutboundLength(size_t amount) {
available_outbound_length_ += amount;
}

void QuicStream::DecrementAvailableOutboundLength(size_t amount) {
available_outbound_length_ -= amount;
}

bool QuicStream::SubmitInformation(v8::Local<v8::Array> headers) {
return session_->SubmitInformation(stream_id_, headers);
}
Expand Down
9 changes: 4 additions & 5 deletions src/quic/node_quic_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void QuicStream::Acknowledge(uint64_t offset, size_t datalen) {
// ngtcp2 guarantees that offset must always be greater
// than the previously received offset, but let's just
// make sure that holds.
CHECK_GE(offset, max_offset_ack_);
max_offset_ack_ = offset;
CHECK_GE(offset, GetStat(&QuicStreamStats::max_offset_ack));
SetStat(&QuicStreamStats::max_offset_ack, offset);

Debug(this, "Acknowledging %d bytes", datalen);

Expand Down Expand Up @@ -216,7 +216,6 @@ int QuicStream::DoWrite(

session()->ResumeStream(stream_id_);

// IncrementAvailableOutboundLength(len);
return 0;
}

Expand Down Expand Up @@ -310,8 +309,8 @@ void QuicStream::ReceiveData(

// ngtcp2 guarantees that offset is always greater than the previously
// received offset. Let's just make sure.
CHECK_GE(offset, max_offset_);
max_offset_ = offset;
CHECK_GE(offset, GetStat(&QuicStreamStats::max_offset_received));
SetStat(&QuicStreamStats::max_offset_received, offset);

if (datalen > 0) {
// IncrementStats will update the data_rx_rate_ and data_rx_size_
Expand Down
12 changes: 4 additions & 8 deletions src/quic/node_quic_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ enum QuicStreamHeadersKind : int {
V(BYTES_RECEIVED, bytes_received, "Bytes Received") \
V(BYTES_SENT, bytes_sent, "Bytes Sent") \
V(MAX_OFFSET, max_offset, "Max Offset") \
V(MAX_OFFSET_ACK, max_offset_ack, "Max Acknowledged Offset") \
V(MAX_OFFSET_RECV, max_offset_received, "Max Received Offset") \
V(FINAL_SIZE, final_size, "Final Size")

#define V(name, _, __) IDX_QUIC_STREAM_STATS_##name,
Expand Down Expand Up @@ -280,9 +282,6 @@ class QuicStream : public AsyncWrap,
size_t nbufs,
uv_stream_t* send_handle) override;

inline void IncrementAvailableOutboundLength(size_t amount);
inline void DecrementAvailableOutboundLength(size_t amount);

// Returns false if the header cannot be added. This will
// typically only happen if a maximimum number of headers
// has been reached.
Expand Down Expand Up @@ -367,14 +366,11 @@ class QuicStream : public AsyncWrap,
void IncrementStats(size_t datalen);

BaseObjectWeakPtr<QuicSession> session_;
QuicBuffer streambuf_;

int64_t stream_id_ = 0;
int64_t push_id_ = 0;
uint64_t max_offset_ = 0;
uint64_t max_offset_ack_ = 0;
uint32_t flags_ = QUICSTREAM_FLAG_INITIAL;

QuicBuffer streambuf_;
size_t available_outbound_length_ = 0;
size_t inbound_consumed_data_while_paused_ = 0;

std::vector<std::unique_ptr<QuicHeader>> headers_;
Expand Down

0 comments on commit a41e830

Please sign in to comment.