Я пытаюсь вставить данные в MongoDB в несколько потоков, используя структуру Spring Data MongoDB. Но, к сожалению, я получаю следующую ошибку:
Caused by: com.mongodb.MongoWaitQueueFullException: Too many threads are already waiting for a connection. Max number of threads (maxWaitQueueSize) of 50 has been exceeded.
at com.mongodb.PooledConnectionProvider.get(PooledConnectionProvider.java:70)
at com.mongodb.DefaultServer.getConnection(DefaultServer.java:60)
at com.mongodb.BaseCluster$WrappedServer.getConnection(BaseCluster.java:216)
at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:503)
at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:451)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:286)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:271)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:84)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66)
at com.mongodb.DBCursor._check(DBCursor.java:458)
at com.mongodb.DBCursor._hasNext(DBCursor.java:546)
at com.mongodb.DBCursor.hasNext(DBCursor.java:571)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1782)
... 22 more
Я использую следующую конфигурацию для Spring:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
<context:annotation-config/>
<context:property-placeholder location="classpath:database.properties"/>
<mongo:mongo host="${mongo.db.host}" port="${mongo.db.port}"/>
<mongo:db-factory id="mongoDbFactory" dbname="${mongo.db.name}"/>
<mongo:repositories base-package="com.test.app.mongodb.dao"/>
<mongo:template db-factory-ref="mongoDbFactory" converter-ref="mappingConverter" write-concern="ACKNOWLEDGED"/>
<mongo:mapping-converter id="mappingConverter" db-factory-ref="mongoDbFactory" type-mapper-ref="defaultMongoTypeMapper"
mapping-context-ref="mappingContext"/>
<bean id="defaultMongoTypeMapper" class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper">
<constructor-arg name="typeKey">
<null/>
</constructor-arg>
</bean>
<bean id="mappingContext" class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
As I understood from documentation there are a few properties which are responsible for allowed connections number (default combination of them allow 50 connections per node). They could be configured with Spring: connections-per-host and threads-allowed-to-block-for-connection-multiplier. I tried to use first one as shown below:
<mongo:mongo host="${mongo.db.host}" port="${mongo.db.port}">
<mongo:options connections-per-host="100"/>
</mongo:mongo>
Но результат тот же. Я все еще получаю это исключение о 50 разрешенных соединениях.
Буду очень признателен, если кто-нибудь объяснит, что я сделал не так. Кто-нибудь сталкивался с этой проблемой?