facebook-developer-circle-delhi / Ask-The-Community

This is an initiative where-in people can ask questions (directly or anonymously) as issues. People can then respond to them as comments. Once there is a satisfactory answer, we can close that issue down.
14 stars 1 forks source link

Improving performance of a website based on MongoDB & Set up on MongoDB Atlas #13

Closed parulagg27 closed 5 years ago

parulagg27 commented 6 years ago

A community member asks anonymously:

" I along with my seniors had set up Mongo Atlas for our MongoDB. Reaction Commerce, an e-commerce tool which generally uses MongoDB for data, was hitting Atlas using some credentials put into the config file.

Things were set up and running well. Users were able to sail through the website. But, as soon as the users started increasing the performance of the website got down dramatically. Just at 1400 to 1500 request or second, the whole website got down.

What happened? We kept restarting the server thinking it might solve the issue but didn't. After so long time putting our heads into, we finally came to a conclusion that the Atlas shouldn't have been hit directly from Reaction Commerce through some credentials but instead it should've been proxied. What it meant is the Atlas would be hit only by the backend server and not by any other outside entity. The moment we did it, the performance reached to its highest level.

So, Reaction Commerce started hitting our backend server and the server inturn hit the Atlas for data. It really did the miracle. Earlier, I was able to connect to Atlas through my local Mongo Shell using the credentials but later I wasn't. I had to first connect to my server and then I was connecting to Atlas through Shell.

What is it that did the miracle? How did the later solution work out. Why did we have to proxy? How does it actually work? Please help me understand the very nuts and bolts of it.

Thanks"

parulagg27 commented 6 years ago

@poush I think, you can help out here?

gaurav-gogia commented 5 years ago

@shreybatra maybe you can shed some light here?

shreybatra commented 5 years ago

@DesmondANIMUS yeah i'll try. See the main reason your site got down was because you were opening too many connections. Understand it like this -

When you were directly hitting Atlas, each time you were creating a new connection with the server. This meant you registered a new client and Mongo had to process another person/client for data consistency among all it's clients. Some what like keeping track of every other client in the network.

Now, when you created a gateway through the backend, you made your backend as a single client for Mongo. So now, mongo only has to keep track or your requests and responses... but not for everyone's request and responses as only backend in interacting with Atlas.

Creating a new connection is ultra heavy to maintain than to process 100 times the request from a single connection.

You can check this link for more information on connection limit here.

parulagg27 commented 5 years ago

Great explanation @shreybatra! Closing this issue now.