Configure mongodb property maxWaitQueueSize in Spring boot application?
NickName:ravindrab Ask DateTime:2016-02-15T23:06:16

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?

Copyright Notice:Content Author:「ravindrab」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35412696/configure-mongodb-property-maxwaitqueuesize-in-spring-boot-application

Answers
Ali Dehghani 2016-02-15T16:20:32

If you're using MongoDB 3.0+, you can set waitQueueMultiple in your mongouri :\n\nspring.data.mongodb.uri=mongodb://user:password@ip:27017/?waitQueueMultiple=10\n\n\nwaitQueueMultiple 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.\n\n\n How do I decide a good value for the maxWaitQueueSize?\n\n\nIt's not directly related to MongoDB but you can read more about Pool Sizing in Hikari github wiki.",


Jong Su Park 2016-06-21T05:35:11

In com.mongodb.MongoClientURI, you can find the parameters which can be used in MongoClientOption.\n\n if (key.equals(\"maxpoolsize\")) {\n builder.connectionsPerHost(Integer.parseInt(value));\n } else if (key.equals(\"minpoolsize\")) {\n builder.minConnectionsPerHost(Integer.parseInt(value));\n } else if (key.equals(\"maxidletimems\")) {\n builder.maxConnectionIdleTime(Integer.parseInt(value));\n } else if (key.equals(\"maxlifetimems\")) {\n builder.maxConnectionLifeTime(Integer.parseInt(value));\n } else if (key.equals(\"waitqueuemultiple\")) {\n builder.threadsAllowedToBlockForConnectionMultiplier(Integer.parseInt(value));\n } else if (key.equals(\"waitqueuetimeoutms\")) {\n builder.maxWaitTime(Integer.parseInt(value));\n } else if (key.equals(\"connecttimeoutms\")) {\n builder.connectTimeout(Integer.parseInt(value));\n } else if (key.equals(\"sockettimeoutms\")) {\n builder.socketTimeout(Integer.parseInt(value));\n } else if (key.equals(\"autoconnectretry\")) {\n builder.autoConnectRetry(_parseBoolean(value));\n } else if (key.equals(\"replicaset\")) {\n builder.requiredReplicaSetName(value);\n } else if (key.equals(\"ssl\")) {\n if (_parseBoolean(value)) {\n builder.socketFactory(SSLSocketFactory.getDefault());\n }\n }\n",


richard 2019-06-04T08:03:45

I am using spring boot starter webflux. This issue also happens. \nI tried to add MongoClientFactoryBean. It doesn't work.\nThe whole application is located in https://github.com/yigubigu/webfluxbenchmark. I tried to test performance benchmark of webflux and original mvc. \n\n@Bean\n public MongoClientFactoryBean mongoClientFactoryBean() {\n MongoClientFactoryBean factoryBean = new MongoClientFactoryBean();\n factoryBean.setHost(\"localhost\");\n factoryBean.setPort(27017);\n factoryBean.setSingleton(true); \n MongoClientOptions options = MongoClientOptions.builder()\n .connectionsPerHost(1000) \n .minConnectionsPerHost(500)\n .threadsAllowedToBlockForConnectionMultiplier(10)\n .build();\n factoryBean.setMongoClientOptions(options);\n return factoryBean;\n }\n",


Hbargujar 2016-02-15T15:47:50

you can achieve this by injecting an object of MongoOptions to your MongoTemplate. ",


More about “Configure mongodb property maxWaitQueueSize in Spring boot application?” related questions

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

Show Detail

Configure MongoDB connection pooling in Spring Boot application

I am trying to connect to a MongoDB replica set through a Spring Boot application with read preference secondary. I want to configure idle static connections only to secondary instance that get cre...

Show Detail

Configure Spring Boot application to use MongoDB connection uri provided in environment variable

I would like to configure the connection-uri to my MongoDB through an environment variable. This way, I can set different values on localhost or if the Spring Boot application is running in a cloud...

Show Detail

Docker, Mongodb,Spring Boot on Windows getting Connection refused error

I am using default docker image of MongoDB and trying to connect using simple spring Boot application on windows box. mongoDB image is getting stared correctly IP in mongoDB image I have

Show Detail

Spring Boot app not connecting to the database specified in application.property for Mongodb

I have developer Application in Spring boot and exported the war file and placed it in tomcat 9 server. When I try to test the API in Rest client the app is connecting to test DB instead of the DB ...

Show Detail

MongoDB Connection for Spring Boot Application on Heroku

What is the best way to configure a Spring Boot application to connect to MongoDB on Heroku? I got it working specifying spring.data.mongodb.uri in the application.properties file, but I would lik...

Show Detail

Spring Data MongoDB + Spring Boot starting twice?

I'm trying to make Spring Data MongoDB (reactive) work with Spring Boot 2.1.5 (and WebFlux). From the startup logs I suspect that something is wrong, it seems like it's initialized twice (note the...

Show Detail

Configure MongoDB in Spring Boot using environment variables

I'm new to Spring Boot and am trying to configure a connection to MongoDB using environment variables - i.e. I have followed an example online showing how to configure my mongo database/host/port via

Show Detail

Spring Boot MongoDB connection bean

I have situation like this. I'm using Spring boot 1.3.2, and I have installed MongoDB on my pc I have added dependency org.springframework.boot:spring-boot-starter-data-mongodb And when I run ...

Show Detail

spring boot - testing mongodb repository

In spring boot app I am trying to unit test my mongo db repository public interface TimezoneDao extends MongoRepository<TimeZone, Long> { } by letting spring boot configure an embedded mong...

Show Detail