From 2f4bdb961bd3d21489363d9ce4ab2fe4933803e6 Mon Sep 17 00:00:00 2001 From: "Ray J. Greenwell" Date: Wed, 23 Apr 2014 09:50:16 -0700 Subject: [PATCH] Fixed a longstanding issue with long thresholds. There was no way to set the "long threshold" per-Invoker. A Unit could override getLongThreshold(), or you could set a static jvm-wide long threshold for all Invokers. That doesn't make sense. Set the long threshold you need on each invoker. All existing behavior is preserved for the time being, but I've deprecated the static method. Units return 0 now to indicate that they don't have their own setting. I'm pretty sure nobody out there is doing anything kooky like "return 500 + super.getLongThreshold();" at least in the code I've scanned. --- .../java/com/samskivert/util/Invoker.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/samskivert/util/Invoker.java b/src/main/java/com/samskivert/util/Invoker.java index b90dc9cf..632dcae3 100644 --- a/src/main/java/com/samskivert/util/Invoker.java +++ b/src/main/java/com/samskivert/util/Invoker.java @@ -83,11 +83,12 @@ public class Invoker extends LoopingThread /** * Returns the duration beyond which this invoker unit will be considered to be running too - * long and result in a warning being logged. The default is 500ms. + * long, or 0 to use the default value. If performance tracking is enabled and this unit + * runs to long, a warning will be logged. */ public long getLongThreshold () { - return _defaultLongThreshold; + return 0L; } /** @@ -112,6 +113,7 @@ public class Invoker extends LoopingThread * Configures the default duration (in milliseconds) for an invoker unit to be reported as * "long". Long units will result in a warning message written to the log. */ + @Deprecated public static void setDefaultLongThreshold (long millis) { _defaultLongThreshold = millis; @@ -126,6 +128,15 @@ public class Invoker extends LoopingThread _receiver = resultReceiver; } + /** + * Set the long threshold for this Invoker. Units that do not specify their own threshold + * will be reported as "long" if their duration exceeds this time. + */ + public void setLongThreshold (long millis) + { + _longThreshold = millis; + } + /** * Posts a unit to this invoker for subsequent invocation on the invoker's thread. */ @@ -271,9 +282,16 @@ public class Invoker extends LoopingThread recordMetrics(key, duration); // report long runners - if (duration > unit.getLongThreshold()) { + long thresh = unit.getLongThreshold(); + if (thresh == 0) { + // TODO: remove _defaultLongThreshold + thresh = (_longThreshold == 0) + ? _defaultLongThreshold + : _longThreshold; + } + if (duration > thresh) { StringBuilder msg = new StringBuilder(); - msg.append((duration >= 10*unit.getLongThreshold()) ? "Really long" : "Long"); + msg.append((duration >= 10*thresh) ? "Really long" : "Long"); msg.append(" invoker unit [unit=").append(unit); msg.append(" (").append(key).append("), time=").append(duration).append("ms"); if (unit.getDetail() != null) { @@ -335,7 +353,11 @@ public class Invoker extends LoopingThread /** Default number of buckets to use when profiling unit times. */ protected int _profileBucketCount = 10; + /** The long threshold for this particular invoker. */ + protected long _longThreshold = 0L; // unset + /** The duration of time after which we consider a unit to be delinquent and log a warning. */ + @Deprecated protected static long _defaultLongThreshold = 500L; /** True after {@link #shutdown} has been called but before the invoker has finished processing