Constant number of threads running lookupServerDescription

6 threads in each thread dump are running DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription. As this code is part of health checks, why do we need this running in 6 threads at any point in time? Is this configurable?

at Method)
at com.mongodb.internal.connection.InternalStreamConnection.receiveResponseBuffers(
at com.mongodb.internal.connection.InternalStreamConnection.receiveMessageWithAdditionalTimeout(
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(
at com.mongodb.internal.connection.InternalStreamConnection.receive(
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(
at com.mongodb.internal.connection.DefaultServerMonitor$

This is expected behavior of all drivers. We use threads so that the monitoring of each server can happen concurrently. We have two threads per server so that we can measure RTT independently of a more complicated topology check.

Are the threads causing issues for your application, or is it just something you noticed?


We noticed this in our thread dumps where some performance issues are being analyzed. So far, we did not find any correlation between these threads and the performance issue, but were wondering why the threads are waiting on SocketInputStream.socketRead? From your response, it sounds like, it is waiting for monitoring data to be sent by the server and that is normal.

Yes, completely normal. The monitoring uses a form of long polling so it’s expected that these threads are blocked on Socket#read most of the time rather than in, say, Thread#sleep.