Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure mongodb property maxWaitQueueSize in Spring boot application?

I get the error com.mongodb.MongoWaitQueueFullException: Too many threads are already waiting for a connection. Max number of threads (maxWaitQueueSize) of 500 has been exceeded. while doing a stress test on my application.

So I am thinking of configuring the maxWaitQueueSize property via configuration.

I am using spring boot to configure mongodb connection. I am using @EnableAutoConfiguration in my Application and I have declared only spring.data.mongodb.uri=mongodb://user:password@ip:27017 in the application.properties file.

How do I configure the maxWaitQueueSize property with spring boot?

How do I decide a good value for the maxWaitQueueSize?

like image 598
ravindrab Avatar asked Dec 24 '22 09:12

ravindrab


2 Answers

If you're using MongoDB 3.0+, you can set waitQueueMultiple in your mongouri :

spring.data.mongodb.uri=mongodb://user:password@ip:27017/?waitQueueMultiple=10

waitQueueMultiple is a number that the driver multiples the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the pool.

How do I decide a good value for the maxWaitQueueSize?

It's not directly related to MongoDB but you can read more about Pool Sizing in Hikari github wiki.

like image 141
Ali Dehghani Avatar answered Jan 25 '23 23:01

Ali Dehghani


In com.mongodb.MongoClientURI, you can find the parameters which can be used in MongoClientOption.

        if (key.equals("maxpoolsize")) {
            builder.connectionsPerHost(Integer.parseInt(value));
        } else if (key.equals("minpoolsize")) {
            builder.minConnectionsPerHost(Integer.parseInt(value));
        } else if (key.equals("maxidletimems")) {
            builder.maxConnectionIdleTime(Integer.parseInt(value));
        } else if (key.equals("maxlifetimems")) {
            builder.maxConnectionLifeTime(Integer.parseInt(value));
        } else if (key.equals("waitqueuemultiple")) {
            builder.threadsAllowedToBlockForConnectionMultiplier(Integer.parseInt(value));
        } else if (key.equals("waitqueuetimeoutms")) {
            builder.maxWaitTime(Integer.parseInt(value));
        } else if (key.equals("connecttimeoutms")) {
            builder.connectTimeout(Integer.parseInt(value));
        } else if (key.equals("sockettimeoutms")) {
            builder.socketTimeout(Integer.parseInt(value));
        } else if (key.equals("autoconnectretry")) {
            builder.autoConnectRetry(_parseBoolean(value));
        } else if (key.equals("replicaset")) {
            builder.requiredReplicaSetName(value);
        } else if (key.equals("ssl")) {
            if (_parseBoolean(value)) {
                builder.socketFactory(SSLSocketFactory.getDefault());
            }
        }
like image 30
Jong Su Park Avatar answered Jan 25 '23 23:01

Jong Su Park