title: Check queued reads/writes for MongoDB
body: <p>I feel like this question would have been asked before, but I can't find one. Pardon me if this is a repeat.</p>
  
  <p>I'm building a service on Node.js hosted in Heroku and using MongoDB hosted by Compose. Under heavy load, the latency is most likely to come from the database, as there is nothing very CPU-heavy in the service layer. Thus, when MongoDB is overloaded, I want to return an HTTP 503 promptly instead of waiting for a timeout.</p>
  
  <p>I'm also using REDIS, and REDIS has a feature where you can check the number of queued commands (redisClient.command_queue.length). With this feature, I can know right away if REDIS is backed up. Is there something similar for MongoDB?</p>
  
  <p>The best option I have found so far is polling the server for status via <a href="http://docs.mongodb.org/manual/reference/command/serverStatus/" rel="nofollow">this command</a>, but (1) I'm hoping for something client side, as there could be spikes within the polling interval that cause problems, and (2) I'm not actually sure what part of the status response I want to act on. That second part brings me to a follow up question...</p>
  
  <p>I don't fully understand how the MondoDB client works with the server. Is one connection shared per client instance (and in my case, per process)? Are queries and writes queued locally or on the server? Or, is one connection opened for each query/write, until the database's connection pool is exhausted? If the latter is the case, it seems like I might want to keep an eye on the open connections. Does the MongoDB server return such information at other times, besides when polled for status?</p>
  
  <p>Thanks!</p>