caseyscarborough / qbittorrent-exporter

A prometheus exporter for qBittorrent.
83 stars 11 forks source link

[Feature Request] Compile to native code through GraalVM to minimize RAM usage #19

Open vincejv opened 1 year ago

vincejv commented 1 year ago

Hi! I think 450mb of RAM usage on idle is a bit too excessive for a Prometheus exporter and the culprit is definitely Java or JVM. There are two options i'd like to suggest

I'd prefer to go for option 2 as there is far less work needed compared to option 1. Let me know your/the communities' thoughts regarding this. On my end I'll try to compile the code with GraalVM Native using Quarkus framework and see how it goes. Skimming and scanning the code seems like it's using GSON + Undertow.

I'm running this exporter thru docker.

vincejv commented 1 year ago

After compiling it with GraalVM thru Quarkus Framework, RAM usage is around 50mb image

vincejv commented 1 year ago

Forked this repo as proof of concept: https://github.com/vincejv/qbittorrent-exporter

Docker images should be available in Docker hub below at any moment when CI finishes https://hub.docker.com/repository/docker/vincejv/qbittorrent-exporter

vincejv commented 1 year ago

Quick comparison between GraalVM Native and JVM In red square - JVM, blue - GraalVM using Quarkus Framework I was also able to further lower memory usage, as per advice from Quarkus Team and GraalVM compiler, by setting an Xmx value, I set it to 50mb by default

Docker Native Image: RSS: 15-32mb RAM Usage: 20-76mb

JVM: RSS: 110-420mb RAM Usage: 120-480mb

Let me know your thoughts! image

Draft PR: https://github.com/caseyscarborough/qbittorrent-exporter/pull/20

taw123 commented 7 months ago

FYI for both @vincejv and @caseyscarborough:

Thank you so much for your work here on this exporter. I ended up deploying Vince's forked exporter and tweaked Casey's "modern" dashboard a bit to migrate off Angular and address some personal prefs. You guys rock....

Wanted to make you aware of another effort (if you weren't already aware). It's a Python based exporter. I'd love to see if perhaps we could get a standard set of metrics for qBit? Or maybe even a single code base. I know the latter is VERY unlikely given significantly different dev environments but perhaps if either of you have a bit of time maybe you could publish the exporter's metrics? Would be really helpful in enhancing/augmenting the sample dashboard and perhaps even adding some elements from the dashboard thee other exporter's author created.

As an FYI, I added a reference/link to your exporters and my experience tweaking them to an issue someone had opened on the other python based exporter I mentioned earlier.

Please let me know if I can do anything to help, as I'd love to see if at least we can some Doc published on the metrics as I think it will help anyone looking to really leverage these exporters. I wasn't thinking anything elaborate, maybe something like this as a potential example. What do you think?

Regards, T

vincejv commented 7 months ago

@taw123 NAK for me, Python is really really slow for a Prometheus exporter, you can see the benchmark here https://www.youtube.com/watch?v=vJsqDqq1R0Y

The ideal plan going forward is to rewrite in Go, but it will require a lot of rework, Quarkus is a middle ground as it preserves the existing code, and it's as fast as GoLang since it's compiled to machine code just like Go.

Even on recent tests, quarkus java is sometimes faster than GoLang GIN https://medium.com/deno-the-complete-reference/quarkus-java-vs-gin-go-hello-world-performance-0a2ec6d92078

taw123 commented 7 months ago

Makes sense and complexity agree about targeting Go long term even if performance ends up being a wash or even slightly less optimal.

That said, any chance you might have some cycles to dominant the exported metrics here/on your repo? Even it it’s not pretty, I’d certainly be willing to help as I think it would help not just myself but others in general to fully exploit the work you have already done.

Thanks again.

martabal commented 6 months ago

Hey, I hate to promote my own stuff, but I rewrote this exporter in go https://github.com/martabal/qbittorrent-exporter last year. I've designed it to be as lightweight and fast as possible (it uses around 10-20MB of RAM, response time is <30ms and uncompressed Docker image size is 19.2MB) . It's fully compatible with this exporter and I added a few more metrics.