Reprinted: View Original
Keywords: COM. MongoDB. dbportpool $ semaphoresout: Out of semaphores to get DB
I did a MongoDB concurrency test today and reported the above error. The reason is that the number of database connections is too small and the resources are exhausted. View the source code of COM. MongoDB. mongooptions, including connectionsperhost and threadsallowedtoblockforconnectionmultiplier.
Connectionsperhost: Number of connections per host
Threadsallowedtoblockforconnectionmultiplier: Number of thread queues. The result of multiplying the connectionsperhost value above is the maximum value of the thread queue. If the connection thread is full, the error "out of semaphores to get DB" will be thrown.
The default value of connectionsperhost is 10, and that of threadsallowedtoblockforconnectionmultiplier is 5, that is, the thread pool has 50 connections. Therefore, you only need to increase the value of this attribute to avoid the above errors.
Other property settings:
Maxwaittime: Maximum thread blocking time waiting for connection
Connecttimeout: the connection timeout time in milliseconds. 0 is the default and unlimited
Sockettimeout: Socket timeout. 0 is the default and unlimited
Autoconnectretry