couchdb icon indicating copy to clipboard operation
couchdb copied to clipboard

Memory Usage Keeps Increasing Gradually

Open arifcse019 opened this issue 6 years ago • 12 comments

Description

Memory usage of our CouchDB Cluster keeps increasing week by week until we have to restart it to release the memory. There is no attachment or conflict (verified programmatically using views) or big document (our biggest document size is ~27 KB)

Steps to Reproduce

  • Running the cluster for a few weeks, you would see the memory usage increasing week by week.

Expected Behaviour

Memory usage remains relatively stable/flat

Your Environment

{"couchdb":"Welcome","version":"2.3.1","git_sha":"c298091a4","uuid":"4ebb08d132299ae512bd001e673fc7fa","features":["pluggable-storage-engines","scheduler"],"vendor":{"name":"The Apache Software Foundation"}}

  • CouchDB version used: 2.3.1
  • 3 Nodes Cluster, n=3, q=9
  • ~15 thousand databases, total data size in the disk is ~11G in each of the three nodes.
  • Browser name and version: Not Applicable
  • Operating system and version: Ubuntu 14.04

Additional Context

  • Among the CouchDB memory components, it is the "processes" which is gradually increasing as can be seen in the diagram below (the dip is when we restarted it last time): primary_node_memory

  • I tried to find individual processes' memory usage, but the total Heap+Stack from i(). =~ 40MB does not match up with the processes component of erlang:memory(). =~ 2.7GB

Following are the commands I tried

root@ip-10-0-3-10:~# erl -name test -remsh [email protected] -setcookie redacted

Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:2:2] [async-threads:10] [kernel-poll:false]

Eshell V8.3.5 (abort with ^G) ([email protected])1> erlang:memory().

[{total,2834080280}, {processes,2709523496}, {processes_used,2709484152}, {system,124556784}, {atom,512625}, {atom_used,505104}, {binary,1510536}, {code,11770466}, {ets,103666808}]

([email protected])2> i().

Pid Initial Call Heap Reds Msgs Registered Current Function Stack
<0.0.0> otp_ring0:start/2 1598 4032 0 init init:loop/1 2

. . .

Total 40590405 31290642 0 10320

  • We upgraded the cluster in-place from 2.1.2 to 2.3.1 a few months ago. We did not have this memory usage issue/trend on 2.1.2. Not sure if it is related or not since we upgraded, we are seeing this error regularly: https://github.com/apache/couchdb/issues/1600#issuecomment-523982028

  • Not sure about its relevance, but the following are two design documents we have and use in all of our 15 thousand databases:

{"_id":"_design/permissions","_rev":"3-e99851a9513d6e9c973a598d69523645","filters":{"user_documents_to_account":"function(doc, req) {\n if (doc._id.indexOf('_') === 0) return false;\n if (!req.query.account_id || !doc.accountId) return false;\n if (req.query.account_id != doc.accountId) return false;\n if (req.query.roles.indexOf('account_writer') !== -1) return true;\n if (doc._id.indexOf('account' === 0) && req.query.roles.indexOf('account_info_writer') !== -1) return true;\n return false;\n }"}}

{"_id":"_design/logDocs","_rev":"1-e64774d95fb1fc9e9c20842eb38edffd","validate_doc_update":"function (newDoc, oldDoc, userCtx){\n var logData = JSON.stringify({newDoc: newDoc, oldDoc: oldDoc, userCtx: userCtx})\n log('[ATVENU] ' + logData);\n }"}

arifcse019 avatar Jan 10 '20 17:01 arifcse019

Also facing the same issue, on Single Node installation , though the increase span is much faster (within 2-4 days, RAM usage jumps to over 8GB and eventually the server crashes. DB usage is minimal, with only 2 DBs and minimal data (<10MB overall). Using latest docker built with version 2.3.1.

toumbask avatar Jan 16 '20 10:01 toumbask

I have a very similar issue, also on 2.3.1 but on Ubuntu 16.04 and 18.04 virtual machines. The memory usage grows for several weeks before it crashes for about 3 seconds and restarts the service. It's completely recoverable (at least for us) and doesn't cause any sort of outage but it is concerning.

Screenshot_20200128_162359

noahbailey avatar Jan 28 '20 21:01 noahbailey

Same problem here on a single node installation. The memory usage is increasing and the server crashes. CouchDB 2.3.1. Does v3.0.0 resolve this issue?

pseudooriginal avatar Mar 11 '20 14:03 pseudooriginal

@pseudooriginal My team hasn't migrated to v3.x yet, so it could be some time before we get good data on that.

noahbailey avatar Mar 11 '20 16:03 noahbailey

I had recurring memory problems that I fixed by upgrading the version of jiffy (see https://github.com/davisp/jiffy/commit/0ba322e42171bb48ffdd0c053cef28a42eb35fc9)

sklassen avatar Mar 31 '20 16:03 sklassen

We do believe this will be resolved in CouchDB 3.0.1 and 3.1.0 via the bump to Jiffy 1.0.4.

Going to close this for now against that fix, so we can track if there are still regressions after people test against those versions.

If & when we do a 2.3.x patch release, we'll be sure to backport this fix there.

wohali avatar Apr 27 '20 18:04 wohali

We're seeing memory usage climb until the kernel OOM killer kills beam.smp on 3.1 while doing an initial replication of a large database (> 70GB with a number of views) on a 32GB server.

[root@couchdb-staging ~]# grep "Out of memory" /var/log/messages                                                                                                                                                          
Jun 15 07:28:44 couchdb-staging kernel: Out of memory: Killed process 2844 (beam.smp) total-vm:41846892kB, anon-rss:30352140kB, file-rss:0kB, shmem-rss:0kB                                      
Jun 15 12:22:26 couchdb-staging kernel: Out of memory: Killed process 5303 (beam.smp) total-vm:42290044kB, anon-rss:29574368kB, file-rss:0kB, shmem-rss:0kB                                                               
Jun 15 13:17:18 couchdb-staging kernel: Out of memory: Killed process 6962 (beam.smp) total-vm:42421488kB, anon-rss:30516064kB, file-rss:0kB, shmem-rss:0kB                                                               
Jun 15 13:50:39 couchdb-staging kernel: Out of memory: Killed process 7740 (beam.smp) total-vm:42459412kB, anon-rss:30034480kB, file-rss:0kB, shmem-rss:0kB                                                               
Jun 15 18:36:14 couchdb-staging kernel: Out of memory: Killed process 8280 (beam.smp) total-vm:42015812kB, anon-rss:29495620kB, file-rss:0kB, shmem-rss:0kB                                                               
Jun 15 20:12:34 couchdb-staging kernel: Out of memory: Killed process 10794 (beam.smp) total-vm:41676032kB, anon-rss:29832200kB, file-rss:0kB, shmem-rss:0kB                                                              
Jun 16 04:32:50 couchdb-staging kernel: Out of memory: Killed process 11847 (beam.smp) total-vm:42226600kB, anon-rss:30368596kB, file-rss:0kB, shmem-rss:0kB

patternseek avatar Jun 16 '20 09:06 patternseek

Hi Guys, Its great that its been identified and fixed in 3.X.X but we are on 2.3 , so how can we fix this? can u pls let us know? do we just update jiffy somehow or update it and recompile the couch source code and redeploy? This should be documented as some people arnt as up to date with what should . thanks

zdravko123 avatar Aug 10 '20 11:08 zdravko123

We have no plans to do a new 2.x release at this time. Sorry about that.

One option is to have rolling reboots on your cluster every X hours. Reboot no more than one node down at a time. This can be automated relatively easily.

wohali avatar Aug 10 '20 17:08 wohali

Thanks for that, i had already suggested we do restarts of the couch service rather than the reboots during our daily chron jobs. We thought it could be daily chro jobs causing this and some adverse effect in the connections limits.

The reason why its so big of an issue for us is because we run some pretty massive clusters, 4 x 32 core instances with 64GB ram each, when the ram dumps it dumps hard, ie 50gb, during this time the node becomes unavailable, I suspect due to the fact it needs to then reload into ram the data to effectively serve requests. This takes time, it ends up taking longer to serve these requests and holds on to the connections, this then has a cascading effect that it exhausts the connection limit maximum threshold resulting in 502 Bad gateway errors as other requests are still coming in.

Now for most of the users of couchDB this isn't a problem as they are not running a massive cluster, but sadly for us we have half the country running off it, where a small glitch like this is noticeable to say the least. We have had to manually reboot the system in the past and has resulted in someone being on-call 24/7 ... me...

While scheduled reboots would fix it a patch would be greatly appreciated, esp since it's just a few lines of code. We are investigating migrating to couch 3.x but that's still in the planning stages and not sure it will happen this side of the year, and will probably result in 2 clusters, 1 remaining on 2.3 due to other limits related to connection, ect. since we have over 6,000 databases atm and twice as many replications.

If this can be done with a paid hot fix please contact me also.

Thanks for all your help. Cheers Drav

zdravko123 avatar Aug 10 '20 23:08 zdravko123

That's not that large of a cluster, actually, but thanks for the info.

wohali avatar Aug 11 '20 00:08 wohali

Heya @zdravko123, just leaving this here, we’d be happy to provide custom builds as part of our professional services: https://neighbourhood.ie/couchdb-support/ — If this is an option, feel free to reach out.

janl avatar Aug 18 '20 13:08 janl