Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8651809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:09:36+00:00 2026-06-12T14:09:36+00:00

Background : I’m trying to optimize the speed of my Node.js API, built with

  • 0

Background: I’m trying to optimize the speed of my Node.js API, built with Express and Mongoose on the Amazon Cloud. I have one API call that takes a good amount of time to run (my /stats API call compiles data from lots of sources, and thus makes hundreds of mongo queries and thus takes about 20 seconds to run). I have noticed that, while this API call is running, other API calls that also hit the Mongo replica set are slow to return. My first thought was that the stats queries were slow, thus blocking, but according to my stat panel I don’t have any queries taking > 100ms to run, and also my Mongo DB stats are all in pretty healthy ranges (20+ queries per second, <1% btree miss, <5% lock).

Question: Right now, my Node.js app establishes a single connection to the Mongo set on startup, and all queries use that connection. Would it be better to establish multiple connections? Eg, should I establish a new Mongo connection for each inbound API request, instead? Or, maybe I should have a static number of connections to the replica set, and load-balance between those connections when executing queries?

Or maybe I’m completely off-base?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:09:38+00:00Added an answer on June 12, 2026 at 2:09 pm

    You absolutely should be using more than a single connection as otherwise only one query can be executing at a time. The cleanest way to do this is to simply enable connection pooling on your mongodb.Server object when creating your Db object. For example:

    var serverOptions = {
        'auto_reconnect': true,
        'poolSize': 5
    };
    
    var mdb = new mongodb.Db('test', new mongodb.Server('127.0.0.1', 27017, serverOptions));
    mdb.open(function (err, mdb) { ... }
    

    The reason you’re not seeing slow query times in the stats is that your concurrent queries are simply queuing up on the client side waiting for the connection to become available. That waiting time won’t show up in the server-side query times.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I am using node.js and express to create an API. I have implemented
Background I am working with a monad built of a stack of transformers one
Background: I have been charged with trying to come up with a new way
Background: I have a UICollectionViewController that shows items in one of two modes, which
Background I am trying to create a copy of a business object I have
Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
Background: I would like to dismiss a modalView that I have presented earlier and
Background: I have a .NET 4.0 web service running on Windows Server 2008 written
Background: I have a custom class, which represents a Data Base Table, each property
Background I have a couple of utility methods I would like to add to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.