-
Notifications
You must be signed in to change notification settings - Fork 137
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 Sender.queue_size limits #230
Conversation
Small feedback @djmitche
You have been with the byte size and not the messages count, I would probably have done the same, but it may make sense to validate it has been done the same way in other implementations and to discuss about it with the team otherwise. |
datadog-go doesn't log anything, but does count it in |
This is based on the Go client, which uses
So that should be easy to emulate with the ruby version. |
Also, somehow I convinced myself that Ruby doesn't have a GIL. It does. So access to an integer is automatically serialized by that GIL. |
And remove use of a Mutex. This is a "soft" limit, so just examining the queue length is sufficient.
I've asked for some advice on how best to test this. I don't think Waiter is a good idea. |
Ivo has suggested using dependency-injection to inject a fake Queue implementation here, mocking out the background thread's behavior. I had tried mocking Thread, without success, so I'll try Queue instead. |
ce4faef
to
bab630f
Compare
bab630f
to
f96c913
Compare
Supporting those ancient Ruby versions is a real drag. |
Hm, it seems webrick might have dropped support for ruby-2.0?? |
f96c913
to
48f99e8
Compare
I think the Ruby-2.0 failures are unrelated to this, so maybe we can handle that with #229 ? |
Merged from main -- looks like I changed all the same places as @abicky :) |
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.
Nice!
This adds a queue_size limit to the Sender class, with messages beyond that limit dropped. We support Ruby-2.1.0, which doesn't have a SizedQueue that supports "attempted" sends (it always blocks the sender if the queue is full), so we need to limit the queue size out-of-band. Also, we want to limit the size based on bytes, not message count. Because the
@message_queue_bytesize
is accessed concurrently in a read-modify-write pattern, it requires a mutex.Things I'd like feedback on:
This isn't quite done yet. Still to do: