memory leak in writer
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.
--- 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.
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.
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
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.
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:
this is your patch https://github.com/graphite-project/ceres/commit/885f2a7
and this is mine:

carbon with my patch also died because of oom..
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.
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.
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.
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.