Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

On one instance I have MongoDB using ~85 threads. In lieu of having time to investigate directly, I am curious:

  1. What are the threads used for? Do they fall into a few high-level usage categories?
  2. How can I control/influence the number of threads used? E.g. max connection params, etc.
share|improve this question

migrated from stackoverflow.com Mar 20 '13 at 3:07

This question came from our site for professional and enthusiast programmers.

2  
If nobody can help you here I would give mongodb-user Group a try as well. –  Steven Farley Mar 18 '13 at 2:15
    
True, will go there if nobody answers here. –  Peter Skirko Mar 18 '13 at 20:56

1 Answer 1

Max connection count is usually %80 of ulimit value which is 1024 in most linux distros by default. That gives you 819 connections. It can be changed by changing ulimit value.

In MongoDB, each host can use 10 connections which is set by MongoOptions.connectionsPerHost property. These connections are controlled by an internal connection pool. It is thread-safe and you can have up to ConnectionPerHost x threadsAllowedToBlockForConnectionMultiplier threads running simultaneously. threadsAllowedToBlockForConnectionMultiplier also can be changed, its default value is 5. That is by default, you can have 50 simultaneous threads running from one host. Threads more than that value will get the "Out of semaphores to get db connection" exception.

You can change MongoOptions.connectionsPerHost and threadsAllowedToBlockForConnectionMultiplier values appropriately according to your needs.

If you are using drivers on a web application, you should use it as singleton class. No need to 'open connection-> do some work -> close connection' loop. Just declare a global connection once (and initialize in init method of your servlet) and use it in your entire web application.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.