-
Notifications
You must be signed in to change notification settings - Fork 780
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
Reuse dictionaries in ActivityExtensions
, MetricItemExtensions
and OtlpLogExporter
#5727
Conversation
|
ef9dbdf
to
d9c05d1
Compare
d9c05d1
to
f989e01
Compare
@paulomorgado Thanks!. |
Resource = processResource, | ||
}; | ||
request.ResourceSpans.Add(resourceSpans); | ||
var spansByLibrary = Interlocked.Exchange(ref spansByLibraryCached, null) ?? new Dictionary<string, ScopeSpans>(); |
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.
@paulomorgado - We could define this field as [ThreadStatic]
[ThreadStatic]
private static Dictionary<string, ScopeSpans>? spansByLibrary;
....
....
...
internal static void AddBatch(..)
{
spansByLibrary ??= new Dictionary<string, ScopeSpans>();
..
..
..
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.
@paulomorgado - We could define this field as
[ThreadStatic]
[ThreadStatic] private static Dictionary<string, ScopeSpans>? spansByLibrary; .... .... ... internal static void AddBatch(..) { spansByLibrary ??= new Dictionary<string, ScopeSpans>(); .. .. ..
How many concurrent threads do you expect to be concurrently requesting these dictionaries?
With [ThreadStatic]
, the dictionaries will be created per-thread, depending on the thread that started this, which might not always be the same one, and might leak.
[ThreadStatic]
is for when you are sure that you'll need it for every thread running the code.
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.
There is a dedicated Exporter thread and that should be the only one invoking this code path.
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.
We can benchmark it, but accessing thread local storage might be worse than interlocked operations.
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.
How many concurrent threads do you expect to be concurrently requesting these dictionaries?
it depends - With single instance of exporter configured as BatchExportProcessor. There would be only one thread executing this. With multiple instances, there could be multiple threads executing this.
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.
we could do that. That would require some refactoring and I would not recommend that effort as the implementation will change anyways with #5450.
is the concern that #5450 will change OTLP Exporter internals, so its better to not make any changes there for now?
If that is the case, then lets close this PR itself as we should not be proceeding with any approaches being discussed, until after the rewriting is complete.
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.
There is a dedicated Exporter thread and that should be the only one invoking this code path.
Isn't this code path called for SimpleExportProcessor
as well?
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.
is the concern that #5450 will change OTLP Exporter internals, so its better to not make any changes there for now
Yes
If that is the case, then lets close this PR itself as we should not be proceeding with any approaches being discussed, until after the rewriting is complete
Agree. I was open to do the small change until #5450 completes. Already have #5731 now, we can close this.
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.
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.
Yup. I was mainly concerned with HashMap
being static
. The issue would mainly be with multiple instances of exporter:
- Multiple SimpleExportProcessor instances
- Multiple BatchExportProcessor instances
- Or a combination of both
@vishweshbankwar I just noticed you already covered this concern in one of your comments above.
I've collected the benchmark results. They're a lot. Are you looking for any particular ones? |
Could you share, so it is easy to tell how much we are improving? (also ensures we don't accidentally regress!) There are few OTLPExporter specific benchmarks: |
@paulomorgado - Thank you for your time, appreciate the help. As discussed #5727 (comment), I am closing this PR as the implementation is soon going to change. |
Fixes #4943
I have to admit I don't know enough of the usage to know if this is really the best option, but it will reduce the number of allocations and dictionary internal growths.
Changes
Tries to use a single instance of a dictionary for
ActivityExtensions
,MetricItemExtensions
andOtlpLogExporter
.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes