0

I am using MongoDB to store data. In my project I am connecting multiple users(100-2000 users) to a server using thread pool and store the responses of those users in the database. But when I do this I am getting this error. Please help me with this. I am not able to get it. I have already wasted 45 hours on this error.

Error:

java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.avaya.onex.hss.requesthandlers.CommandExecutor.executeCommands(CommandExecutor.java:129)
    at com.avaya.onex.hss.requesthandlers.CommandExecutor.run(CommandExecutor.java:59)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: com.mongodb.DBPortPool$SemaphoresOut: Out of semaphores to get db connection
    at com.mongodb.DBPortPool.get(DBPortPool.java:176)
    at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:370)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:149)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:138)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:261)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:211)
    at com.mongodb.DBCollection.insert(DBCollection.java:57)
    at com.mongodb.DBCollection.insert(DBCollection.java:102)
    at com.avaya.onex.hss.objects.LoginRequest.storeData(LoginRequest.java:152)
    at com.avaya.onex.hss.requesthandlers.LoginHandler.handleRequest(LoginHandler.java:20)
    ... 8 more
com.mongodb.DBPortPool$SemaphoresOut: Out of semaphores to get db connection
    at com.mongodb.DBPortPool.get(DBPortPool.java:176)
    at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:370)
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:212)
    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305)
    at com.mongodb.DB.command(DB.java:160)
    at com.mongodb.DB.command(DB.java:183)
    at com.mongodb.DB.command(DB.java:144)
    at com.mongodb.DBCollection.drop(DBCollection.java:777)
    at com.mongodb.DBApiLayer$MyCollection.drop(DBApiLayer.java:206)
    at com.avaya.onex.hss.requesthandlers.CommandExecutor.executeCommands(CommandExecutor.java:118)
    at com.avaya.onex.hss.requesthandlers.CommandExecutor.run(CommandExecutor.java:59)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
4
  • Have you checked the MongoDB source code, especially for the DBPortPool class? Commented Jun 18, 2012 at 11:04
  • I just have the jar file of that.. In which DBPortPool class is present... How can I read that java source.. Commented Jun 18, 2012 at 11:11
  • You download the source from the MongoDB website: mongodb.org/downloads (the rightmost column) Commented Jun 18, 2012 at 11:15
  • The source is available at github: github.com/mongodb/mongo-java-driver Commented Jun 18, 2012 at 16:57

1 Answer 1

2

Try increasing the number of connections in the connection pool.

Look here, at the connectionsPerHost.

Sign up to request clarification or add additional context in comments.

3 Comments

This may be the right way to solve it. There's also the threadsAllowedToBlockForConnectionMultiplier which may be relevant. But maybe shalki have found and tried these already after a week of troubleshooting?
yes.. I tried that also. It was not working by increasing this. The same error occurs.
If you set connectionsPerHost to a value as large as your thread pool, you should never get the error that you're getting now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.