carbon icon indicating copy to clipboard operation
carbon copied to clipboard

memory leak in writer

Open dkulikovsky opened this issue 13 years ago • 9 comments

This bug exists only in megacarbon branch with ceres database.

I've found a strange bug in writer daemon. Under heavy load (as much as possible datapoints is sent to carbon), with simpe config with 2 relays and 2 writers, when writer hits MAX_CACHE_SIZE, it stops accepting new data through tcp connection and struggles to write datapoints to disk. When this happens, writer starts to consume memory and sometimes this process would never stop until oom is invoked.

dkulikovsky avatar Aug 20 '13 15:08 dkulikovsky

--- ceres.py.bad        2013-08-20 20:01:01.512828595 +0400
+++ ceres.py.good       2013-08-20 19:28:26.005867642 +0400
@@ -442,6 +442,7 @@
           leftover = sequence[:boundaryIndex]
           sequences.append(leftover)
           slice.write(sequenceWithinSlice)
+          break

         else:
           needsEarlierSlice.append(sequence)

This patch fixes the problem, but i'm not 100% sure that i've done right.

dkulikovsky avatar Aug 20 '13 16:08 dkulikovsky

By the way, there is one more memory leak somewhere, under flood test through all night resulted in oom's and memory consumption by some procs is about 2-4Gb.

dkulikovsky avatar Aug 22 '13 11:08 dkulikovsky

I added some unit tests and caught some problems with the logic in CeresNode.write(). I didn't spot anything that looked like it'd cause a leak, but I'd love if you'd try and see if it helps the situation: https://github.com/graphite-project/ceres/commit/885f2a7ef97f8ded437d5b0d651af92d47900b5c

mleinart avatar Aug 25 '13 04:08 mleinart

Well, it was not memory leak, but it did look like a leak. Under really heavy load (1M metrics per minute on single host) for a long time, copying leftover slices results in huge sequence for a single metric. And while writer try to write this huge sequence (and as a understand this code - this huge sequence has tons of dublicate data), all other metrics keep receiving data, so writer get stuck in never ending cycles of copying leftover sequences. I started long stress test on vanila ceres plugin and ceres plugin with patch graphite-project/ceres@885f2a7. Will see tomorrow if it helps.

btw my patch is working good in our production environment, all writers keep memory consumption below limit.

dkulikovsky avatar Sep 13 '13 12:09 dkulikovsky

Your patch doesn't solve my problem. Under stress tests writer with yout patch or without it, at some point, starts to consume memory. Same problem happens when carbon daemons have worked for a long time - few weeks. My stress test is just a way to show that there is a problem. Here some screenshots: This is ceres without any patches: ceres_no_patch_overload this is your patch https://github.com/graphite-project/ceres/commit/885f2a7 ceres_complex_patch_overload and this is mine: ceres_simple_patch_overload

carbon with my patch also died because of oom..

dkulikovsky avatar Sep 16 '13 13:09 dkulikovsky

Are you only seeing this problem with Ceres? We had a single carbon-cache last week get in to a state where it was sitting with 1.5+ GB of memory. strace showed it spinning on a mutex. We tried to attach ltrace, but that seemed to kill it.

davcamer avatar Sep 16 '13 14:09 davcamer

Thanks. This really saved our day, although carbon-daemon is still leaking memory somewhere(~4MB/day).

Yes, this was with ceres - 1.5GB+ RES in a day on relay; ~ 700MB RES, 100% CPU per writer. SIGKILL was necessary to stop writers.

zstyblik avatar Dec 14 '13 08:12 zstyblik

Hello,

is there a reason why this haven't been merged even though it fixes serious issue like ~~memory leak~~ endless loop?

EDIT: Also, this PR/issue probably should rather be in https://github.com/graphite-project/ceres than here?

Thanks.

zstyblik avatar Jan 15 '14 09:01 zstyblik

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 13 '20 22:04 stale[bot]