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

feat(memory): Implement shared memory state across Relay #3821

Merged
merged 40 commits into from
Jul 22, 2024

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented Jul 16, 2024

This PR implements a new shared memory state MemoryStat which allows polling memory usage from multiple threads.

This new mechanism is implemented in place of the old BufferGuard which was statically maxing out the number of possible envelopes that go through Relay.

Thanks to the new mechanism, the following code was removed:

  • BufferGuard and all related code
  • Semaphore and all related code

Some tests that tested permits were also removed. We are planning a new implementation of the spooler, in which we will figure out a way to properly test memory limits.

Closes: https://github.com/getsentry/team-ingest/issues/367

@iambriccardo iambriccardo changed the title riccardo/feat/remove semaphore feat(memory): Implement shared memory state across Relay Jul 16, 2024
@iambriccardo iambriccardo requested a review from jjbayer July 18, 2024 09:36
relay-server/src/services/health_check.rs Outdated Show resolved Hide resolved
relay-server/src/utils/memory.rs Show resolved Hide resolved
relay-server/src/utils/memory.rs Outdated Show resolved Hide resolved
@iambriccardo iambriccardo requested a review from jjbayer July 18, 2024 13:06
@iambriccardo iambriccardo marked this pull request as ready for review July 19, 2024 08:08
@iambriccardo iambriccardo requested a review from a team as a code owner July 19, 2024 08:08
relay-server/src/endpoints/common.rs Outdated Show resolved Hide resolved
relay-server/src/utils/memory.rs Outdated Show resolved Hide resolved
relay-server/src/utils/memory.rs Outdated Show resolved Hide resolved
relay-server/src/utils/memory.rs Outdated Show resolved Hide resolved
relay-server/src/utils/memory.rs Outdated Show resolved Hide resolved
relay-server/src/utils/memory.rs Outdated Show resolved Hide resolved
relay-server/src/utils/memory.rs Outdated Show resolved Hide resolved
@iambriccardo iambriccardo force-pushed the riccardo/feat/remove-semaphore branch from b7decf2 to 05b1317 Compare July 19, 2024 10:34
Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

Left a few nits, but looks good overall! Let's maybe wait until Monday before we deploy :)

relay-server/src/endpoints/common.rs Outdated Show resolved Hide resolved
relay-server/src/endpoints/common.rs Show resolved Hide resolved
relay-server/src/service.rs Outdated Show resolved Hide resolved
use sysinfo::{MemoryRefreshKind, System};

/// Count after which the [`MemoryStat`] data will be refreshed.
const UPDATE_TIME_THRESHOLD_MS: u64 = 100;
Copy link
Member

Choose a reason for hiding this comment

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

Should we make this configurable?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could do that, I could put it under the health key.

relay-server/src/utils/memory.rs Outdated Show resolved Hide resolved
relay-server/src/utils/memory.rs Outdated Show resolved Hide resolved
iambriccardo and others added 9 commits July 19, 2024 13:01
Co-authored-by: Joris Bayer <joris.bayer@sentry.io>
Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
@@ -220,7 +222,7 @@ impl ServiceState {
);
ProjectCacheService::new(
config.clone(),
buffer_guard.clone(),
MemoryChecker::new(memory_stat.clone(), config.clone()),
Copy link
Member

Choose a reason for hiding this comment

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

Instead of creating new memory checkers, we could just clone a single one and pass that around and internally create the MemoryStat in the constructor.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could also do that yes, we will likely not use MemoryStat in isolation, so it's fair to implement it this way.

@iambriccardo iambriccardo merged commit ebf3351 into master Jul 22, 2024
23 checks passed
@iambriccardo iambriccardo deleted the riccardo/feat/remove-semaphore branch July 22, 2024 11:29
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.

4 participants