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
EventHub EventSource remove allocations and boxing #26989
Conversation
Thank you for your contribution @danielmarbach! We will review the pull request and get back to you soon. |
@jsquire what do you think about this one? |
2dc7c7b
to
ab00097
Compare
Interesting. If I'm following, we're overloading to explicitly handle cases that would normally trigger this overload to avoid the Assuming that I've got that correct, I'm good with the approach. We've got other libraries, like Azure.Core allowing unsafe blocks, so there's precedent. I know that Event Hubs, specifically, commonly uses this 4 or 5 string set... but I wonder if we should start to add these kinds of overloads to AzureEventSource in core so that other libraries can use them - even just by coincidence. My rationale is that if we start to add these as they come up for individual needs, we'd be building out a reasonable common set. Do you think that there's benefit to centralizing, or do you feel that we'd start to see too much bloat if we add all the special cases to the base? Regardless, the use is extensive enough in Event Hubs that there's definitely benefit to something like this. |
That is correct
I would need to know how many other event sources are actually using 4 and 5 string-based overloads. If there are many of those, it might warrant to centralize it. Doing that research is quite a bit of work for me, and I'm uncertain whether I can pull this off, honestly. I would definitely not try to centralize the other permutations of overloads, since it would bloat the base class with highly specific use cases. |
Fair enough; I can't answer that either, and if we're trying to avoid bloating the general class, its probably better to just move forward with this as a special case locally. |
@jsquire I pushed a few examples how it would look like. Let me know if you want me to proceed with this. It will probably take a while until I got all the methods |
Wow. I had mistakenly assumed that the scope was going to be a small handful of overrides. This seems like a non-trivial amount of work; if you're willing to keep going, please feel free. If you'd rather not, I want to be respectful of your kindness. I can add this to the backlog and schedule time to take over, if you'd prefer not to invest this level of time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have found a good balance of generic methods covering the majority of the array allocations and a few specialized methods where necessary.
sdk/eventhub/Azure.Messaging.EventHubs/src/Diagnostics/EventHubsEventSource.cs
Outdated
Show resolved
Hide resolved
sdk/eventhub/Azure.Messaging.EventHubs/src/Diagnostics/EventHubsEventSource.cs
Outdated
Show resolved
Hide resolved
sdk/eventhub/Azure.Messaging.EventHubs/src/Diagnostics/EventHubsEventSource.cs
Outdated
Show resolved
Hide resolved
sdk/eventhub/Azure.Messaging.EventHubs/src/Diagnostics/EventHubsEventSource.cs
Outdated
Show resolved
Hide resolved
This probably needs some good eyeballing to verify I haven't mixed up the parameter order, the event id or the data type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eyeball check looks good on the surface. I don't see anything obviously mismatched or count issues.
sdk/eventhub/Azure.Messaging.EventHubs/src/Diagnostics/EventHubsEventSource.cs
Outdated
Show resolved
Hide resolved
sdk/eventhub/Azure.Messaging.EventHubs/src/Diagnostics/EventHubsEventSource.cs
Outdated
Show resolved
Hide resolved
sdk/eventhub/Azure.Messaging.EventHubs/src/Diagnostics/EventHubsEventSource.cs
Outdated
Show resolved
Hide resolved
Note to self:
|
@danielmarbach: I left myself a bunch of notes for extending this. Once we think this is in a good stable spot, I'll probably grab a local copy of the changes and implement the first three bullets. That'll force me to give the parameter an event id matching a deeper look. We can then do a merge of this followed by my add-ons. Thoughts? |
/azp run net - eventhub - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
Works for me. The branch is open for contributions. That being said I'm also happy to help out. Right now though I'm a bit knocked out due to a sickness and don't have energy to do much. If you start doing something locally just give me a quick heads up here (I'll do the same) so that we won't duplicate effort. |
@jsquire have a look. I pushed some things on the TODO list. I decided to copy the methods for now. Moving them to an extension method is not possible because we need access to the protected I've also started outsourcing the event IDs. I did only five of them to see whether you like the approach or not. Once we have it confirmed, I can do a few more 🐒 style |
FYI ServiceBus has the constants in a region https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/src/Diagnostics/ServiceBusEventSource.cs#L47 |
The other alternative would be that the introduced |
sdk/eventhub/Azure.Messaging.EventHubs.Processor/src/Diagnostics/BlobEventStoreEventSource.cs
Show resolved
Hide resolved
...nthub/Azure.Messaging.EventHubs.Processor/src/Diagnostics/EventProcessorClientEventSource.cs
Outdated
Show resolved
Hide resolved
sdk/eventhub/Azure.Messaging.EventHubs/src/Diagnostics/EventHubsEventSourceEventIds.cs
Outdated
Show resolved
Hide resolved
Oooh... I didn't think of that. I LOVE that idea. |
dfe57ef
to
acae703
Compare
@jsquire Done. I think this is ready |
Awesome. I'm going to pull down the change set locally and run some log captures via stress test to validate. |
sdk/eventhub/Azure.Messaging.EventHubs/src/Diagnostics/EventHubsEventSource.cs
Show resolved
Hide resolved
sdk/eventhub/Azure.Messaging.EventHubs.Processor/src/Diagnostics/BlobEventStoreEventSource.cs
Show resolved
Hide resolved
@danielmarbach: I pushed a batch of minor formatting nits since you had previously mentioned that you wouldn't be offended if I did so. The only thing of substance that I did was to add the inlining hint to the two |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Offline validation looks good. Some weird |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overnight tests were successful. I think we're good to go.
@danielmarbach: Are you ready for me to merge or are there changes that you'd like to make?
This PR adds two additional overloads of
WriteEvent
that take four or five strings to make sure the param overload is not used and hence doesn't heap allocate anymore.Very similar to for example
https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.cs#L380
I'm not using a SetEvent method since I felt this might be overkill here
This requires enabling unsafe on the project. If you are OK with this approach, I will finish the few remaining methods that also box some value types.
FYI there are over 60 usages of WriteEvent that use the param based overload and/or box value types.