[JAVA-3437] Allow connection threads to use non-default name Created: 14/Sep/19  Updated: 30/Mar/22

Status: Backlog
Project: Java Driver
Component/s: Reactive Streams
Affects Version/s: 3.11.0
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Wing Tsang Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

My application is non-blocking based using Vertx / Reactor and we use slf4j to log the thread name, which is very handy for debug.

However it looks like the connection threads created by the java reactive driver is using the default thread name. Can we change the mongo connection threads use non-default thread name prefix?



 Comments   
Comment by Jeffrey Yemin [ 09/Oct/19 ]

ywtsang@gmail.com

Thanks for your investigation. I'll add this to our backlog, but since there appears to be a workaround (create your own AsynchronrouChannelGroup) we don't plan to fix this immediately.

Comment by Wing Tsang [ 09/Oct/19 ]

After opening TRACE logging for mongodb driver, 2 more logs are printed under "Thread-7" by LoggingCommandEventSender

2019-10-09 12:13:03,552 DEBUG [Thread-7] org.mongodb.driver.protocol.command - Sending command '{[MASKED]}' with request id 8 to database [MASKED] on connection [connectionId\{localValue:2, serverValue:1871851}] to server [MASKED]
2019-10-09 12:13:03,762 DEBUG [Thread-7] org.mongodb.driver.protocol.command - Execution of command with request id 8 completed successfully in 212.46 ms on connection [connectionId\{localValue:2, serverValue:1871851}] to server [MASKED]

which should be triggered by InternalStreamConnection, which is using Stream which is indirectly created by AsynchronousSocketChannelStreamFactoryFactory

so it is the AsynchronousChannelGroup to control the thread name

by default AsynchronousChannelGroup is null and so the threads created are just "Thread-*"

I have tried to configure AsynchronousChannelGroup and the thread name can be changed accordingly.

So if it is ok for mongodb java driver to create a default AsynchronousChannelGroup with appropriate thread name prefix to indicate the threads are created by mongodb java driver internal?

 

Comment by Jeffrey Yemin [ 30/Sep/19 ]

ywtsang@gmail.com

I don't think that the Java driver is creating the thread named "Thread-7". The Java driver only creates threads for connection pool and cluster monitoring, not for execution of reactive callbacks.

Comment by Wing Tsang [ 17/Sep/19 ]

Here is an example log:

2019-09-17 16:19:52,553 INFO  [vert.x-eventloop-thread-2] cluster - Cluster created with settings {hosts=[10.82.0.173:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=5000}
2019-09-17 16:19:52,935 INFO  [vert.x-eventloop-thread-2] EpollProvider - Starting without optional epoll library
2019-09-17 16:19:52,937 INFO  [vert.x-eventloop-thread-2] KqueueProvider - Starting without optional kqueue library
2019-09-17 16:19:53,208 INFO  [vert.x-eventloop-thread-2] Bootstrap - bootstrap started ok... reactor SMALL_BUFFER_SIZE=256, reactor XS_BUFFER_SIZE=32 reactor schedule DEFAULT_POOL_SIZE=4
2019-09-17 16:19:53,777 INFO  [cluster-ClusterId{value='5d809728a8a13e543ccbc849', description='null'}-10.82.0.173:27017] cluster - Monitor thread successfully connected to server with description ServerDescription{address=10.82.0.173:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 2]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=225536900}
2019-09-17 16:19:54,284 INFO  [vert.x-eventloop-thread-3] Vertxs - init tracker: testmongohang#0, inactive threshold: PT3M2S
2019-09-17 16:19:54,308 INFO  [vert.x-eventloop-thread-3] 1 - | onSubscribe([Fuseable] FluxOnAssembly.OnAssemblySubscriber)
2019-09-17 16:19:54,315 INFO  [vert.x-eventloop-thread-3] 1 - | request(unbounded)
2019-09-17 16:19:57,018 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,018 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,018 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,019 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,019 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,019 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,020 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,020 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,020 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,020 INFO  [Thread-7] 1 - | onNext(kotlin.Unit)
2019-09-17 16:19:57,021 INFO  [Thread-7] 1 - | onComplete()

The log starts from vertx event loop, until after subscribe and request, then is switched to the mongodb driver "Thread-7" after data is returned from querying mongodb.

 

Comment by Jeffrey Yemin [ 16/Sep/19 ]

Hi ywtsang@gmail.com,

The driver creates threads for multiple purposes. Can you share a log snippet with us to show which ones you're referring to?

Generated at Thu Feb 08 08:59:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.