Skip to content

Commit

Permalink
HTTP/2 flow control tracing
Browse files Browse the repository at this point in the history
subchannel_flowctrl tracer, if enabled, logs local and remote window
sizes of subchannel's HTTP2 session to debug log every 5 seconds.
  • Loading branch information
nimf committed Feb 9, 2022
1 parent faa79fe commit c0052a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ can be set.
- `server_call` - Traces server handling of individual requests
- `subchannel` - Traces subchannel connectivity state and errors
- `subchannel_refcount` - Traces subchannel refcount changes
- `subchannel_flowctrl` - Traces HTTP/2 flow control

The following tracers are added by the `@grpc/grpc-js-xds` library:
- `cds_balancer` - Traces the CDS load balancing policy
Expand Down
18 changes: 18 additions & 0 deletions packages/grpc-js/src/subchannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { SubchannelRef, ChannelzTrace, ChannelzChildrenTracker, SubchannelInfo,
const clientVersion = require('../../package.json').version;

const TRACER_NAME = 'subchannel';
const FLOW_CONTROL_TRACER_NAME = 'subchannel_flowctrl';

const MIN_CONNECT_TIMEOUT_MS = 20000;
const INITIAL_BACKOFF_MS = 1000;
Expand Down Expand Up @@ -176,6 +177,7 @@ export class Subchannel {
private messagesReceived = 0;
private lastMessageSentTimestamp: Date | null = null;
private lastMessageReceivedTimestamp: Date | null = null;
private windowReportInterval: NodeJS.Timer | null = null;

/**
* A class representing a connection to a single backend.
Expand Down Expand Up @@ -324,6 +326,10 @@ export class Subchannel {
logging.trace(LogVerbosity.DEBUG, 'subchannel_refcount', '(' + this.channelzRef.id + ') ' + this.subchannelAddressString + ' ' + text);
}

private flowControlTrace(text: string): void {
logging.trace(LogVerbosity.DEBUG, FLOW_CONTROL_TRACER_NAME, '(' + this.channelzRef.id + ') ' + this.subchannelAddressString + ' ' + text);
}

private handleBackoffTimer() {
if (this.continueConnecting) {
this.transitionToState(
Expand Down Expand Up @@ -573,6 +579,18 @@ export class Subchannel {
);
});
}
if (logging.isTracerEnabled(FLOW_CONTROL_TRACER_NAME)) {
this.windowReportInterval = setInterval(() => {
if (!this.session) {
if (this.windowReportInterval) {
clearInterval(this.windowReportInterval);
}
return;
}
this.flowControlTrace('local window size: ' + this.session.state.localWindowSize);
this.flowControlTrace('remote window size: ' + this.session.state.remoteWindowSize);
}, 5000);
}
}

private startConnectingInternal() {
Expand Down

0 comments on commit c0052a1

Please sign in to comment.