Reduce overhead of cancel flowcontrolled writes.

Motivation:

When we cancel the flowcontrolled writes we did create a new StreamException for each write that was enqueued. Creating Exceptions is very expensive due of filling the stacktrace.

Modifications:

Only create the StreamException once and reuse the same for all the flowcontrolled writes (per stream).

Result:

Less expensive to cancel flowcontrolled writes.
This commit is contained in:
Norman Maurer 2018-01-23 09:15:37 +01:00
parent 2d815fa752
commit b769ec0934

View File

@ -480,13 +480,15 @@ public class DefaultHttp2RemoteFlowController implements Http2RemoteFlowControll
return;
}
for (;;) {
FlowControlled frame = pendingWriteQueue.poll();
if (frame == null) {
break;
}
writeError(frame, streamError(stream.id(), INTERNAL_ERROR, cause,
"Stream closed before write could take place"));
FlowControlled frame = pendingWriteQueue.poll();
if (frame != null) {
// Only create exception once and reuse to reduce overhead of filling in the stacktrace.
final Http2Exception exception = streamError(stream.id(), INTERNAL_ERROR, cause,
"Stream closed before write could take place");
do {
writeError(frame, exception);
frame = pendingWriteQueue.poll();
} while (frame != null);
}
streamByteDistributor.updateStreamableBytes(this);