Last active
July 17, 2025 08:33
-
-
Save andsel/b463c32a8cbe12ee60546add7c90a789 to your computer and use it in GitHub Desktop.
Test size estimation of HdrHistogram varying the accuracy and max value stored
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///usr/bin/env jbang "$0" "$@" ; exit $? | |
| //DEPS info.picocli:picocli:4.6.3 | |
| //DEPS org.hdrhistogram:HdrHistogram:2.2.2 | |
| import picocli.CommandLine; | |
| import picocli.CommandLine.Command; | |
| import picocli.CommandLine.Option; | |
| import picocli.CommandLine.Parameters; | |
| import java.security.SecureRandom; | |
| import java.time.Duration; | |
| import java.util.List; | |
| import java.util.ArrayList; | |
| import java.util.concurrent.Callable; | |
| import java.util.concurrent.CountDownLatch; | |
| import java.util.concurrent.TimeUnit; | |
| import org.HdrHistogram.Recorder; | |
| import org.HdrHistogram.Histogram; | |
| @Command(name = "hdrhistogram_size", mixinStandardHelpOptions = true, version = "hdrhistogram_size 0.1", | |
| description = "hdrhistogram_size checker script made with jbang") | |
| class hdrhistogram_size implements Callable<Integer> { | |
| public static void main(String... args) { | |
| int exitCode = new CommandLine(new hdrhistogram_size()).execute(args); | |
| System.exit(exitCode); | |
| } | |
| @Override | |
| public Integer call() throws Exception { | |
| System.out.println("HdrHistoragm size test start"); | |
| Histogram histogram = new Histogram(32 * 1024 * 1024 * 1024L, 4); | |
| // Histogram histogram = new Histogram(20 * 1024 * 1024L, 4); | |
| // Histogram histogram = new Histogram(2 * 1024L, 3); | |
| histogram.recordValue(histogram.getHighestTrackableValue() + 1); | |
| long histogramFootprint = histogram.getEstimatedFootprintInBytes(); | |
| long highest = histogram.getHighestTrackableValue(); | |
| long max = histogram.getMaxValue(); | |
| System.out.printf("Estimation of histogram in bytes: %d, highest trackable value: %d, max tracked value: %d %n", | |
| histogramFootprint, highest, max); | |
| histogram.recordValue(histogram.getHighestTrackableValue() + 1_000_000); | |
| // histogram.recordValue(histogram.getHighestTrackableValue() + 1_000); | |
| max = histogram.getMaxValue(); | |
| histogram.recordValue(100); | |
| long min = histogram.getMinValue(); | |
| System.out.printf("max tracked value after +1M: %d, min: %d %n", max, min); | |
| Histogram histogramByteSize = new Histogram(20 * 1024 * 1024L, 3); | |
| Histogram histogramEventCount = new Histogram(4 * 1024L, 3); | |
| int currentSnapshotsNum = 10; | |
| int minute_1_SnapshotsNum = 20; | |
| int minute_5_SnapshotsNum = 20; | |
| int minute_15_SnapshotsNum = 30; | |
| int hour_1_SnapshotsNum = 60; | |
| int totalSnapshots = minute_1_SnapshotsNum + minute_5_SnapshotsNum + minute_15_SnapshotsNum + hour_1_SnapshotsNum; | |
| long byteSizeMetricConsumption = histogramByteSize.getEstimatedFootprintInBytes() * totalSnapshots; | |
| long eventCountMetricConsumption = histogramEventCount.getEstimatedFootprintInBytes() * totalSnapshots; | |
| System.out.printf("Estimated total memory for flow metrics (%d digits) %n" + | |
| "\tbyte size metric %d bytes, event count metric %d bytes (total %d bytes) %n", | |
| histogramByteSize.getNumberOfSignificantValueDigits(), byteSizeMetricConsumption, | |
| eventCountMetricConsumption, byteSizeMetricConsumption + eventCountMetricConsumption); | |
| return 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment