Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/histogram: Make Histogram::observe atomic across collects #314

Merged
merged 14 commits into from
Jul 14, 2020

Commits on Apr 20, 2020

  1. src/histogram: Add test ensuring Histogram::observe is atomic

    If an observe and a collect operation interleave, the latter should not
    expose a snapshot of the histogram that does not uphold all histogram
    invariants. For example for the invariant that the overall observation
    counter should equal the sum of all bucket counters: Say that an
    `observe` increases the overall counter but before updating a specific
    bucket counter a collect operation snapshots the histogram.
    
    This commits adds a basic unit test to test that the above is not
    happening.
    
    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Apr 20, 2020
    Configuration menu
    Copy the full SHA
    81e9949 View commit details
    Browse the repository at this point in the history
  2. src/{histogram,atomic64}: Make Histogram::observe atomic across collects

    A histogram supports two main execution paths:
    
    1. `observe` which increases the overall observation counter, updates
    the observation sum and increases a single bucket counter.
    
    2. `proto` (aka. collecting the metric, from now on referred to as the
    collect operation) which snapshots the state of the histogram and
    exposes it as a Protobuf struct.
    
    If an observe and a collect operation interleave, the latter could be
    exposing a snapshot of the histogram that does not uphold all histogram
    invariants. For example for the invariant that the overall observation
    counter should equal the sum of all bucket counters: Say that an
    `observe` increases the overall counter but before updating a specific
    bucket counter a collect operation snapshots the histogram.
    
    This commits adjusts the `HistogramCore` implementation to make such
    race conditions impossible. It introduces the notion of shards, one hot
    shard for `observe` operations to record their observation and one cold
    shard for collect operations to collect a consistent snapshot of the
    histogram.
    
    `observe` operations hit the hot shard and record their observation.
    Collect operations switch hot and cold, wait for all `observe` calls to
    finish on the previously hot now cold shard and then expose the
    consistent snapshot.
    
    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Apr 20, 2020
    Configuration menu
    Copy the full SHA
    f431b2a View commit details
    Browse the repository at this point in the history
  3. benches/histogram: Add benchmark for concurrent observe and collect

    Add a basic benchmark test which spawns 4 threads in the background
    continuously calling `observe` 1_000 times and then `collect`. At the
    same time call `observe` within the `Bencher::iter` closure to measure
    impact of background threads on `observe` call.
    
    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Apr 20, 2020
    Configuration menu
    Copy the full SHA
    6954253 View commit details
    Browse the repository at this point in the history
  4. src/histogram: Account for missing take without protobuf feature

    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Apr 20, 2020
    Configuration menu
    Copy the full SHA
    2b3fbc0 View commit details
    Browse the repository at this point in the history
  5. src/histogram,benches/histogram: Run Rust fmt

    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Apr 20, 2020
    Configuration menu
    Copy the full SHA
    2faf0e0 View commit details
    Browse the repository at this point in the history

Commits on Jun 19, 2020

  1. Configuration menu
    Copy the full SHA
    3db6ddf View commit details
    Browse the repository at this point in the history
  2. src/histogram: Drop collect lock guard explicitly

    Rusts drop semantics can be confusing sometimes. E.g. `let _ = l.lock()`
    would drop the lock guard immediately whereas `let _guard = l.lock()`
    would drop the guard in LIFO order at the end of the current scope.
    
    Instead of relying on the above guarantee with `let _guard`, drop the
    mutex guard explicitely hopefully making this less error prone in the
    future.
    
    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    79a499f View commit details
    Browse the repository at this point in the history
  3. src/histogram: Remove underscore prefix from used variable

    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    b0ef4e2 View commit details
    Browse the repository at this point in the history

Commits on Jul 14, 2020

  1. src/{atomic,histogram}: Make swap take ordering and tighten usage

    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Jul 14, 2020
    Configuration menu
    Copy the full SHA
    ff8f075 View commit details
    Browse the repository at this point in the history
  2. src/histogram: Test invariant that sum == count with observe(1.0)

    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Jul 14, 2020
    Configuration menu
    Copy the full SHA
    0df9322 View commit details
    Browse the repository at this point in the history
  3. src/atomic64: Adjust swap doc comment

    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Jul 14, 2020
    Configuration menu
    Copy the full SHA
    e4c58f2 View commit details
    Browse the repository at this point in the history
  4. src/histogram: Remove pub from shard related structs and fn

    Signed-off-by: Max Inden <mail@max-inden.de>
    mxinden committed Jul 14, 2020
    Configuration menu
    Copy the full SHA
    4ddabff View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    390a7d5 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    9fd6bfa View commit details
    Browse the repository at this point in the history