PromPHP / prometheus_client_php

Prometheus instrumentation library for PHP applications
https://prometheus.io/docs/concepts/metric_types/
Apache License 2.0
423 stars 93 forks source link

Implement next-gen APC storage engine (APCng) #72

Closed thedeacon closed 2 years ago

thedeacon commented 2 years ago

This PR deprecates the older PR #37 and solves Issue #36 . It also fixes a few places where Issue #27 can crop up, for instance if an APC value is deleted by another process at just the right moment, the APC engine would spin forever waiting for apcu_cas to succeed - this solves the problem by limiting the number of iterations we will wait.

README.APCng.md includes detailed benchmarking results comparing the original APC engine vs this new APCng engine, as requested by @LKaemmerling . Also as requested, this is implemented as a new Storage engine type, since the storage format is not compatible. Either the APC or APCng engine may be employed by users, both are currently treated equally and APC remains unchanged.

I put a fair amount of effort into a semi-automated performance-test "mini suite", including some assertions around performance of APCng relative to APC (basically: it should be much faster for collect() calls, and approximately the same speed for all other calls to the storage layer). This "Performance" PHPUnit group is excluded by default, since it takes many minutes to complete, but the README files include instructions on how to run this test suite. PHPUnit isn't the best tool for the job, but I do like the ability to make assertions about relative performance, and it beats trying to write up my own test harness and make it work cross-platform.

By comparing the src/Prometheus/Storage/APCng.php with the APC.php from #37 , one can see the overall structure of the engine is very similar, so most of the comments from that PR about the storage structure and function are still relevant. However, a few changes have been made to improve stability and speed, and remove complex code that offers little actual performance increase, based on real-world experience in our production environment. See README.APCng.md for a more-detailed description of how the engine works.

I am happy to answer questions or respond/engage in any other ways needed for anyone reviewing this PR, just let me know!

thedeacon commented 2 years ago

Thank you for the kind words, @LKaemmerling! I've fixed up the two items you pointed out.

LKaemmerling commented 2 years ago

As i said really good job @thedeacon! A release with the new storage engine will follow asap! Good job!