@@ -84,7 +84,7 @@ public MockNioTransport(Settings settings, Version version, ThreadPool threadPoo
84
84
PageCacheRecycler pageCacheRecycler , NamedWriteableRegistry namedWriteableRegistry ,
85
85
CircuitBreakerService circuitBreakerService ) {
86
86
super (settings , version , threadPool , pageCacheRecycler , circuitBreakerService , namedWriteableRegistry , networkService );
87
- this .transportThreadWatchdog = new TransportThreadWatchdog (threadPool );
87
+ this .transportThreadWatchdog = new TransportThreadWatchdog (threadPool , settings );
88
88
}
89
89
90
90
@ Override
@@ -330,21 +330,20 @@ public void sendMessage(BytesReference reference, ActionListener<Void> listener)
330
330
}
331
331
332
332
static final class TransportThreadWatchdog {
333
-
334
- private static final long WARN_THRESHOLD = TimeUnit .MILLISECONDS .toNanos (150 );
335
-
336
333
// Only check every 2s to not flood the logs on a blocked thread.
337
334
// We mostly care about long blocks and not random slowness anyway and in tests would randomly catch slow operations that block for
338
335
// less than 2s eventually.
339
336
private static final TimeValue CHECK_INTERVAL = TimeValue .timeValueSeconds (2 );
340
337
338
+ private final long warnThreshold ;
341
339
private final ThreadPool threadPool ;
342
340
private final ConcurrentHashMap <Thread , Long > registry = new ConcurrentHashMap <>();
343
341
344
342
private volatile boolean stopped ;
345
343
346
- TransportThreadWatchdog (ThreadPool threadPool ) {
344
+ TransportThreadWatchdog (ThreadPool threadPool , Settings settings ) {
347
345
this .threadPool = threadPool ;
346
+ warnThreshold = ThreadPool .ESTIMATED_TIME_INTERVAL_SETTING .get (settings ).nanos () + TimeValue .timeValueMillis (100L ).nanos ();
348
347
threadPool .schedule (this ::logLongRunningExecutions , CHECK_INTERVAL , ThreadPool .Names .GENERIC );
349
348
}
350
349
@@ -361,7 +360,7 @@ public void unregister() {
361
360
362
361
private void maybeLogElapsedTime (long startTime ) {
363
362
long elapsedTime = threadPool .relativeTimeInNanos () - startTime ;
364
- if (elapsedTime > WARN_THRESHOLD ) {
363
+ if (elapsedTime > warnThreshold ) {
365
364
logger .warn (
366
365
new ParameterizedMessage ("Slow execution on network thread [{} milliseconds]" ,
367
366
TimeUnit .NANOSECONDS .toMillis (elapsedTime )),
@@ -372,7 +371,7 @@ private void maybeLogElapsedTime(long startTime) {
372
371
private void logLongRunningExecutions () {
373
372
for (Map .Entry <Thread , Long > entry : registry .entrySet ()) {
374
373
final long elapsedTimeInNanos = threadPool .relativeTimeInNanos () - entry .getValue ();
375
- if (elapsedTimeInNanos > WARN_THRESHOLD ) {
374
+ if (elapsedTimeInNanos > warnThreshold ) {
376
375
final Thread thread = entry .getKey ();
377
376
logger .warn ("Potentially blocked execution on network thread [{}] [{} milliseconds]: \n {}" , thread .getName (),
378
377
TimeUnit .NANOSECONDS .toMillis (elapsedTimeInNanos ),
0 commit comments