Rocket.Chat on mongo replica set and read/write preference consequences
Hey all,
We have recently deployed RocketChat to a 2 node+arbiter mongo setup. Both nodes have a single meteor instance and are in front of a load balancer and the arbiter is a smaller VM there for voting purposes only.
I have currently set the RS read preference to nearest and write preference to majority thinking that it's optimal in terms of guaranteeing writes and it helps balance the database load on the reads with some presumably minor latency effect.
Any thoughts on this setup for or against?
Thanks Georgios
I think this is the first time i've heard of someone setting up like this.
Are you seeing any performance hits / gains? What kind of load?
@RocketChat/core
It depends on what you compare it to.
Our old set up was on a standalone VM/mongo instance on an Azure VM with 2x AMD cores/7GB RAM.
The new setup has the above mongo setup on 2x load balanced Azure VMs with 1x Xeon core+3.5GB RAM each. We've also set up RAID-0 with 2x cloud disks for the data (previously they were on the OS disk) and done several other OS tweaks such as swap on SSD drive etc.
Between the two we have seen at 3-4x improvement on the amount of active concurrent users.
What is the typical kind of setup you are implicitly referring to?
@georgiosd I was referring specifically to the ReplicaSet settings. Most don't go so far as to detail those settings. So first i've seen specifically those settings. I personally have not done much with mongo replicasets. So others would be more qualified to answer this. :)
But sounds like a solid setup.
Thanks for the tip! We are planning some more performance enhancements that should improve the amount of active concurrent users another 10 fold.
Oh ok :)
It seems to me like the minimum configuration for having any reliability if a VM fails for any reason.
What we have noticed is that the "user is typing" feature is limited to the users connected to the particular node. Meaning, if I can connected to node B, I will only see "x is typing" for users also connected to node B.
I presume that this is because of the read preference being set to nearest but perhaps you know something different?
That is strange.. that should not be the case. All nodes broadcast the "user is typing" to the other running nodes via DDP... it that is not working, we have a bug.
If it does not depend on the database, then yes, I would agree :)
Are you saying that you've git clone RC-source-code and running meteor on each of the node, with each one also running a local MongoDB instance?
Yes, and all mongodb instances are connected to the same replica set (2x nodes + arbiter)
The round-robin load balancer is in front of the RC/meteor instances (port 3000)?
@georgiosd are you running git clone RC-source-code and running meteor rather than downloading the latest version from https://rocket.chat/releases and running it using pm2?
The meteor command is only meant for development.. it will run much slower.
Also - we might not have tested the typing... message when running multiple independent meteor instances operating in development mode on separate machines.
Might have rushed my responses a little.
The production instances are executed on node 0.10.40 like so:
node $APP_DIR/bundle/main.js
Package is built with meteor build
Ah. OK :smiley: :+1: Is the load balancer in front of the 2 x RC instances ?
Yes, so both nodes have 8080 listening for requests, there's an nginx reverse proxy (redirects HTTP requests to HTTPS and proxies HTTPS requests to localhost:8080). The load balancer will distribute the load on port 443 for both nodes based on ClientIP (sticky).
And the RC instances loop back again, via IP, round-robin to the two mongo instances co-located on the same 2 x VMs?
Not if I understood the question correctly.
This is the mongo config that I've found for replica set meteor environments:
MONGO_URL="mongodb://primary:27017,secondary:27017,arb:27017/$DB?replicaSet=rs0&readPreference=nearest&w=majority"
MONGO_OPLOG_URL="mongodb://primary:27017,secondary:27017,arb:27017/local"
Basically mongo is accessed directly by virtual network ip, it doesn't go through a load balancer.
Each node should pick the local mongo instance to read from given readPreference=nearest
Makes sense?
Yep :smile: Very interesting. Thanks for sharing!
We find that number of active users handled scales with number of mid-tier RC instances. On demo.rocket.chat - we're running 4 x RC instances.
Certainly the repl set + arbiter config provide additional up-time availability benefits.
That makes sense. Is that one instance per core? It's the recommendation I've found in my research for node/meteor.
Given that at least on Azure, 1-core VM is half the price of a 2-core VM and 1/4 of the price of a 4-core VM, I thought it's better to increase uptime and keep cost the same.
If we need more juice in the near-term, I will turn the arbiter VM into a full node so we should gain another 1-2x.
The other problem with the kind of setup that you're describing, at least on Azure, is that the load balancer has a fixed destination port so if you have multiple VMs with multiple instances each, you'd have to have a load balancer on the virtual network level and another on the VM level to distribute the load between instances and that's when things start getting iffy. Too bad node can't just spawn workers.
Yes. One instance per core. Server-side node.js is single-threaded :smile:
Thanks for sharing. Yes, a mix of horizontally scaled + vertically scaled nodes typically results in super brittle configs.