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

subscriber: update sharded-slab to 0.1, pool hashmap allocations #1062

Merged
merged 15 commits into from
Oct 22, 2020

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Oct 22, 2020

Motivation

hawkw/sharded-slab#45 changes sharded-slab so that the per-shard
metadata is allocated only when a new shard is created, rather than all
up front when the slab is created. This fixes the very large amount of
memory allocated by simply creating a new Registry without actually
collecting any traces.

Solution

This branch updates tracing-subscriber to depend on sharded-slab
0.1.0, which includes the upstream fix.

In addition, this branch the registry from using sharded_slab::Slab to
sharded_slab::Pool. This allows us to clear hashmap allocations for
extensions in-place, retaining the already allocated maps. This should
improve new_span performance a bit.

Fixes #1005

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw requested a review from a team as a code owner October 22, 2020 18:11
@hawkw
Copy link
Member Author

hawkw commented Oct 22, 2020

i'll also backport this to v0.1.x once it merges.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
this fixes an issue where the first time a slot is used, it starts with
0 refs instead of 1 ref, because the ref count is set to 1 in `clear`
instead.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Oct 22, 2020
`tracing-subscriber` can conditionally use `parking_lot`'s locks rather
than `std::sync`'s locks, when a feature flag is enabled. Because
`parking_lot`'s locks do not poison on panics, while `std::sync`'s locks
do, the APIs differ slightly. Currently, we handle this by wrapping the
`parking_lot` `RwLock` in a newtype that returns `Result`s, like
`std::sync::RwLock` does, but always returns `Ok`. Then, potentially
poisoned locks are handled at the callsite.

However, this is unnecessary (and potentially incorrect). Because locks
may or may not be poisoned depending on the feature flag,
`tracing-subscriber` can't rely on poisoning for correctness. Doing so
would mean potentially different behavior between `std::sync` and
`parking_lot`. Currently, because a number of `tracing-subscriber`
functions are called in `Drop` impls, we don't panic when a lock is
poisoned, to avoid double panics. Most cases where a lock might be
poisoned are handled by returning early with a default value. However,
with `parking_lot` enabled, this will never happen, and it adds
complexity at the callsite.

This branch changes our approach to wrap `std::sync`'s locks and use
`PoisonError::into_inner` to ignore poisoning. This results in more
consistent behavior between the `parking_lot` feature and `std`, and
also probably improves performance a bit with `parking_lot` --- we don't
have to have extra code for handling an `Err` case that will never
happen (although rustc might be smart enough to optimize it away). Also,
the callsites are simpler since they never have to handle poisoning, and
we can't accidentally `unwrap` in a `Drop` impl.

I also removed the janky user-space thread-local implementation used by
`CurrentSpan`, and changed it to just use the `thread-local` crate. We
already depend on that crate for the `Registry`, and my DIY
implementation has some performance issues. So, I removed it.

Depends on #1062
clippy was INNOCENT

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw merged commit 1bf9da2 into master Oct 22, 2020
hawkw added a commit that referenced this pull request Oct 22, 2020
This backports #1062 to v0.1.6. This has already been approved on
master.

hawkw/sharded-slab#45 changes `sharded-slab` so that the per-shard
metadata is allocated only when a new shard is created, rather than all
up front when the slab is created. This fixes the very large amount of
memory allocated by simply creating a new `Registry` without actually
collecting any traces.

This branch updates `tracing-subscriber` to depend on `sharded-slab`
0.1.0, which includes the upstream fix.

In addition, this branch the registry from using `sharded_slab::Slab` to
`sharded_slab::Pool`. This allows us to clear hashmap allocations for
extensions in-place, retaining the already allocated maps. This should
improve `new_span` performance a bit.

Fixes #1005

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Oct 22, 2020
This backports #1062 to v0.1.6. This has already been approved on
master.

hawkw/sharded-slab#45 changes `sharded-slab` so that the per-shard
metadata is allocated only when a new shard is created, rather than all
up front when the slab is created. This fixes the very large amount of
memory allocated by simply creating a new `Registry` without actually
collecting any traces.

This branch updates `tracing-subscriber` to depend on `sharded-slab`
0.1.0, which includes the upstream fix.

In addition, this branch the registry from using `sharded_slab::Slab` to
`sharded_slab::Pool`. This allows us to clear hashmap allocations for
extensions in-place, retaining the already allocated maps. This should
improve `new_span` performance a bit.

Fixes #1005

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
dvdplm added a commit to dvdplm/tracing that referenced this pull request Oct 23, 2020
* upstream/master:
  subscriber: update sharded-slab to 0.1, pool hashmap allocations (tokio-rs#1062)
  subscriber: remove deprecated type, structs, and methods tokio-rs#1030
  core: rename Subscriber to Collect (tokio-rs#1015)
  chore: fix rustdoc warning in tracing-subscriber (tokio-rs#1061)
dvdplm added a commit to dvdplm/tracing that referenced this pull request Oct 23, 2020
* dp-target-is-cow:
  subscriber: update sharded-slab to 0.1, pool hashmap allocations (tokio-rs#1062)
  subscriber: remove deprecated type, structs, and methods tokio-rs#1030
  core: rename Subscriber to Collect (tokio-rs#1015)
  chore: fix rustdoc warning in tracing-subscriber (tokio-rs#1061)
dvdplm added a commit to dvdplm/tracing that referenced this pull request Oct 23, 2020
…spatch-as-owned-tokio-rs#455

* upstream/master:
  subscriber: update sharded-slab to 0.1, pool hashmap allocations (tokio-rs#1062)
  subscriber: remove deprecated type, structs, and methods tokio-rs#1030
  core: rename Subscriber to Collect (tokio-rs#1015)
  chore: fix rustdoc warning in tracing-subscriber (tokio-rs#1061)
hawkw added a commit that referenced this pull request Oct 24, 2020
## Motivation

`tracing-subscriber` can conditionally use `parking_lot`'s locks rather
than `std::sync`'s locks, when a feature flag is enabled. Because
`parking_lot`'s locks do not poison on panics, while `std::sync`'s locks
do, the APIs differ slightly. Currently, we handle this by wrapping the
`parking_lot` `RwLock` in a newtype that returns `Result`s, like
`std::sync::RwLock` does, but always returns `Ok`. Then, potentially
poisoned locks are handled at the callsite.

However, this is unnecessary (and potentially incorrect). Because locks
may or may not be poisoned depending on the feature flag,
`tracing-subscriber` can't rely on poisoning for correctness. Doing so
would mean potentially different behavior between `std::sync` and
`parking_lot`. Currently, because a number of `tracing-subscriber`
functions are called in `Drop` impls, we don't panic when a lock is
poisoned, to avoid double panics. Most cases where a lock might be
poisoned are handled by returning early with a default value. However,
with `parking_lot` enabled, this will never happen, and it adds
complexity at the callsite.

## Solution

This branch changes our approach to wrap `std::sync`'s locks and use
`PoisonError::into_inner` to ignore poisoning. This results in more
consistent behavior between the `parking_lot` feature and `std`, and
also probably improves performance a bit with `parking_lot` --- we don't
have to have extra code for handling an `Err` case that will never
happen (although rustc might be smart enough to optimize it away). Also,
the callsites are simpler since they never have to handle poisoning, and
we can't accidentally `unwrap` in a `Drop` impl.

I also removed the janky user-space thread-local implementation used by
`CurrentSpan`, and changed it to just use the `thread-local` crate. We
already depend on that crate for the `Registry`, and my DIY
implementation has some performance issues. So, I removed it.

Depends on #1062
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
This backports tokio-rs#1062 to v0.1.6. This has already been approved on
master.

hawkw/sharded-slab#45 changes `sharded-slab` so that the per-shard
metadata is allocated only when a new shard is created, rather than all
up front when the slab is created. This fixes the very large amount of
memory allocated by simply creating a new `Registry` without actually
collecting any traces.

This branch updates `tracing-subscriber` to depend on `sharded-slab`
0.1.0, which includes the upstream fix.

In addition, this branch the registry from using `sharded_slab::Slab` to
`sharded_slab::Pool`. This allows us to clear hashmap allocations for
extensions in-place, retaining the already allocated maps. This should
improve `new_span` performance a bit.

Fixes tokio-rs#1005

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tracing-subscriber: big RAM usage
2 participants