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

Added basic event counters for hosting #10884

Merged
merged 1 commit into from
Jun 5, 2019
Merged

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Jun 5, 2019

  • Added Request Rate counter (RPS), Total Requests counter, current requests and failed requests.
  • Counters do nothing until enabled
  • Added tests for counters and improved tests to use unique event source names
  • Renamed EventSource to match the convention in the runtime Microsoft.AspNetCore.Hosting

Fixes #9486

How it looks:

image

cc @shirhatti @DamianEdwards

- Added Request Rate counter (RPS), Total Requests counter, current requests and failed requests.
- Counters do nothing until enabled
- Added tests for counters and improved tests to use unique event source names
- Renamed EventSource to match the convention in the runtime Microsoft.AspNetCore.Hosting
Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

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

Clean


protected override void OnEventCommand(EventCommandEventArgs command)
{
if (command.Command == EventCommand.Enable)
Copy link
Member

Choose a reason for hiding this comment

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

What about Disable?

Copy link
Contributor

Choose a reason for hiding this comment

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

From below this line:

// They aren't disabled afterwards...

Do you have more context on why?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's racy to disable counters and dispose and re-create them, that would need to be synchronized. The other way to turn it off is to stop pumping the data (that can be done via a different set of arguments), which turns the timer off so allocating the counter itself is fine.

@analogrelay analogrelay added this to the 3.0.0-preview7 milestone Jun 5, 2019
Copy link
Contributor

@analogrelay analogrelay left a comment

Choose a reason for hiding this comment

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

Swanky!

@@ -136,10 +136,19 @@ public void RequestEnd(HttpContext httpContext, Exception exception, HostingAppl
StopActivity(httpContext, activity, context.HasDiagnosticListener);
}

if (context.EventLogEnabled && exception != null)
if (context.EventLogEnabled)
Copy link
Contributor

Choose a reason for hiding this comment

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

First time I'm seeing this code, so I know this is already "how it's been" but EventLog != EventSource so this name struck me as odd. I backtracked to where it's initialized and confirmed it was right but the naming seems off.

It's internal so a rename would be safe if you want to be a little more consistent... 🤷‍♂

Copy link
Member Author

Choose a reason for hiding this comment

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

It's public unfortunately. That's why I never renamed it. Can do it later, I think we should make all this stuff internal anyways.

if (exception != null)
{
// Non-inline
HostingEventSource.Log.UnhandledException();
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 reason we don't put exception details in the message?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. This isn't new code
  2. You can't pass the exception itself (that isn't supported in EventSource writes), you could pass the text though.

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. This isn't new code

Yes, I am aware.


protected override void OnEventCommand(EventCommandEventArgs command)
{
if (command.Command == EventCommand.Enable)
Copy link
Contributor

Choose a reason for hiding this comment

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

From below this line:

// They aren't disabled afterwards...

Do you have more context on why?

@@ -35,13 +55,16 @@ public void HostStop()
[Event(3, Level = EventLevel.Informational)]
public void RequestStart(string method, string path)
{
Interlocked.Increment(ref _totalRequests);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is cool stuff. Is it worth investigating using ThreadLocal<int> and summing the .Values in the counter delegate? That would save a bit of time in the hot path by not locking the processor cores. Though I'm probably optimizing a bit prematurely ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea I had a version with that though I'll do it after we measure this which I haven't since it involves turning on logging/eventsource which has other overhead. We also still need to interlocked.increment/decrement current requests which also made me go meh.

Copy link
Contributor

Choose a reason for hiding this comment

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

Measure first is best

@@ -216,5 +263,36 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
}
}
}

private class CounterListener : EventListener
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be useful for testing all counters. We'll have to remember this when adding other counters and promote this to src/Shared (or you could just do it now...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. I have a thread with corefx about how to test these things. As I add more counters I'll move it to shared.

@davidfowl davidfowl merged commit bba6b44 into master Jun 5, 2019
@ghost ghost deleted the davidfowl/simpler-counters branch June 5, 2019 21:06
@amcasey amcasey added the area-hosting Includes Hosting label Jun 1, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-hosting Includes Hosting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create an RPS EventCounter
5 participants