Couch cluster cpu spike causing unavailability of service
Hi All,
I was hoping someone would be able to assist in a few CouchDB related issues. To give a bit of a background, our system is Lunix/Ubuntu and runs on a couch v2.3.1 cluster of 4 nodes with 3 replications inAzure. Prior to this we were running in AWS with 3 nodes and 3 replications (mirrored mode I'll call it).
We have over 4000 databases and around 8,000 synchronisations/continuous replications, the main db replicates to a cut down database with a subset of records (2 way sync). The average size of the data is about 100gb on the nodes – and sometimes can grow quite rapidly, once we got caught out with the 30gb free filling up taking one of the modes offline. We also have some old replications in there, which shouldn’t work but are still there and on restart might kick off, I'm not sure really, we don’t restart the box/service often (should we?).
The main issue is that lately we have been getting service interruption due to couch CPU spiking on all the nodes at the same time, and network traffic increasing. We looked at the logs we saw: (See below for more detailed errors)
Terminated reason killed Killed in context shut down Unknown error: normal
This meant that our system was offline for 10 minutes, it wasn’t during peak time but it's still a massive concern as the reason we run couch is for the up time, hence the cluster. I was wondering if anyone can assist in explaining what could cause this and how to make it stop. I am also looking if anyone knows of an expert that can provide support to audit our set up and help identify any issues and/or recommendations as we do not have a CouchDB expert in-house.
We also use pouch.js for synchronisation with our client side SPA and that is really the main reason we run the couch cluster. Any assistance would be welcome and much appreciated.
Cheers Zdravko
error] 2019-10-31T10:13:50.065116Z [email protected] <0.14377.6> -------- CRASH REPORT Process (<0.14377.6>) with 1 neighbors exited with reason: killed at gen_server:terminate/7(line:812) <= proc_lib:init_p_do_apply/3(line:247); initial_call: {couch_replicator_httpc_pool,init,['Argument__1']}, ancestors: [<0.2970.6>,couch_replicator_scheduler_sup,couch_replicator_sup,...], messages: [{'DOWN',#Ref<0.0.786436.115470>,process,<0.2970.6>,...}], links: [<0.8087.4>], dictionary: [], trap_exit: true, status: running, heap_size: 987, stack_size: 27, reductions: 1064 [error] 2019-10-31T10:13:55.188654Z [email protected] <0.20609.0> -------- Supervisor couch_replicator_scheduler_sup had child undefined started with couch_replicator_scheduler_job:start_link() at <0.4532.6> exit with reason killed in context shutdown_error [error] 2019-10-31T10:13:55.201177Z [email protected] <0.12029.13> -------- gen_server <0.12029.13> terminated with reason: killed [error] 2019-10-31T10:13:55.218911Z [email protected] <0.12029.13> -------- CRASH REPORT Process (<0.12029.13>) with 1 neighbors exited with reason: killed at gen_server:terminate/7(line:812) <= proc_lib:init_p_do_apply/3(line:247); initial_call: {couch_replicator_httpc_pool,init,['Argument__1']}, ancestors: [<0.4532.6>,couch_replicator_scheduler_sup,couch_replicator_sup,...], messages: [{'DOWN',#Ref<0.0.524292.226283>,process,<0.4532.6>,...}], links: [<0.29867.8>], dictionary: [], trap_exit: true, status: running, heap_size: 376, stack_size: 27, reductions: 254 [error] 2019-10-31T10:13:55.232533Z [email protected] <0.19716.6> -------- gen_server <0.19716.6> terminated with reason: killed
#--------------------------------------------------------- max_dbs_open = 32768 [replicator] max_jobs = 10000 connection_timeout = 1000000 retries_per_request = 10 worker_processes = 8 [cluster] q=8 n=3 #--------------------------------------------------------- (edited)
Hi @zdravko123,
Thank you for your report.
It might help to adjust your replication settings.
max_jobs at 10000 seems a bit high, I would lower that, so to say 4000. And if you have so many replications and you intend for them to all be running, perhaps reduce the workers_processes a bit, maybe from 8 to 4 or 2.
connection_timeout = 1000000 seems high as well. A value closer to the default (30000) or 2-3x (60000-90000) times usually works best there. If jobs checkpoint regularly you'd probably want the job to fail and wait until the network stabilizes or endpoints look better than having it stick around waiting on a single request. The reason is that replication jobs already have a scheduler which is designed to deal with jobs retrying periodically.
Same thing with retries_per_request the default is 5. You could increase it to 6 or 7, but every increase is a doubling. You'd be better off letting the job fail and let other, healthy jobs, consume resources instead.
And most of all, since you have so many jobs per node, the setting that might help you the most could be
[replicator] startup_jitter = 5000
That setting takes effect when starting a replication job and make it sleep for a random amount of time between 0 and that many milliseconds (so the default is 5 sec). When a replication job starts, it has a spike of activity, it checks source, target, compares replication logs, etc, so having 5000 of those happing at the same time can bring the cluster down.
Also, when a node is disconnected from the cluster, which could have happened in your case, the replicator will rescan all jobs and possibly start a whole new set of jobs in case it can't "talk" to the other nodes. During that time, there will be a surge of activity due to say 5000 new jobs all starting at the same time. So making start_jitter = 30000 you'd randomize that startup a bit and hopefully smooth over the initial activity spike.
(When a replication job starts, it has a spike of activity, it checks source, target, compares replication logs, etc, so having 5000 of those happing at the same time can bring the cluster down).
Thanks for your assistance, one other thing we noticed is that our clusters nodes all had different UUID's from reading the docs, these all needed to be the same?
Ah good find. Yes, the UUID value must be the same on all the nodes of the cluster.
And it would also explain why you periodically get huge CPU spikes. This scenario is possible:
-
Server UUIDs participate in generating the replication IDs. So a replication task started on node1 will use that node's UUID and maybe generate some replication ID, say "abc123.."
-
If there is a node disconnection noticed, then nodes in the cluster will rescan all the replication documents in order to pick up any replications which were previously running on the disconnected node.
-
If any replications move to another node, they will now have different replication IDs. So the same replication from, with ID "abc123..." might now have ID "def123...".
-
Replication ID is used in _local replication checkpoint documents. So when jobs migrate, they won't find their recent checkpoint documents anymore, and will start reprocessing _changes feeds either since the beginning or since the last time they ended up running on that node.
After you fix the issue and set the same UUID. You might restart the nodes and will notice a CPU after all the jobs catch up. Then it should stabilize.