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.
remeh
left a comment
There was a problem hiding this comment.
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.
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.
_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.
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.
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?
Co-authored-by: Rémy Mathieu <remy.mathieu@datadoghq.com>
Co-authored-by: Rémy Mathieu <remy.mathieu@datadoghq.com>
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-incompatiblelabel attached.do-not-merge/label attached.kind/andseverity/labels attached at least.