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

Add cuckoo-based drop cache #567

Merged
merged 13 commits into from
Nov 22, 2022
Merged

Add cuckoo-based drop cache #567

merged 13 commits into from
Nov 22, 2022

Conversation

kentquirk
Copy link
Contributor

Which problem is this PR solving?

Currently, Refinery uses a circular LRU cache to retain a record for every trace; this cache is hardcoded to 5x the configured cache size, and does not change when the cache is resized.

This is a relatively small number, and for long-lived traces, it might mean that late spans look like new traces, and therefore might get a different sampling decision -- which would result in missing spans in Honeycomb.

#561 abstracted the SampleCache interface to prepare for other implementations. This uses it to provide a new cache design.

Short description of the changes

This design implements a "cuckoo filter" cache for dropped traces, which can store the dropped trace information much more efficiently (about 4 bytes per trace as compared to about 200 bytes for kept traces).

  • Adds a CuckooTraceChecker type that implements a 2-stage cuckoo filter for tracking recently-used trace IDs over time.
  • Implements the SampleCache interface with a CuckooSentCache, which uses the existing LRU for kept traces, and a CuckooTraceChecker for dropped traces.
  • Implements a new configuration block for caches to allow users to opt into the cuckoo cache and control it for their needs, but is still backwards compatible.
  • Adds documentation to the config_complete file.

@kentquirk kentquirk requested a review from a team November 18, 2022 19:05
@MikeGoldsmith MikeGoldsmith added type: enhancement New feature or request version: bump minor A PR that adds behavior, but is backwards-compatible. labels Nov 21, 2022
Comment on lines 55 to 63
if c.firstTime && dropFactor > 0.5 {
c.mut.Lock()
defer c.mut.Unlock()
c.firstTime = false
}
// if the current one is full, cycle the filters
if dropFactor > 0.99 {
c.mut.Lock()
defer c.mut.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this result in a deadlock? We could acquire a lock on line 56, defer unlock on line 57 and then try to acquire another lock on line 62. Will the lock be released as part of the if statement scope closing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa -- good catch. The lock will NOT be released and this can cause a deadlock. Will fix!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in latest update, please re-review.

collect/cache/cuckoo.go Outdated Show resolved Hide resolved
collect/cache/cuckooSentCache.go Show resolved Hide resolved
collect/cache/cuckooSentCache.go Show resolved Hide resolved
collect/collect.go Outdated Show resolved Hide resolved
collect/cache/cuckooSentCache.go Outdated Show resolved Hide resolved
Copy link
Contributor

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs PR title updating 😄

config_complete.toml Outdated Show resolved Hide resolved
collect/cache/cuckoo.go Outdated Show resolved Hide resolved
collect/cache/cuckoo.go Show resolved Hide resolved
@kentquirk kentquirk changed the title Kent.add cuckoo drop cache Add cuckoo-based drop cache Nov 21, 2022
collect/cache/cuckoo.go Outdated Show resolved Hide resolved
collect/cache/cuckoo.go Outdated Show resolved Hide resolved
collect/cache/cuckooSentCache.go Outdated Show resolved Hide resolved
Copy link
Contributor

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

collect/cache/cuckoo.go Outdated Show resolved Hide resolved
collect/cache/cuckoo.go Show resolved Hide resolved
@kentquirk kentquirk merged commit 6dccaa9 into main Nov 22, 2022
@kentquirk kentquirk deleted the kent.add_cuckoo_drop_cache branch November 22, 2022 22:28
ghost pushed a commit to opsramp/tracing-proxy that referenced this pull request Jul 5, 2024
## Which problem is this PR solving?

Before this change, Refinery used a circular LRU cache to retain a record for
every trace; this cache is hardcoded to 5x the configured cache size,
and does not change when the cache is resized.

This is a relatively small number, and for long-lived traces, it might
mean that late spans look like new traces, and therefore might get a
different sampling decision -- which would result in missing spans in
Honeycomb.

honeycombio#561 abstracted the SampleCache interface to prepare for other
implementations. This uses it to provide a new cache design.

## Short description of the changes

This design implements a "cuckoo filter" cache for dropped traces, which
can store the dropped trace information much more efficiently (about 4
bytes per trace as compared to about 200 bytes for kept traces).

- Adds a CuckooTraceChecker type that implements a 2-stage cuckoo filter
for tracking recently-used trace IDs over time.
- Implements the SampleCache interface with a CuckooSentCache, which
uses the existing LRU for kept traces, and a CuckooTraceChecker for
dropped traces.
- Implements a new configuration block for caches to allow users to opt
into the cuckoo cache and control it for their needs, but is still
backwards compatible.
- Adds documentation to the config_complete file.
- Adds additional metrics for tracking the cuckoo cache size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request version: bump minor A PR that adds behavior, but is backwards-compatible.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants