2121import java .util .concurrent .ScheduledThreadPoolExecutor ;
2222import java .util .concurrent .TimeUnit ;
2323
24- import org .apache .hadoop .hbase .util .MovingAverage ;
25- import org .apache .hadoop .hbase .util .WindowMovingAverage ;
2624import org .apache .yetus .audience .InterfaceAudience ;
2725import org .slf4j .Logger ;
2826import org .slf4j .LoggerFactory ;
@@ -81,10 +79,6 @@ public abstract class ScheduledChore implements Runnable {
8179 */
8280 private final Stoppable stopper ;
8381
84- private final MovingAverage <Void > timeMeasurement ;
85- private static final long FIVE_MINUTES_IN_NANOS = TimeUnit .MINUTES .toNanos (5L );
86- private long lastLog = System .nanoTime ();
87-
8882 interface ChoreServicer {
8983 /**
9084 * Cancel any ongoing schedules that this chore has with the implementer of this interface.
@@ -165,7 +159,6 @@ public ScheduledChore(final String name, Stoppable stopper, final int period,
165159 this .period = period ;
166160 this .initialDelay = initialDelay < 0 ? 0 : initialDelay ;
167161 this .timeUnit = unit ;
168- this .timeMeasurement = new WindowMovingAverage (name );
169162 }
170163
171164 /**
@@ -183,18 +176,21 @@ public void run() {
183176 if (LOG .isInfoEnabled ()) LOG .info ("Chore: " + getName () + " was stopped" );
184177 } else {
185178 try {
179+ // TODO: Histogram metrics per chore name.
180+ // For now, just measure and log if DEBUG level logging is enabled.
181+ long start = 0 ;
182+ if (LOG .isDebugEnabled ()) {
183+ start = System .nanoTime ();
184+ }
186185 if (!initialChoreComplete ) {
187186 initialChoreComplete = initialChore ();
188187 } else {
189- timeMeasurement .measure (() -> {
190- chore ();
191- return null ;
192- });
193- if (LOG .isInfoEnabled () && (System .nanoTime () - lastLog > FIVE_MINUTES_IN_NANOS )) {
194- LOG .info ("{} average execution time: {} ns." , getName (),
195- (long )(timeMeasurement .getAverageTime ()));
196- lastLog = System .nanoTime ();
197- }
188+ chore ();
189+ }
190+ if (LOG .isDebugEnabled () && start > 0 ) {
191+ long end = System .nanoTime ();
192+ LOG .debug ("{} execution time: {} ms." , getName (),
193+ TimeUnit .NANOSECONDS .toMillis (end - start ));
198194 }
199195 } catch (Throwable t ) {
200196 if (LOG .isErrorEnabled ()) LOG .error ("Caught error" , t );
0 commit comments