Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am developing an Angular Web App that receives its data from a nodejs/express API. This API runs mongoose that connect to MongoLab (the free account).

When receiving data, I experience a response time > 500ms for small data sets (1.5kb) and > 1s for "large" data sets (hundreds of kb).

This is clearly already too much and I am affraid it will be even worse when my db will grow.

The current process is as follow:

  1. Client goes to mysite.com/discover
  2. Server send the Angular App
  3. Client does an ajax request to mysite.com/api/collections
  4. Server connects to MongoLab, receives data
  5. Server send back data to client

This process is very fast in local development (local node, local MongoDB) (<20ms) but takes so much time when put online. I investigated what was taking so much time and I found two equal contributions:

  • API response time
  • MongoLab response time

The MongoDB query takes no time (<1ms).

The Question

What are my options to reduce this response time? Is it possible to store locally the data and use mongoLab as a "copy" (it would remove the MongoDB latency in most cases)? If so, would you suggest disk temporary storage, mongoDB replica, ...?

What I tried

I migrated my mongoLab DB to match the physical localization of my server (VM on digitalocean), it improve by a few 50ms, not much more.

Thanks a lot

share|improve this question
    
I suggest first you analyze where the bottleneck is. E.g.: How long is the roundtrip time for a simple route, say mysite.com/api/collectionstest to echo back to your app directly? –  Geert-Jan Sep 18 '14 at 9:06
    
Thanks for the reply. I did analyze, the two contributions are respectively (in the case of small queries): 300ms to round-trip the api alone and 200ms for the mongoLab query, and 500ms/500ms for large queries –  Baloo Sep 18 '14 at 9:18
    
hmm, they both sound slow, but the 300ms roundtrip to your api seems pretty extreme. With a pretty default express setup, such a 'echo round-trip' should cost no more than say 10-20ms (you could time that to know for sure). That means the rest is probably lost 'in transport' meaning, establishing tcp-connections, resolving DNS, etc. I'd probably go and look there first. –  Geert-Jan Sep 18 '14 at 9:35
    
The thing is: depending on the user's location, the API roundtrip will vary (got 100ms from work, 300ms in roaming). However, the mongoLab query is constant & takes 300 to 500ms, that's why I wanted to act on it. –  Baloo Sep 18 '14 at 9:41
    
We only run our databases in the public cloud (AWS, Azure, Google, etc.). Our API server is in AWS, which may explain the long trips from the app to the API server and back. If you email us at [email protected] we can see if there are any better options for you. -Chris@MongoLab –  Chris Chang Sep 18 '14 at 15:27

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.