Skip to content

Commit 43ba912

Browse files
committed
Add some debug logging to the allocate process when there is a backlog.
Fix some bugs identified by unit test I haven't committed yet (because it is still failing) git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1685091 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0b57b4e commit 43ba912

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

java/org/apache/coyote/http2/Http2UpgradeHandler.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ private void releaseBackLog(int increment) {
563563
while (leftToAllocate > 0) {
564564
leftToAllocate = allocate(this, leftToAllocate);
565565
}
566-
allocate(this, increment);
567566
for (Entry<AbstractStream,int[]> entry : backLogStreams.entrySet()) {
568567
int allocation = entry.getValue()[1];
569568
if (allocation > 0) {
@@ -578,6 +577,10 @@ private void releaseBackLog(int increment) {
578577

579578

580579
private int allocate(AbstractStream stream, int allocation) {
580+
if (log.isDebugEnabled()) {
581+
log.debug(sm.getString("upgradeHandler.allocate.debug", getConnectionId(),
582+
stream.getIdentifier(), Integer.toString(allocation)));
583+
}
581584
// Allocate to the specified stream
582585
int[] value = backLogStreams.get(stream);
583586
if (value[0] >= allocation) {
@@ -593,6 +596,11 @@ private int allocate(AbstractStream stream, int allocation) {
593596
value[0] = 0;
594597
leftToAllocate -= value[1];
595598

599+
if (log.isDebugEnabled()) {
600+
log.debug(sm.getString("upgradeHandler.allocate.left",
601+
getConnectionId(), stream.getIdentifier(), Integer.toString(leftToAllocate)));
602+
}
603+
596604
// Recipients are children of the current stream that are in the
597605
// backlog.
598606
Set<AbstractStream> recipients = new HashSet<>();
@@ -608,6 +616,11 @@ private int allocate(AbstractStream stream, int allocation) {
608616

609617
int totalWeight = 0;
610618
for (AbstractStream recipient : recipients) {
619+
if (log.isDebugEnabled()) {
620+
log.debug(sm.getString("upgradeHandler.allocate.recipient",
621+
getConnectionId(), stream.getIdentifier(), recipient.getIdentifier(),
622+
Integer.toString(recipient.getWeight())));
623+
}
611624
totalWeight += recipient.getWeight();
612625
}
613626

@@ -616,10 +629,13 @@ private int allocate(AbstractStream stream, int allocation) {
616629
Iterator<AbstractStream> iter = recipients.iterator();
617630
while (iter.hasNext()) {
618631
AbstractStream recipient = iter.next();
619-
// +1 is to avoid rounding issues triggering an infinite loop.
620-
// Will cause a very slight over allocation but HTTP/2 should
621-
// cope with that.
622-
int share = 1 + leftToAllocate * recipient.getWeight() / totalWeight;
632+
int share = leftToAllocate * recipient.getWeight() / totalWeight;
633+
if (share == 0) {
634+
// This is to avoid rounding issues triggering an infinite
635+
// loop. It will cause a very slight over allocation but
636+
// HTTP/2 should cope with that.
637+
share = 1;
638+
}
623639
int remainder = allocate(recipient, share);
624640
// Remove recipients that receive their full allocation so that
625641
// they are excluded from the next allocation round.

java/org/apache/coyote/http2/LocalStrings.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ streamProcessor.httpupgrade.notsupported=HTTP upgrade is not supported within HT
6666
streamStateMachine.debug.change=Connection [{0}], Stream [{1}], State changed from [{2}] to [{3}]
6767
streamStateMachine.invalidFrame=Connection [{0}], Stream [{1}], State [{2}], Frame type [{3}]
6868

69+
upgradeHandler.allocate.debug=Connection [{0}], Stream [{1}], allocated [{2}] bytes
70+
upgradeHandler.allocate.left=Connection [{0}], Stream [{1}], [{2}] bytes unallocated - trying to allocate to children
71+
upgradeHandler.allocate.recipient=Connection [{0}], Stream [{1}], potential recipient [{2}] with weight [{3}]
6972
upgradeHandler.rst.debug=Connection [{0}], Stream [{1}], Error [{2}], RST (closing stream)
7073
upgradeHandler.goaway.debug=Connection [{0}], Goaway, Last stream [{1}], Error code [{2}], Debug data [{3}]
7174
upgradeHandler.init=Connection [{0}]

0 commit comments

Comments
 (0)