-
Notifications
You must be signed in to change notification settings - Fork 306
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
Add blocking socket mode and background sender #787
Conversation
b0ff7cd
to
8cf0201
Compare
settimeout(0) is equivalent to setblocking(0), so need only one call. Neither UDP or nor unix datagram sockets block on connect, so handling timeout in get_socket is not necessary.
Align reported metrics with the go client.
eefd108
to
a7f6b62
Compare
a7f6b62
to
1ac3a88
Compare
Python2.7 does not allow other positional parameters after *expression.
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.
Made a few polishing comments but that's a neat implementation.
self._xmit_packet(packet + '\n', False) | ||
if self._queue is not None: | ||
try: | ||
self._queue.put(packet + '\n', self._queue_blocking, self._queue_timeout) |
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.
Nit: about the packet + '\n'
, it might be worth doing it directly at the only direct call to _send_to_server
in the flush method:
self._send_to_server("\n".join(self._buffer) + '\n')
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.
_send_to_server
is also used in a bunch of places indirectly via the _send
alias when buffering is disabled.
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.
That's right, but it doesn't stop us from having the call to _send_to_server
in the flush method to add the \n
as shown above. No strong opinion here, feel free to discard 👍
self._xmit_packet_with_telemetry(self._queue.get()) | ||
self._queue.task_done() | ||
|
||
def wait_for_pending(self): |
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.
Should we consider documenting the new need (when using the threaded sender) to use this method to make sure everything's flushed properly and no buffered metrics are lost on shutdown?
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.
Good idea, done
Co-authored-by: Rémy Mathieu <[email protected]>
Co-authored-by: Rémy Mathieu <[email protected]>
5334be9
to
d2f4a60
Compare
d2f4a60
to
5fdad16
Compare
What does this PR do?
Add options to improve dogstatsd packet deliverability.
Description of the Change
Allow dogstatsd socket to be used in a blocking mode with a timeout. This improves our chances to send the packet if the socket queue is full (e.g. after a burst in packets).
Add a background thread to handle the writes, with a queue to act as a buffer.
Together, this allows users to reduce dropped packets to zero while maintaining low latency for the user application, at the cost of higher cpu and memory usage.
Alternate Designs
Possible Drawbacks
Verification Process
Additional Notes
Release Notes
Review checklist (to be filled by reviewers)
changelog/
label attached. If applicable it should have thebackward-incompatible
label attached.do-not-merge/
label attached.kind/
andseverity/
labels attached at least.