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

profiler: start collecting profiles immediately #1417

Merged
merged 4 commits into from
Aug 8, 2022

Conversation

nsrip-dd
Copy link
Contributor

@nsrip-dd nsrip-dd commented Aug 5, 2022

Previously, it would take two minutes for the first profile to be
uploaded. One minute for the internal time.Ticker to fire, and then an
additional minute to collect the profiles for the first time. This means
we wouldn't get profiles for the first minute of activity.

Two tests had to be changed due to this:

  • TestStartStopIdempotency became significantly slower, because it would
    start 5000 profiles, and stopping each one involved waiting 200 ms
    for the CPU profile to stop. Changed to just collect the heap profile
    and to do fewer iterations.
  • TestProfilerInternal broke because it expected one round of profiling
    to happen after the "ticker" fired, but now one happens sooner so you
    see multiple profiles. It also broke because the test was supposed to
    close p.exit, not send to it. In general, the test is too tied to the
    specific implementation. TestAllUploaded covers all the same behavior
    and more, and didn't get broken by this implementation change. So I
    opted to just delete TestProfilerInternal.

Previously, it would take two minutes for the first profile to be
uploaded. One minute for the internal time.Ticker to fire, and then an
additional minute to collect the profiles for the first time. This means
we wouldn't get profiles for the first minute of activity.

Two tests had to be changed due to this:

* TestStartStopIdempotency became significantly slower, because it would
  start 5000 profiles, and stopping each one involved waiting 200 ms
  for the CPU profile to stop. Changed to just collect the heap profile
  and to do fewer iterations.
* TestProfilerInternal broke because it expected one round of profiling
  to happen after the "ticker" fired, but now one happens sooner so you
  see multiple profiles. It also broke because the test was supposed to
  close p.exit, not send to it. In general, the test is too tied to the
  specific implementation. TestAllUploaded covers all the same behavior
  and more, and didn't get broken by this implementation change. So I
  opted to just delete TestProfilerInternal.
@nsrip-dd nsrip-dd requested a review from a team as a code owner August 5, 2022 18:04
@nsrip-dd nsrip-dd added this to the 1.41.0 milestone Aug 5, 2022
@@ -241,58 +243,6 @@ func TestStopLatency(t *testing.T) {
}
}

func TestProfilerInternal(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: We could "fix" this test by removing the tick <- time.Now() line and changing p.exit <- struct{}{} to close(p.exit). That would make the test pass. However I personally think this test should just be removed.

@@ -568,3 +518,32 @@ func TestTelemetryEnabled(t *testing.T) {
check("profile_period", time.Duration(10*time.Millisecond).String())
check("cpu_duration", time.Duration(1*time.Millisecond).String())
}

func TestImmediateProfile(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I've come up with so far for testing this change. Time-based tests aren't my favorite but I think this should be okay & not flaky. I'm open to other ideas!

Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with this test. The alternative would be a test that uses an unstartedProfiler and calls the collect() method with a ticket that never fires and still expect a profile.

Copy link
Member

@felixge felixge left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks 🙇

@@ -568,3 +518,32 @@ func TestTelemetryEnabled(t *testing.T) {
check("profile_period", time.Duration(10*time.Millisecond).String())
check("cpu_duration", time.Duration(1*time.Millisecond).String())
}

func TestImmediateProfile(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with this test. The alternative would be a test that uses an unstartedProfiler and calls the collect() method with a ticket that never fires and still expect a profile.

@nsrip-dd nsrip-dd merged commit 03a3099 into main Aug 8, 2022
@nsrip-dd nsrip-dd deleted the feature-collect-profiles-immediately branch August 8, 2022 15:06
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.

2 participants