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 java.net.SocketInputStream.socketRead0(java.base@11.0.18/Native Method)
at java.net.SocketInputStream.socketRead(java.base@11.0.18/SocketInputStream.java:115)
at java.net.SocketInputStream.read(java.base@11.0.18/SocketInputStream.java:168)
at java.net.SocketInputStream.read(java.base@11.0.18/SocketInputStream.java:140)
at com.mongodb.internal.connection.SocketStream.read(SocketStream.java:109)
at com.mongodb.internal.connection.SocketStream.read(SocketStream.java:131)
at com.mongodb.internal.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:688)
at com.mongodb.internal.connection.InternalStreamConnection.receiveMessageWithAdditionalTimeout(InternalStreamConnection.java:552)
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:395)
at com.mongodb.internal.connection.InternalStreamConnection.receive(InternalStreamConnection.java:355)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:223)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:151)
at java.lang.Thread.run(java.base@11.0.18/Thread.java:829)

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?

Regards,
Jeff

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.