Can I have a smaller Prometheus

Prometheus | Power Devops

For the past few weeks, I’ve been thinking about having a time series DB and visualization tool that is easy to use and light on resources, so it can be used locally for development. Tried several times to find it with keywords such as “Grafana alternative”, “Prometheus alternative”, nothing to be seen as an alternative close to my liking. At one stage I almost write my own tools, which will be too big an undertaking for me.

So why not just use Prometheus? Well not until you see the binary size of it, a whopping 103.93 MB. Not surprising for a statically linked executable, but still, it’s big. Yesterday morning I told myself, why not make it smaller? How hard it can be right? Well at least smaller on the binary size, as I’m not yet informed enough to do a runtime utilization measurement on it.

The first thing I did after getting access to the code is to just remove whatever code I deemed not necessary. Like one time I completely remove tracing and alerting functionality, but that’s only reducing a maximum of 2MB. This comes with a lot bunch of modified files and breaking test cases. Definitely not the right way, we need to do it smarter.

The weight

After browsing for a binary size analysis tool I found goweight. It helps to determine what’s contributing to the binary size :

No surprise to see that the main contributors are cloud provider SDKs, but it’s still disappointing. At this stage, it is just a matter of finding where those are being used. A simple text search revealed that all the SDKs are mainly for Service Discovery (SD), for local development file-SD are more than enough.

After tinkering here and there, the very minimum change to exclude all unused SD is to comment them out in the in discovery/install/install.go . With this change, all tests are passed except one test related to zookeeper initialization. The binary got reduced to just 35.69 MB, just 34% from the original one.

Wrap Up

After stripping the debugging info using -ldflags="-s -w", the size got reduced quite bit more. At the end we reduced the size to 28.30% of the original file to just 29.42 MB.

It’s crazy when you think that more than 50% (I’m being generous) of the size is something most people will not use, maybe this is the price of modern computation where 50MB means nothing. To be fair Prometheus developers are kinda aware of this and putting the discussion in the readme of service discovery, however, the binary size is not discussed there.

There are several potential ways to reduce the file size, like by using upx to package the file. However it’s not readily available on brew, so I just skipped it. Another way is just to cut more functionality like tracing, alert and remote storage, however, it will take more effort to maintain and make sure all the tests will be passed.

The related changes can be found here https://github.com/wejick/prometheus/commit/6dd776019a315764a9f70147f83f1235b9b13189

4 thoughts on “Can I have a smaller Prometheus

  1. Pingback: More than 70% of prometheus executable are unused by most people - The web development company Lzo Media - Senior Backend Developer

  2. I wonder if stripping the DWARF symbol by default (“-w”) should be the way to go for Prometheus binary then, or even any Go project in general, since usually developers uses panic stack trace to debug the binary, instead of those symbols

Leave a comment