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

Refactor exporter - step 6 #1094

Merged
merged 15 commits into from
Aug 19, 2020
Merged

Refactor exporter - step 6 #1094

merged 15 commits into from
Aug 19, 2020

Conversation

reyang
Copy link
Member

@reyang reyang commented Aug 18, 2020

This is a follow up PR of #1078.

Changes

  • Implemented BatchExportActivityProcessor.
  • Updated the tutorial to reflect the changes.
  • Dispose/Shutdown issue will be addressed in a separate PR. Ref: Consistent Dispose pattern #1024.

For significant contributions please make sure you have completed the following items:

  • Design discussion issue #
  • Changes in public API reviewed

@reyang reyang requested a review from a team August 18, 2020 19:20
@codecov
Copy link

codecov bot commented Aug 18, 2020

Codecov Report

Merging #1094 into master will decrease coverage by 0.57%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1094      +/-   ##
==========================================
- Coverage   75.04%   74.46%   -0.58%     
==========================================
  Files         223      223              
  Lines        6295     6344      +49     
==========================================
  Hits         4724     4724              
- Misses       1571     1620      +49     
Impacted Files Coverage Δ
...penTelemetry/Trace/BatchExportActivityProcessor.cs 0.00% <0.00%> (ø)
...enTelemetry/Trace/SimpleExportActivityProcessor.cs 0.00% <ø> (ø)

@@ -29,9 +29,13 @@ public class BatchExportActivityProcessor : ActivityProcessor
{
private readonly ActivityExporterSync exporter;
private readonly CircularBuffer<Activity> queue;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: not from your change but why not name the field circularBuffer? It is not a queue...

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, renamed.

Copy link
Member Author

@reyang reyang Aug 19, 2020

Choose a reason for hiding this comment

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

After the change it seems we're still quite messy with names, as the spec is asking for maxQueueSize, so we have something weird like new CircularBuffer<Activity>(maxQueueSize).

private readonly int maxExportBatchSize;
private readonly Thread exporterThread;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not a Task?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think having an explicit thread gives a lot of benefit:

  1. The exporter thread runaway time would give idea on how much CPU cycles were used by exporting job.
  2. While debugging a live process or a dump, it is easy to see whether the exporting job got stuck or not.
  3. It avoids the accidental context leakage of SuppressInstrumentation.

src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs Outdated Show resolved Hide resolved
/// timed out. Using a 32bit signed integer to specify the time
/// interval in milliseconds.
/// </summary>
/// <param name="timeoutMillis">
Copy link
Contributor

Choose a reason for hiding this comment

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

Q.: why the preference for an int instead of a TimeSpan? I see TimeSpan as more user friendly but opinions differ :)

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. It aligns better with the spec.
  2. It allows default parameter to be specified in the signature directly, which results in simpler code.
  3. Debugging a crash dump would be simpler.

None of the above gives any significant benefit though.

src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs Outdated Show resolved Hide resolved
private readonly int maxExportBatchSize;
private readonly Thread exporterThread;
private readonly ManualResetEvent exportTrigger = new ManualResetEvent(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that ManualResetEventSlim is a better option here. Any specific reason to not use it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see the slim version giving benefit other than burning CPU cycles.
Most of these operations will wait for I/O operation which takes longer time so the spin will upgrade to a real event.

Comment on lines 309 to 310
this.dataExportedNotification.Set();
this.dataExportedNotification.Reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this guaranteed to wake up the one waiting?

Comment on lines +311 to +312
this.dataExportedNotification.Set();
this.dataExportedNotification.Reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this guaranteed to wake-up one waiting for the signal?

processor.ForceFlush();
processor.ForceFlush();
processor.ForceFlush();
processor.ForceFlush();
Copy link
Member

Choose a reason for hiding this comment

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

There is a 🚽 joke to be made here, but I don't want to be a drain.

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

@cijothomas cijothomas merged commit bf694a0 into master Aug 19, 2020
@cijothomas cijothomas deleted the reyang/exporter6 branch August 19, 2020 03:58
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.

4 participants