@@ -520,7 +520,7 @@ static OverLimitStrategy createOverLimitStrategy(boolean trackRealMemoryUsage) {
520
520
HierarchyCircuitBreakerService ::realMemoryUsage ,
521
521
createYoungGcCountSupplier (),
522
522
System ::currentTimeMillis ,
523
- 5000 ,
523
+ 500 ,
524
524
lockTimeout
525
525
);
526
526
} else {
@@ -561,6 +561,8 @@ static class G1OverLimitStrategy implements OverLimitStrategy {
561
561
562
562
private long blackHole ;
563
563
private final ReleasableLock lock = new ReleasableLock (new ReentrantLock ());
564
+ // used to throttle logging
565
+ private int attemptNo ;
564
566
565
567
G1OverLimitStrategy (
566
568
JvmInfo jvmInfo ,
@@ -607,9 +609,12 @@ public MemoryUsage overLimit(MemoryUsage memoryUsed) {
607
609
boolean leader = false ;
608
610
int allocationIndex = 0 ;
609
611
long allocationDuration = 0 ;
612
+ long begin = 0 ;
613
+ int attemptNoCopy = 0 ;
610
614
try (ReleasableLock locked = lock .tryAcquire (lockTimeout )) {
611
615
if (locked != null ) {
612
- long begin = timeSupplier .getAsLong ();
616
+ attemptNoCopy = ++this .attemptNo ;
617
+ begin = timeSupplier .getAsLong ();
613
618
leader = begin >= lastCheckTime + minimumInterval ;
614
619
overLimitTriggered (leader );
615
620
if (leader ) {
@@ -641,9 +646,11 @@ public MemoryUsage overLimit(MemoryUsage memoryUsed) {
641
646
long now = timeSupplier .getAsLong ();
642
647
this .lastCheckTime = now ;
643
648
allocationDuration = now - begin ;
649
+ this .attemptNo = 0 ;
644
650
}
645
651
}
646
652
} catch (InterruptedException e ) {
653
+ logger .info ("could not acquire lock when attempting to trigger G1GC due to high heap usage" );
647
654
Thread .currentThread ().interrupt ();
648
655
// fallthrough
649
656
}
@@ -658,6 +665,13 @@ public MemoryUsage overLimit(MemoryUsage memoryUsed) {
658
665
allocationIndex ,
659
666
allocationDuration
660
667
);
668
+ } else if (attemptNoCopy < 10 || Long .bitCount (attemptNoCopy ) == 1 ) {
669
+ logger .info (
670
+ "memory usage down after [{}], before [{}], after [{}]" ,
671
+ begin - lastCheckTime ,
672
+ memoryUsed .baseUsage ,
673
+ current
674
+ );
661
675
}
662
676
return new MemoryUsage (
663
677
current ,
@@ -674,6 +688,13 @@ public MemoryUsage overLimit(MemoryUsage memoryUsed) {
674
688
allocationIndex ,
675
689
allocationDuration
676
690
);
691
+ } else if (attemptNoCopy < 10 || Long .bitCount (attemptNoCopy ) == 1 ) {
692
+ logger .info (
693
+ "memory usage not down after [{}], before [{}], after [{}]" ,
694
+ begin - lastCheckTime ,
695
+ memoryUsed .baseUsage ,
696
+ current
697
+ );
677
698
}
678
699
// prefer original measurement when reporting if heap usage was not brought down.
679
700
return memoryUsed ;
0 commit comments