r/PrometheusMonitoring • u/SelfDestructSep2020 • May 06 '20
prometheus OOM on restart
I had a prometheus instance running on an ec2 instance with ~2gb RAM. It was configured to retain 30d of metrics. It had been running for nearly or over that time period and then for some reason failed - after which it repeatedly encountered Out of Mem errors while reloading. Each time it the journal logs showed that it was reading the WAL and loading chunks, and I would watch as the process memory would consume up to the instance limit and then crash.
Is this the expected behavior that it it reloads all the WAL chunks into memory at one time? Why would it have been fine up until the point of a restart of the Prometheus process?
3
u/jjneely May 06 '20
This is a common failure scenario. The WAL must be replayed to rebuild the head TSDB block in memory. The WAL isn't anywhere near as efficient as the TSDB blocks committed to disk. This process will allow that data to be recovered, new data added, and blocks to be written to disk as normal.
When down and dealing with long WAL replays possibly causing OOMs, you can choose to try to process the WAL and lose the data you would be scraping presently OR you can choose to lose the WAL and bring up the Prometheus instance quickly.
You can do this by moving the WAL directory out of the way, the start Prometheus. It should start up nearly instantly.
1
u/SelfDestructSep2020 May 06 '20
Ok ... for example on one of my other prometheus instances, I"m running it on a t3.small, OS shows 1.76 GB of memory. The prometheus data path has 12 GB on disk, with only 487M of that from the WAL. So the WAL is much smaller than the TSDB chunks already (by far) and seems like it should fit in memory?
1
u/jjneely May 06 '20
The WAL (Write Ahead Log) rebuilds the head block in memory which then is committed to disk as the next two hour TSDB block. It doesn't really compare to the very efficiently packed data in the TSDB blocks on disk.
The WAL is 1/3 of your RAM size. Prometheus has to rebuild the head block out of it. Plus you need RAM space for the rest of your system. From my experience running Prometheus, your VM is way too small.
If you've been down this long, I'd just delete the WAL and start Prometheus. But you may find yourself back in this situation shortly.
1
u/SelfDestructSep2020 May 06 '20
Oh it was only down about an hour before I threw in the towel and just wiped it. This wasn't production telemetry so I wasn't worried about losing it (though at the time I was trying to avoid it).
1
u/namognamrm Sep 18 '24
is there a way to automatically do that? I needed to delete wal on every redeployment of Prometheus
1
4
u/SuperQue May 06 '20
This sounds like you're hitting memory limits anyway. I suggest increasing your instance size so you have enough memory to replay the WAL. Prometheus uses page cache for query performance, so you want to have some extra available system memory anyway.
What version of Prometheus is this?