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

Bug 1916673 - Buffered API for memory/timing distributions #2948

Merged
merged 4 commits into from
Sep 17, 2024

Conversation

badboy
Copy link
Member

@badboy badboy commented Sep 2, 2024

This is the implementation for what's being designed in bug-1915388

  • final ack in the design bug
  • docs will be done separately (bug-1917809)
  • experimental marker

@badboy badboy requested a review from a team as a code owner September 2, 2024 11:28
@badboy badboy requested review from chutten and removed request for a team September 2, 2024 11:28
@badboy badboy marked this pull request as draft September 2, 2024 11:28
@badboy badboy changed the title Buffered API for memory/timing distributions Bug 1916673 - Buffered API for memory/timing distributions Sep 4, 2024
@badboy
Copy link
Member Author

badboy commented Sep 4, 2024

Usage of it WIP: https://phabricator.services.mozilla.com/D221017

Copy link
Contributor

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Thank you for the work here.

If I understand this pull request correctly, it only adds a buffered API to MemoryDistribution and TimingDistribution.

In https://phabricator.services.mozilla.com/D220062 I want to add 4 new metrics:

  1. http3_udp_datagram_segment_size_sent
  2. http3_udp_datagram_segment_size_received
  3. http3_udp_datagram_size_received
  4. http3_udp_datagram_num_segments_received

(1), (2) and (3) I can model with a MemoryDistribution. (4) on the other hand counts the number of segments received, where values range between 1 and 128.

Here is metrics definition draft from the above Phabricator patch.

  http3_udp_datagram_num_segments_received:
    type: custom_distribution
    unit: integer
    range_min: 0
    # Maximum number of UDP segments per datagram.
    #
    # See e.g. Linux https://github.com/torvalds/linux/blob/20371ba120635d9ab7fc7670497105af8f33eb08/include/linux/udp.h#L111.
    range_max: 128
    bucket_count: 100
    histogram_type: exponential
    description: >
      HTTP3 UDP number of segments per datagram received.
    bugs:
      - https://bugzilla.mozilla.org/show_bug.cgi?id=1906853
    data_reviews:
      - https://bugzilla.mozilla.org/show_bug.cgi?id=1906853
    data_sensitivity:
      - technical
    notification_emails:
      - necko@mozilla.com
      - minden@mozilla.com
    expires: never

I assume this is best modeled by the CustomDistribution. Would a buffered API for CustomDistribution be included in this patch?

(Note, in case you want to ship a buffered API for one distribution only for now, I assume I could as well model (1), (2) and (3) with a CustomDistribution instead of a MemoryDistribution.)

glean-core/src/metrics/memory_distribution.rs Show resolved Hide resolved
glean-core/src/metrics/memory_distribution.rs Outdated Show resolved Hide resolved
glean-core/src/metrics/memory_distribution.rs Show resolved Hide resolved
glean-core/src/histogram/mod.rs Show resolved Hide resolved
glean-core/src/metrics/memory_distribution.rs Outdated Show resolved Hide resolved
glean-core/src/metrics/memory_distribution.rs Outdated Show resolved Hide resolved
glean-core/src/metrics/memory_distribution.rs Outdated Show resolved Hide resolved
glean-core/src/metrics/timing_distribution.rs Show resolved Hide resolved
glean-core/src/metrics/memory_distribution.rs Outdated Show resolved Hide resolved
samples/rust/src/main.rs Outdated Show resolved Hide resolved
@badboy badboy marked this pull request as ready for review September 10, 2024 10:10
@badboy badboy force-pushed the buffered-distributions-api branch from 0886642 to 0e29b7e Compare September 10, 2024 10:58
@badboy badboy requested a review from chutten September 10, 2024 11:12
@badboy badboy force-pushed the buffered-distributions-api branch 2 times, most recently from 71713ac to 7ea4e2b Compare September 10, 2024 12:44
Copy link
Contributor

@chutten chutten left a comment

Choose a reason for hiding this comment

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

As much as I'd like this to be a r+with_followups, I think we need to decide about the FFI and Kotlin interfaces for certain before we ship this, as subsequent changes will be breaking.

/**
* Record data from the histogram buffer into the associated metric.
*
* This instance must not be used after `commit()` is called.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to prevent it from being used after commit()? I think the Java-like pattern is tothrow new IllegalStateException("Use after commit");

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm.
Then we need to track that state.

I'm considering to remove the Kotlin part. The first user is Rust only.

class LocalTimingDistribution(
val metric: TimingDistributionMetricType,
val inner: FfiLocalTimingDistribution,
) : AutoCloseable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want protected fun finalize() { /* TODO: bug 1691073 */ report_some_error(); ffi_abandon_buffer(this); or whatever to help report misuse and prevent memory leaks.

}

/// Record data from the histogram buffer into this metric.
pub fn ffi_commit_buffer(&self, buffer: Arc<FfiLocalTimingDistribution>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we clear the buffer to stop folks accidentally committing the same buffer twice? Or is that prevented somewhere/somehow else? For non-FFI we rely on the "called at most once" behaviour of drop, but I don't see us accounting for the lack of that guarantee (or testing that case) here.

@badboy badboy force-pushed the buffered-distributions-api branch from 7ea4e2b to 8175fc8 Compare September 11, 2024 11:13
@badboy
Copy link
Member Author

badboy commented Sep 11, 2024

Ok, I split Kotlin out so we can tackle that separately.

@badboy badboy requested a review from chutten September 11, 2024 15:33
@badboy badboy force-pushed the buffered-distributions-api branch from 8175fc8 to 3affca9 Compare September 16, 2024 12:20
Copy link
Contributor

@chutten chutten left a comment

Choose a reason for hiding this comment

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

r+wc

@badboy badboy force-pushed the buffered-distributions-api branch from 3affca9 to 4d58644 Compare September 17, 2024 09:50
@badboy badboy merged commit 4f03d77 into main Sep 17, 2024
29 of 30 checks passed
@badboy badboy deleted the buffered-distributions-api branch September 17, 2024 10:07
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.

3 participants