Reprint: View Original
Keywords: com.mongodb.dbportpool$semaphoresout:out of semaphores to get DB
Do MongoDB concurrency test today to report the above error. The reason is that the number of database connections is too small, the resources are exhausted. View the Com.mongodb.MongoOptions source code, which has the connectionsperhost and threadsallowedtoblockforconnectionmultiplier two important properties.
Connectionsperhost: Number of connections per host
Threadsallowedtoblockforconnectionmultiplier: The number of thread queues, the result of which is multiplied by the above Connectionsperhost value is the maximum thread queue value. The "out of semaphores to get DB" error is thrown if the connection thread is fully queued.
Connectionsperhost default is 10,threadsallowedtoblockforconnectionmultiplier default is 5, that is, the thread pool has 50 connections to use. Therefore, the above error can be avoided as long as the value of this property is increased.
Other property settings:
Maxwaittime: The maximum waiting time for a connected thread to block
ConnectTimeout: The milliseconds that the connection timed out. 0 is the default and unlimited
Sockettimeout:socket timeout. 0 is the default and unlimited
Autoconnectretry: If this control is in a connection, the system will automatically retry