I am on 1GB Linode (VPS) with MongoDB + Apache.
MongoDB has 1.5M+ records. Multiple instances of the script , over which the service entirely depends cause 50+ active connections and around 50 queries per second.
My free -m
output
total used free shared buffers cached
Mem: 995 974 21 0 4 823
-/+ buffers/cache: 145 849
Swap: 511 79 432
Now, the script need ~17MB for each instance (already optimized) and as I said multiple instances of it run. There a huge difference in the free cache memory ( 849 MB! ) and actual free memory ( 21 MB ). I cannot run instances of the PHP script, I get an error that memory allocation fails.
Most of the memory is used by MongoDB and it also causes high CPU usage, 250+ %
. This is useless, I could run even many instances of my PHP script within 849 MB. I want to know if it will be better for me to host my MongoDB remotely ( I prefer MongoHQ ). They have a $15/month plan which is fair for me. I could downgrade to 768 MB linode which will be enough without MonogDB running on it.
But, what are cons of using a remotely hosted database? 50+ connections and ~50 queries per second? There will bandwidth issues next.
Any help is greatly appreciated.
Best Answer
If you are going to run the database remotely, run it at the same network segment than your app servers, or at least the same datacenter.
Even if you get low(ish) latency like < 10 ms, that can impact on your queries depending on the type of data load you have.
Also you end adding another point of failure to your system, communication between your application servers and database servers may fail. MongoDB doesn't use any encryption on it's protocol and your data will be running clear between god knows how many hops unless you tunnel it some way. And, as you pointed, there's the bandwidth use. Overall I suggest you to get another node to run your DB, but at the same place of your application server.