Reputation: 13377
I started a CockroachDB process earlier today and its memory usage has kept increasing in the background even though I haven't been using it. What's going on? Is there any way to stop it from growing?
Upvotes: 2
Views: 408
Reputation: 13377
If you start a CockroachDB node and let it run for hours or days, it's not unexpected for its memory usage steadily grows for a while before plateauing at around 25% of the computer’s total memory. There are two factors playing into this:
CockroachDB stores internal timeseries monitoring data into itself in order to power the graphs in its admin UI. This means that data is periodically being written even if you aren't sending traffic to the system.
Like most databases, CockroachDB caches the most recently accessed data in memory so that it can provide faster reads. The timeseries writes are included in this, and so the timeseries data accumulates in memory until the system hits its configured memory limit.
The cache size limit defaults to 25% of the machine’s memory, but can be controlled by setting the --cache flag when running cockroach start. For example, you could run cockroach start --cache=512MiB to limit the cache size to 2^29 bytes.
If you don't care at all about the admin UI, you can also choose to decrease the frequency with which timeseries data is sampled by setting the COCKROACH_METRICS_SAMPLE_INTERVAL
environment variable before starting the CockroachDB process. It defaults to sampling every 10 seconds, so you could set it to COCKROACH_METRICS_SAMPLE_INTERVAL=1m
to decrease the amount of data written by 6x.
Upvotes: 3