Skip to content

Investigate prometheus metrics library (as medida replacement) #4945

Closed

Description

@marta-lokhova
  • Investigate performance vs medida

Activity

  1. marta-lokhova commented on Jan 28, 2026

    @marta-lokhova
    ContributorAuthor

    @drebelsky any learnings so far?

  2. drebelsky commented on Jan 28, 2026

    @drebelsky
    Contributor

    Putting some notes on what I recall about this from last year. The client libraries with non-GC languages listed on the prometheus docs are:

    • rust: one of the official SDKs
    • C: unofficial, under DigitalOcean Github org, doesn't seem to have been updated since 2020
    • C++: unofficial, under individual GitHub account jupp0r It's not listed on the page, but there is also
    • rust-prometheus: owned by TiKV, not listed on the page but seems to be more used than the official rust client library

    Last I checked, iirc, the official rust client library was missing some features we wanted, so we were leaning toward using the C++ library or rust-prometheus.

    One of our reasons for switching was the slow speed of the histogram/ckms—our implementation is lightly modified from the C++ client libraries (and iirc, was a little faster). When this was implemented in the C++ client library, the Java implementation's linked list became a vector in C++, which causes some of the slowdown. The algorithm is also known to be faulty1.

    The C++ client library isn't super well documented (for example, see the Exposer Documentation), and in the microbenchmarks that I adapted from the client library to medida, medida tended to perform better2. Other differences include Medida tracking information that Prometheus does not (e.g., one_minute_rate, five_minute_rate) and relatedly, Prometheus's /metrics endpoint only containing present (not historical values): we could work around this or have people run Grafana locally. I'll search for the results, but as I recall, the microbenchmarks in the C++ client library tended to have Medida outperforming Prometheus. There were also some considerations about integrating prometheus (and its dependencies) into core.

    Given the reasons listed above, we were leaning toward exploring rust-prometheus over the C++ client library.

    Since the last update, we also merged #4964, which presents an alternative to the medida histogram for measuring point loads.

    Footnotes

    1. There's some discussion in Add rust CKMS backend #4686, this blog post, and this PR in prometheus-haskell, which corresponds to the blog post. Note also that there is an implementation of the algorithm the Haskell library uses in Apache's DataSketches. ↩

    2. It performed better for the updating of metrics (e.g., compare counter increments).

      Unable to determine clock rate from sysctl: hw.cpufrequency: No such file or directory
      This does not affect benchmark measurements, only the metadata output.
      ***WARNING*** Failed to set thread affinity. Estimated CPU frequency may be incorrect.
      2026-01-27T16:47:16-08:00
      Running ./main
      Run on (14 X 24 MHz CPU s)
      CPU Caches:
        L1 Data 64 KiB
        L1 Instruction 128 KiB
        L2 Unified 4096 KiB (x14)
      Load Average: 1.72, 1.51, 1.64
      ---------------------------------------------------------------------------------------------
      Benchmark                                                   Time             CPU   Iterations
      ---------------------------------------------------------------------------------------------
      BM_Counter_Increment                                     4.05 ns         4.05 ns    168990691
      BM_Counter_Collect                                       2.18 ns         2.18 ns    322510793
      BM_Medida_Counter_Increment                              1.56 ns         1.56 ns    449501695
      BM_Gauge_Increment                                       4.00 ns         4.00 ns    174641984
      BM_Gauge_Decrement                                       4.00 ns         4.00 ns    174594504
      BM_Gauge_SetToCurrentTime                                18.8 ns         18.8 ns     38260356
      BM_Gauge_Collect                                         1.74 ns         1.74 ns    383387281
      BM_Medida_Counter_Decrement                              1.56 ns         1.56 ns    449008653
      BM_Histogram_Observe/0/manual_time                       18.3 ns         36.7 ns     38107883
      BM_Histogram_Observe/1/manual_time                       18.4 ns         36.8 ns     38257263
      BM_Histogram_Observe/8/manual_time                       18.3 ns         36.8 ns     36899510
      BM_Histogram_Observe/64/manual_time                      18.3 ns         36.7 ns     38248297
      BM_Histogram_Observe/512/manual_time                     18.3 ns         36.6 ns     38292693
      BM_Histogram_Observe/4096/manual_time                    18.4 ns         36.8 ns     36569162
      BM_Histogram_Collect/0                                   15.6 ns         15.6 ns     44456864
      BM_Histogram_Collect/1                                   15.4 ns         15.4 ns     45639177
      BM_Histogram_Collect/8                                   27.2 ns         27.2 ns     25638959
      BM_Histogram_Collect/64                                   269 ns          269 ns      2585736
      BM_Histogram_Collect/512                                 2233 ns         2233 ns       318347
      BM_Histogram_Collect/4096                               17799 ns        17798 ns        38996
      BM_Medida_Buckets_Observe/0/manual_time                  5848 ns         5866 ns       203967
      BM_Medida_Buckets_Observe/1/manual_time                  4824 ns         4843 ns       351290
      BM_Medida_Buckets_Observe/8/manual_time                  4572 ns         4592 ns      1319003
      BM_Medida_Buckets_Observe/64/manual_time                  648 ns          668 ns      1000000
      BM_Medida_Buckets_Observe/512/manual_time                 437 ns          456 ns      3941651
      BM_Medida_Buckets_Observe/4096/manual_time                197 ns          216 ns      3749877
      BM_Info_Collect                                          1.61 ns         1.61 ns    438308131
      BM_Registry_CreateFamily                                 14.4 ns         14.4 ns     48515764
      BM_Registry_CreateCounter/0                              41.5 ns         41.5 ns     16447137
      BM_Registry_CreateCounter/1                               378 ns          378 ns      2404713
      BM_Registry_CreateCounter/8                              1300 ns         1300 ns       571611
      BM_Registry_CreateCounter/64                            10601 ns        10600 ns        65602
      BM_Registry_CreateCounter/512                           96085 ns        96079 ns         7375
      BM_Registry_CreateCounter/4096                         945525 ns       945453 ns          748
      BM_Medida_CreateCounter/0/manual_time                    11.7 ns         30.5 ns     59746772
      BM_Medida_CreateCounter/1/manual_time                    1520 ns         1677 ns      1047072
      BM_Medida_CreateCounter/8/manual_time                   12852 ns        14378 ns       139089
      BM_Medida_CreateCounter/64/manual_time                  79706 ns        92539 ns        10000
      BM_Medida_CreateCounter/512/manual_time                538582 ns       651472 ns         1000
      BM_Medida_CreateCounter/4096/manual_time              4428921 ns      5447802 ns          207
      BM_Summary_Observe/0/iterations:262144                   2767 ns         2766 ns       262144
      BM_Summary_Observe/1/iterations:262144                   2795 ns         2795 ns       262144
      BM_Summary_Observe/8/iterations:262144                   3916 ns         3916 ns       262144
      BM_Summary_Observe/64/iterations:262144                  5119 ns         5118 ns       262144
      BM_Medida_CKMS_Insert/0/iterations:262144                 565 ns          565 ns       262144
      BM_Medida_CKMS_Insert/1/iterations:262144                 577 ns          577 ns       262144
      BM_Medida_CKMS_Insert/8/iterations:262144                 808 ns          808 ns       262144
      BM_Medida_CKMS_Insert/64/iterations:262144               1046 ns         1046 ns       262144
      BM_Summary_Collect/0/0                                   5.35 ns         5.35 ns    125801988
      BM_Summary_Collect/1/0                                   26.6 ns         26.6 ns     26562340
      BM_Summary_Collect/8/0                                    122 ns          122 ns      5674955
      BM_Summary_Collect/64/0                                   895 ns          895 ns       779996
      BM_Summary_Collect/0/1                                   5.61 ns         5.61 ns    123581025
      BM_Summary_Collect/1/1                                   26.6 ns         26.6 ns     26267402
      BM_Summary_Collect/8/1                                    132 ns          132 ns      5222672
      BM_Summary_Collect/64/1                                  2226 ns         2226 ns       318792
      BM_Summary_Collect/0/8                                   5.37 ns         5.37 ns    121936349
      BM_Summary_Collect/1/8                                   28.4 ns         28.4 ns     23897555
      BM_Summary_Collect/8/8                                    337 ns          337 ns      2086786
      BM_Summary_Collect/64/8                                 13668 ns        13667 ns        51468
      BM_Summary_Collect/0/64                                  5.55 ns         5.55 ns    130570219
      BM_Summary_Collect/1/64                                  56.8 ns         56.8 ns     12277256
      BM_Summary_Collect/8/64                                  1913 ns         1913 ns       366640
      BM_Summary_Collect/64/64                                96392 ns        96386 ns         7338
      BM_Summary_Collect/0/512                                 5.57 ns         5.57 ns    128697762
      BM_Summary_Collect/1/512                                  278 ns          278 ns      2521668
      BM_Summary_Collect/8/512                                 9206 ns         9205 ns        79995
      BM_Summary_Collect/64/512                              520976 ns       520944 ns         1354
      BM_Summary_Collect/0/4096                                5.66 ns         5.66 ns    131578947
      BM_Summary_Collect/1/4096                                 346 ns          346 ns      1599601
      BM_Summary_Collect/8/4096                               23222 ns        23221 ns        30563
      BM_Summary_Collect/64/4096                            1371900 ns      1371820 ns          529
      BM_Summary_Collect/0/32768                               5.62 ns         5.62 ns    125693559
      BM_Summary_Collect/1/32768                                668 ns          668 ns       985471
      BM_Summary_Collect/8/32768                              68516 ns        68513 ns        10297
      BM_Summary_Collect/64/32768                           3906639 ns      3906464 ns          179
      BM_Summary_Collect/0/262144                              5.54 ns         5.54 ns    131346868
      BM_Summary_Collect/1/262144                              1717 ns         1716 ns       391140
      BM_Summary_Collect/8/262144                            178278 ns       178269 ns         3903
      BM_Summary_Collect/64/262144                         10352060 ns     10351338 ns           68
      BM_Summary_Observe_Common/iterations:262144              2115 ns         2115 ns       262144
      BM_Medida_CKMS_Insert_Common/iterations:262144            570 ns          570 ns       262144
      BM_Summary_Collect_Common/0                              68.5 ns         68.5 ns     10140372
      BM_Summary_Collect_Common/1                              71.6 ns         71.6 ns      9900150
      BM_Summary_Collect_Common/8                               128 ns          128 ns      5545521
      BM_Summary_Collect_Common/64                              398 ns          398 ns      1750722
      BM_Summary_Collect_Common/512                             887 ns          887 ns       799105
      BM_Summary_Collect_Common/4096                           4245 ns         4245 ns       163408
      BM_Summary_Collect_Common/32768                          9849 ns         9848 ns        70775
      BM_Summary_Collect_Common/262144                        26523 ns        26521 ns        26174
      BM_Summary_Observe_Medida_Ranges/iterations:262144      11818 ns        11817 ns       262144
      BM_Medida_Histogram/iterations:262144                    4211 ns         4211 ns       262144
      
      ↩
  3. drebelsky commented on Apr 9, 2026

    @drebelsky
    Contributor

    Closing the issue since the initial investigation is done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions