@@ -84,7 +84,7 @@ public MockNioTransport(Settings settings, Version version, ThreadPool threadPoo
8484 PageCacheRecycler pageCacheRecycler , NamedWriteableRegistry namedWriteableRegistry ,
8585 CircuitBreakerService circuitBreakerService ) {
8686 super (settings , version , threadPool , pageCacheRecycler , circuitBreakerService , namedWriteableRegistry , networkService );
87- this .transportThreadWatchdog = new TransportThreadWatchdog (threadPool );
87+ this .transportThreadWatchdog = new TransportThreadWatchdog (threadPool , settings );
8888 }
8989
9090 @ Override
@@ -330,21 +330,20 @@ public void sendMessage(BytesReference reference, ActionListener<Void> listener)
330330 }
331331
332332 static final class TransportThreadWatchdog {
333-
334- private static final long WARN_THRESHOLD = TimeUnit .MILLISECONDS .toNanos (150 );
335-
336333 // Only check every 2s to not flood the logs on a blocked thread.
337334 // We mostly care about long blocks and not random slowness anyway and in tests would randomly catch slow operations that block for
338335 // less than 2s eventually.
339336 private static final TimeValue CHECK_INTERVAL = TimeValue .timeValueSeconds (2 );
340337
338+ private final long warnThreshold ;
341339 private final ThreadPool threadPool ;
342340 private final ConcurrentHashMap <Thread , Long > registry = new ConcurrentHashMap <>();
343341
344342 private volatile boolean stopped ;
345343
346- TransportThreadWatchdog (ThreadPool threadPool ) {
344+ TransportThreadWatchdog (ThreadPool threadPool , Settings settings ) {
347345 this .threadPool = threadPool ;
346+ warnThreshold = ThreadPool .ESTIMATED_TIME_INTERVAL_SETTING .get (settings ).nanos () + TimeValue .timeValueMillis (100L ).nanos ();
348347 threadPool .schedule (this ::logLongRunningExecutions , CHECK_INTERVAL , ThreadPool .Names .GENERIC );
349348 }
350349
@@ -361,7 +360,7 @@ public void unregister() {
361360
362361 private void maybeLogElapsedTime (long startTime ) {
363362 long elapsedTime = threadPool .relativeTimeInNanos () - startTime ;
364- if (elapsedTime > WARN_THRESHOLD ) {
363+ if (elapsedTime > warnThreshold ) {
365364 logger .warn (
366365 new ParameterizedMessage ("Slow execution on network thread [{} milliseconds]" ,
367366 TimeUnit .NANOSECONDS .toMillis (elapsedTime )),
@@ -372,7 +371,7 @@ private void maybeLogElapsedTime(long startTime) {
372371 private void logLongRunningExecutions () {
373372 for (Map .Entry <Thread , Long > entry : registry .entrySet ()) {
374373 final long elapsedTimeInNanos = threadPool .relativeTimeInNanos () - entry .getValue ();
375- if (elapsedTimeInNanos > WARN_THRESHOLD ) {
374+ if (elapsedTimeInNanos > warnThreshold ) {
376375 final Thread thread = entry .getKey ();
377376 logger .warn ("Potentially blocked execution on network thread [{}] [{} milliseconds]: \n {}" , thread .getName (),
378377 TimeUnit .NANOSECONDS .toMillis (elapsedTimeInNanos ),
0 commit comments