-
Notifications
You must be signed in to change notification settings - Fork 100
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
Do not create a new emitter when a shared emitter is provided #310
base: master
Are you sure you want to change the base?
Conversation
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.
Just a quick comment, and of course would need to fix the CI. Thanks!
this(null); | ||
} | ||
|
||
public AWSXRayRecorder(Emitter sharedEmitter) { |
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.
Not too excited about increasing our API surface for this, maybe we can make the new constructor package private?
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.
Sure.
@hden There's still some syntax errors it seems |
349d829
to
0260158
Compare
@willarmiros Oops. |
@willarmiros I've fixed the type annotations. Please take a look and tell me what you think. |
Codecov Report
@@ Coverage Diff @@
## master #310 +/- ##
============================================
- Coverage 58.92% 58.89% -0.03%
Complexity 1206 1206
============================================
Files 131 131
Lines 5066 5068 +2
Branches 593 593
============================================
Hits 2985 2985
- Misses 1806 1808 +2
Partials 275 275
Continue to review full report at Codecov.
|
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.
Code lgtm, though one thing I'm concerned about in general is thread safety. Having several recorders use the same emitter means this path could be executed concurrently for the same socket:
Lines 111 to 124 in 7e93511
private boolean sendData(byte[] data, Entity entity) { | |
try { | |
DatagramPacket packet = new DatagramPacket(sendBuffer, DAEMON_BUF_RECEIVE_SIZE, config.getAddressForEmitter()); | |
packet.setData(data); | |
logger.debug("Sending UDP packet."); | |
daemonSocket.send(packet); | |
} catch (Exception e) { | |
String segmentName = Optional.ofNullable(entity.getParent()).map(this::nameAndId).orElse("[no parent segment]"); | |
logger.error("Exception while sending segment over UDP for entity " + nameAndId(entity) + " on segment " | |
+ segmentName, e); | |
return false; | |
} | |
return true; | |
} |
Is there any possibility of interference, overload, or data corruption for all that traffic going to a socket at once? Also if I may ask, what is your use case that requires several recorders which share an emitter? Generally speaking the recorder is meant to be a singleton, with only one per application.
We've been testing with thread safety as well, so far we have not seen any evidence of interference, overload, or data corruption. Our use-case is exactly thread safety. We have been handling concurrent workload on a thread-pool (in Clojure). We started with a singleton, but it's quite unrealistic to keep track with segment context since context switching is everywhere. So we've been trying with the idea that we could create one recorder per job (a request, to be precise) and pass the recorder along the job context instead. cc @popoppo What do you think? |
Issue #, if available:
Currently AWSXRayRecorder's constructor will create a new emitter even when a shared emitter is specified in the AWSXRayRecorderBuilder. This creates an unnecessary Emitter / Socket for each new AWSXRayRecorder and leads to fire descriptor exhaustion if enough Emitter is created.
Description of changes:
Change AWSXRayRecorder's constructor so that it does not create a new emitter when a shared emitter is provided.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.