Originally posted by @plebhash in #33899
we are getting reports of out-of-memory crashes on https://github.com/stratum-mining/sv2-apps/pull/59#issuecomment-3568252007
initially I suspected there could be thread-related issues similar to what I reported on #33923, but it turns out it was the VPS running out of it’s 2GB available RAM, which only happened after long (12h+) running sessions
so I leveraged
psrecordto observe how Bitcoin Core (a14e7b9dee9145920f93eab0254ce92942bd1e5e from30.xbranch) was consuming RAM across time (connected tomainnetfor high mempool activity, for about ~1h to have enough chain tip updates)this is RAM consumption of Bitcoin Core with the Rust code from https://github.com/stratum-mining/sv2-apps/pull/59 (more specifically SRI Pool at https://github.com/stratum-mining/sv2-apps/pull/59/commits/57576e083e82fb5acd5dbad75e8b4de7158a3d61) connected to it:
there’s a clear upwards trend in RAM consumption, which made me wonder if we were doing something wrong on the Rust code
so then I ran it alongside
sv2-tpfor a comparison:which shows a similar upwards trend that never gets throttled down
I don’t know whether the root cause for this is related to template memory management, but there’s a chance it is, so I’m reporting it here rather than opening a new issue
Originally posted by @Sjors in #33899
I’m planning to make similar plots for #33922 (without CPU and ideally with marks to indicate where blocks were found).
If you’re measuring the process memory instead of only the template memory (which #33922 enables), you’ll want to hold the mempool itself constant. E.g. by picking some value for
-maxmempooland waiting for it to fill before starting the measurement. You also want to set-dbcacheto its minimum, because that’s also accuring
Originally posted by @Sjors in #33899
@plebhash it looks like you found a real bug. Because
BlockTemplate::createNewBlockdoesn’t have a context param, it looks like its destroy method is not invoked until sv2-tp disconnects. So the node keeps holding on to templates even though the Template Provider already pruned them.I’ll open a PR to fix that.
Originally posted by @plebhash in #33899
that’s good to know!
but do we have to explicitly call
destroyor is it sufficient to drop the reference from memory on the client side?from my understanding of capnp, I believe it should be sufficient to drop it from memory, but on the other hand there must be a reason for
destroyto exist?
Originally posted by @Sjors in #33899
@plebhash IIUC libmultiprocess does this automatically, but only
sv2-tpuses that library. So it probably depends on how the rust capnp library is implemented. It might be worth testing how that library behaves out of the box, with and without the fix here. Just look for theIPC server destroymessages on the Bitcoin Core side (preferably tested against master).