Permalink
Browse files

[split] GC monitor: be more quiet about missed GCs

Log these at most once every ½ hour.

RB_ID=79217
  • Loading branch information...
1 parent 291d309 commit eb9aca7b5684fb1157c5e7c9a60a80f77361bb8c @mariusae mariusae committed Aug 7, 2012
@@ -71,7 +71,10 @@ trait Jvm {
*/
def foreachGc(f: Gc => Unit) {
val Period = 1.second
+ val LogPeriod = 30.minutes
val log = Logger.getLogger(getClass.getName)
+ @volatile var missedCollections = 0L
+ @volatile var lastLog = Time.epoch
val lastByName = mutable.HashMap[String, Long]()
def sample() {
@@ -81,8 +84,12 @@ trait Jvm {
lastByName.get(name) match {
case Some(`count`) => // old
case Some(lastCount) =>
- if (lastCount != count-1)
- log.warning("Missed %d collections for %s due to sampling".format(count-1-lastCount, name))
+ missedCollections += count - 1 - lastCount
+ if (missedCollections > 0 && Time.now - lastLog > LogPeriod) {
+ log.warning("Missed %d collections for %s due to sampling".format(missedCollections, name))
+ lastLog = Time.now
+ missedCollections = 0
+ }
f(gc)
case None =>
f(gc)
@@ -67,7 +67,7 @@ class JvmSpec extends SpecificationWithJUnit with Mockito with TestLogging {
b(3) must be_==(gc1.copy(count=1))
}
- "Complain when sampling rate is too low" in {
+ "Complain when sampling rate is too low, every 30 minutes" in Time.withCurrentTimeFrozen { tc =>
traceLogger(Level.WARNING)
jvm foreachGc { _ => /*ignore*/}
@@ -79,7 +79,20 @@ class JvmSpec extends SpecificationWithJUnit with Mockito with TestLogging {
r.run()
jvm.pushGc(gc.copy(count=2))
r.run()
- mustLog("Missed 1 collections for pcopy due to sampling")
+ logLines() must be_==(Seq("Missed 1 collections for pcopy due to sampling"))
+ jvm.pushGc(gc.copy(count=10))
+ logLines() must be_==(Seq("Missed 1 collections for pcopy due to sampling"))
+ r.run()
+ tc.advance(29.minutes)
+ r.run()
+ logLines() must be_==(Seq("Missed 1 collections for pcopy due to sampling"))
+ tc.advance(2.minutes)
+ jvm.pushGc(gc.copy(count=12))
+ r.run()
+ logLines() must be_==(Seq(
+ "Missed 1 collections for pcopy due to sampling",
+ "Missed 8 collections for pcopy due to sampling"
+ ))
}
}
@@ -65,13 +65,14 @@ trait TestLogging { self: Specification =>
logger.clearHandlers()
logger.addHandler(traceHandler)
}
+
+ def logLines(): Seq[String] = traceHandler.get.split("\n")
/**
* Verify that the logger set up with `traceLogger` has received a log line with the given
* substring somewhere inside it.
*/
def mustLog(substring: String) = {
- val lines = traceHandler.get.split("\n")
- lines.filter { _ contains substring }.size must be_>(0)
+ logLines().filter { _ contains substring }.size must be_>(0)
}
}

0 comments on commit eb9aca7

Please sign in to comment.