druid icon indicating copy to clipboard operation
druid copied to clipboard

Performance testing improvements

Open dclim opened this issue 10 years ago • 6 comments

There has been some recent discussion on the benefits of improving Druid's performance testing and setting up a standard performance test harness that is:

  1. easy to execute: can be scripted and run nightly, while also being runnable individually from a dev environment
  2. easy to contribute tests to: which will make it easier for contributors to add performance testing as part of PRs in a standardized way

This will provide Druid's already performance-sensitive community with a mechanism to more formally measure the impact of changes and will give developers a way to understand the implications of changes when contributing or reviewing performance-critical sections of code.

This issue is to provide a place for the community to express their thoughts around performance testing considerations, things like:

  • what's our criteria to determine if a test has passed or failed?
  • to what degree is cloud hardware or dev machines acceptable for performance tests vs. dedicated bare metal test hardware?

dclim avatar Apr 12 '16 20:04 dclim

IMHO anyone deploying druid needs appropriate production monitoring for performance. I suggest the goal here to be to catch obvious performance degradations, and not attempt to catch things that are completely scale dependent (ex: if something runs fine on a 4 core instance, but not on a 32 core instance, I don't think these tests are the appropriate place to catch such a thing)

The type of testing machine determines the repeatability of the tests, and as such, a VM or laptop would have to simply have more tests run to have a high degree of confidence in performance results. Such a scenario (assuming the VM is reasonable, like not a T-series from AWS) then I would expect it to be able to catch major performance regressions.

drcrallen avatar Apr 12 '16 20:04 drcrallen

I think the setup should be able to maintain history and fail tests only when there is a performance regression, depending on the hardware, absolute time taken to run a test might be high or low but on same hardware the time should not vary too much.

himanshug avatar Apr 12 '16 20:04 himanshug

JMHRunner Proposal

Based on the comments from @drcrallen and @himanshug + other offline discussions (@gianm), I think it makes sense for us to build a "runner" helper app. The main function of the runner is to provide persistence functionality which JMH doesn't natively have, which would allow us to a) define performance thresholds we can use to fail performance tests, and b) emit test data that we can use to build a history of performance over time.

The runner would be based on the JMH Java API, which returns a collection of results when run:

Collection<RunResult> results = new Runner(opt).run();

The idea is that we would define something like a ResultWriter and a BaselineReader interface, which would first be implemented to write and read to JSON flat files but could be eventually extended to read and write to a database, HTTP endpoint, S3, etc. For the JSON implementation, the output of the writer could be used as the input for the baseline reader. The runner would accept a generateBaseline parameter which would cause the results of that run to be written by the writer with a baseline flag; on the next run, the reader would then scan the file and would find the latest events tagged as baseline and use them as the baseline for that run.

To make this more clear, this is how it might work:

  • JMHRunner is executed; it reads a benchmarks.json file and finds the latest entries for each test (benchmark/parameter combination) that is labelled with the baseline flag
  • If each test in the list of tests to run didn't have a previous run to use as a baseline, the runner aborts and tells the user they need to generate a baseline for that test
  • If there was a baseline for all tests to run (or the runner had the generateBaseline parameter specified), the runner would execute the tests (by calling JMH's new Runner().run() which will do the usual process forking stuff) and would return the results of the test
  • The results would be appended to the benchmarks.json file
  • If it wasn't a baseline run, the results would then be compared to the baseline, and if they exceeded some threshold, the runner would exit with failure.

The proposed format for writing results would be something that is easily ingested into Druid so that we would have the option to use Druid to monitor performance tests (in the same way we use Druid for metrics monitoring, because Druid is da best). For example, the data might look like this:

{"timestamp":"2016-05-09T16:04:58.984Z","id":"io.druid.benchmark.ConciseComplementBenchmark.uncompressed-Throughput-emptyRows-1000","benchmark":"io.druid.benchmark.ConciseComplementBenchmark.uncompressed","mode":"Throughput","sampleCount":20,"score":36.41845411908736,"scoreUnit":"ops/us","scoreError":0.7878746926095094,"errorRatio":0.02163394113416183,"p50":36.637158309024244,"p90":37.16626927057083,"p95":37.24287720621276,"p99":37.24598917309243,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.002Z","id":"io.druid.benchmark.ConciseComplementBenchmark.uncompressed-Throughput-emptyRows-10000","benchmark":"io.druid.benchmark.ConciseComplementBenchmark.uncompressed","mode":"Throughput","sampleCount":20,"score":36.32715517899067,"scoreUnit":"ops/us","scoreError":0.616663390583611,"errorRatio":0.016975273388328795,"p50":36.54748901131131,"p90":36.90231952222449,"p95":36.99186864109728,"p99":36.99652874122591,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.002Z","id":"io.druid.benchmark.ConciseComplementBenchmark.uncompressed-AverageTime-emptyRows-1000","benchmark":"io.druid.benchmark.ConciseComplementBenchmark.uncompressed","mode":"AverageTime","sampleCount":20,"score":0.02709184900738217,"scoreUnit":"us/op","scoreError":1.188770166818284E-4,"errorRatio":0.004387925558327008,"p50":0.027066438906702156,"p90":0.027338037047910158,"p95":0.027386921329720114,"p99":0.027389079518541512,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.003Z","id":"io.druid.benchmark.ConciseComplementBenchmark.uncompressed-AverageTime-emptyRows-10000","benchmark":"io.druid.benchmark.ConciseComplementBenchmark.uncompressed","mode":"AverageTime","sampleCount":20,"score":0.027194119314113037,"scoreUnit":"us/op","scoreError":1.9676138483469723E-4,"errorRatio":0.007235438756517598,"p50":0.027156123671669283,"p90":0.0277090047094858,"p95":0.027747817190770817,"p99":0.027748193041071016,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.003Z","id":"io.druid.benchmark.DimensionPredicateFilterBenchmark.matchIsEven-AverageTime-cardinality-1000","benchmark":"io.druid.benchmark.DimensionPredicateFilterBenchmark.matchIsEven","mode":"AverageTime","sampleCount":20,"score":340.8350048284128,"scoreUnit":"us/op","scoreError":2.1311105566497384,"errorRatio":0.006252616446255593,"p50":340.72432117336666,"p90":343.5514078286976,"p95":346.8035907043599,"p99":346.972820228611,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.003Z","id":"io.druid.benchmark.DimensionPredicateFilterBenchmark.matchIsEven-AverageTime-cardinality-100000","benchmark":"io.druid.benchmark.DimensionPredicateFilterBenchmark.matchIsEven","mode":"AverageTime","sampleCount":20,"score":35379.40993910098,"scoreUnit":"us/op","scoreError":298.7792285284239,"errorRatio":0.008445003154171207,"p50":35284.26534482758,"p90":35542.31389655172,"p95":36657.849473953196,"p99":36716.40167857143,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.004Z","id":"io.druid.benchmark.DimensionPredicateFilterBenchmark.matchIsEven-AverageTime-cardinality-1000000","benchmark":"io.druid.benchmark.DimensionPredicateFilterBenchmark.matchIsEven","mode":"AverageTime","sampleCount":20,"score":325614.3205916667,"scoreUnit":"us/op","scoreError":6295.064173552967,"errorRatio":0.019332884874701896,"p50":323894.605125,"p90":327672.87419999996,"p95":354059.34785416664,"p99":355442.89033333334,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.004Z","id":"io.druid.benchmark.TimeParseBenchmark.parseNoContext-AverageTime-numBatches-10000","benchmark":"io.druid.benchmark.TimeParseBenchmark.parseNoContext","mode":"AverageTime","sampleCount":20,"score":7.37504070175E8,"scoreUnit":"ns/op","scoreError":1.721646108901912E7,"errorRatio":0.023344225184999835,"p50":7.3019919775E8,"p90":7.760390897E8,"p95":7.9664021555E8,"p99":7.97696596E8,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.004Z","id":"io.druid.benchmark.TimeParseBenchmark.parseNoContext-AverageTime-numBatches-100000","benchmark":"io.druid.benchmark.TimeParseBenchmark.parseNoContext","mode":"AverageTime","sampleCount":20,"score":7.439017072E8,"scoreUnit":"ns/op","scoreError":2.103624712106932E7,"errorRatio":0.028278261654014012,"p50":7.3389686325E8,"p90":7.915615579E8,"p95":8.150533508E8,"p99":8.1626208E8,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.004Z","id":"io.druid.benchmark.TimeParseBenchmark.parseNoContext-AverageTime-numBatches-500000","benchmark":"io.druid.benchmark.TimeParseBenchmark.parseNoContext","mode":"AverageTime","sampleCount":20,"score":7.590551233E8,"scoreUnit":"ns/op","scoreError":2.1118103090745386E7,"errorRatio":0.02782156715962105,"p50":7.4920938E8,"p90":8.0505842765E8,"p95":8.28197016625E8,"p99":8.294146945E8,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.005Z","id":"io.druid.benchmark.TimeParseBenchmark.parseNoContext-AverageTime-numBatches-1000000","benchmark":"io.druid.benchmark.TimeParseBenchmark.parseNoContext","mode":"AverageTime","sampleCount":20,"score":7.59819681E8,"scoreUnit":"ns/op","scoreError":1.8709652596795674E7,"errorRatio":0.024623806232778635,"p50":7.514978635E8,"p90":8.0510555055E8,"p95":8.21130046525E8,"p99":8.21927792E8,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.005Z","id":"io.druid.benchmark.TimeParseBenchmark.parseWithContext-AverageTime-numBatches-10000","benchmark":"io.druid.benchmark.TimeParseBenchmark.parseWithContext","mode":"AverageTime","sampleCount":20,"score":2.2686279074320085E7,"scoreUnit":"ns/op","scoreError":1792115.803572537,"errorRatio":0.07899558132479895,"p50":2.2304652446618356E7,"p90":2.6540789944736842E7,"p95":2.702926734868421E7,"p99":2.7054514710526317E7,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.005Z","id":"io.druid.benchmark.TimeParseBenchmark.parseWithContext-AverageTime-numBatches-100000","benchmark":"io.druid.benchmark.TimeParseBenchmark.parseWithContext","mode":"AverageTime","sampleCount":20,"score":9.373615378916666E7,"scoreUnit":"ns/op","scoreError":4365879.978200344,"errorRatio":0.04657626541857237,"p50":9.154570227272728E7,"p90":1.0455056766999999E8,"p95":1.07402813615E8,"p99":1.075438408E8,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.005Z","id":"io.druid.benchmark.TimeParseBenchmark.parseWithContext-AverageTime-numBatches-500000","benchmark":"io.druid.benchmark.TimeParseBenchmark.parseWithContext","mode":"AverageTime","sampleCount":20,"score":3.9653099206666666E8,"scoreUnit":"ns/op","scoreError":1.1900175313275995E7,"errorRatio":0.030010706732540294,"p50":3.911699466666666E8,"p90":4.185842724333333E8,"p95":4.394357664166666E8,"p99":4.40507675E8,"baseline":false}
{"timestamp":"2016-05-09T16:04:59.005Z","id":"io.druid.benchmark.TimeParseBenchmark.parseWithContext-AverageTime-numBatches-1000000","benchmark":"io.druid.benchmark.TimeParseBenchmark.parseWithContext","mode":"AverageTime","sampleCount":20,"score":7.6751458405E8,"scoreUnit":"ns/op","scoreError":1.983054972536445E7,"errorRatio":0.025837358843037415,"p50":7.5809771275E8,"p90":8.1637124765E8,"p95":8.33141779075E8,"p99":8.33958246E8,"baseline":false}

Ultimately, it would be pretty cool if we could do something like:

  • create a new EC2 instance and load the JMH runner JAR with the benchmarks
  • read a baseline file from S3
  • run the tests
  • write the results to Tranquility Server for ingestion into Druid
  • terminate the EC2 instance

Metrics and Threshold

JMH's benchmark "score" is calculated as the mean result over all the runs (not including warmups). It is supplemented with a "score error", which is the mean error at a 99.9% confidence interval. If the confidence interval is too wide (due to not enough iterations or wild variance during the iterations), the score error will be large proportional to the score. I think it makes sense to fail test runs if the scoreError/score ratio exceeds a certain threshold, since this means that the result is unreliable and not that meaningful anyway. This could be because of too few iterations, too much variance going on in the testing environment, or a badly written test. In any case, comparing say a baseline of [1000ops/sec] with a result of [1000ops/sec +/- 1000ops/sec] is a pretty useless comparison and should be a failure.

We can also get percentiles from the JMH results (in the above example I'm storing the p50, p90, p95, and p99). I'm undecided as to whether it is really necessary to capture percentiles as I believe performance benchmark results should be fairly normally distributed and hence the mean + CI should be good. Looking for any thoughts on this.

Alternatives

The primary alternative I see to building our own runner is to use JMH's Maven script to build a benchmarks.jar file, configure it to write the results to a file, and then write scripts to parse and act on the output generated by calling java -jar target/benchmarks.jar. I think building our own runner has a number of advantages over this, the main ones being the ability to check before running the benchmarks to make sure we have baselines available, and the ability to output the results to a format we want directly from their Java RunResult object instead of parsing their output file.

There are also plugins for Jenkins and TeamCity available; I haven't looked too much into them as I don't know that we want to tie ourselves to any specific build framework (and I like the idea of being able to emit results in a format that we can ingest into Druid).

Thoughts?

dclim avatar May 09 '16 19:05 dclim

Thanks @dclim for writing this up. Looks great. Some thoughts,

  1. A custom runner sounds good, I would probably prefer writing to Kafka rather than Tranquility Server though (that way it can go to wherever – Druid or S3 or what have you)
  2. I agree that we probably don't need to look at percentiles
  3. For the baselines, is the idea that we would manually run a job to generate the baseline file? If so, that sounds good. The one thing I would want to make sure of here is that it's difficult to accidentally upload a wonky baseline file. Maybe it'd be enough to generate the new file and let the person running the test decide if it's OK to upload.
  4. For deciding if a test passed or failed, are you thinking of the test being a threshold % (10% difference = fail) or some other thing?
  5. Results that are "too good" should fail too, I think. This will help ensure that we remember to update the baseline when we optimize something, and thereby prevent performance from regressing after an optimization.

gianm avatar Jun 15 '16 23:06 gianm

This issue has been marked as stale due to 280 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar May 30 '23 00:05 github-actions[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

github-actions[bot] avatar Jun 27 '23 00:06 github-actions[bot]