-
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
Optimized sending #44
Conversation
Thank you very much for your contribution @AMekss ! It's a huge performance improvement! I wanted to compare them both more precisely, so I used this gem, and slightly modified your script there. Without dogstatsd: Warming up --------------------------------------
connect_and_send 1.000 i/100ms
just_send 8.000 i/100ms
Calculating -------------------------------------
connect_and_send 4.276 (±23.4%) i/s - 21.000 in 5.043441s
just_send 85.699 (±12.8%) i/s - 424.000 in 5.059091s
Comparison:
just_send: 85.7 i/s
connect_and_send: 4.3 i/s - 20.04x slower With dogstatsd: Warming up --------------------------------------
connect_and_send 1.000 i/100ms
just_send 6.000 i/100ms
Calculating -------------------------------------
connect_and_send 2.654 (± 0.0%) i/s - 14.000 in 5.321916s
just_send 57.761 (±10.4%) i/s - 288.000 in 5.056199s
Comparison:
just_send: 57.8 i/s
connect_and_send: 2.7 i/s - 21.77x slower I still want to check a few potential edge cases before merging (results are too good not to have a drawback). |
Sure, its always better be safe and don't rush. Let me know if I can help |
dfee529
to
145e02b
Compare
I've noticed that I forgot to remove |
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.
Hello again @AMekss, sorry for the delay!
I have one remark about it, please let me know what you think!
lib/datadog/statsd.rb
Outdated
socket = UDPSocket.new | ||
socket.connect(host, port) | ||
socket | ||
rescue => boom |
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.
connect
shouldn't fail unless the host is unresolvable, and in this case we're probably fine with raising the exception (since it will be unabled to send anything anyway).
I'm not sure what would be the status of the socket if connect
fails, most likely it would require using send(message, 0, host, port)
, and thus would fail afterwards. So I think failing there is better than failing after.
Could you remove the error handling? (unless you think it's needed?)
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.
My rationale for that rescue
was to make a transparent change which wouldn't affect any of the current behavior, so this could be shipped as a patch version update.
Currently there is no way that Datadog::Statsd.new
would raise an exception. While if I would omit this rescue this won't be true any more. So I don't mind to remove this rescue since this PR is aimed for the next minor version upgrade and such change is acceptable.
145e02b
to
578a029
Compare
@degemer updated! |
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.
Thanks a lot @AMekss!
Code looks good, it's ready to be merged.
You're right, this change means that an exception can be raised when initializing the object whereas before no exception could be raised. I think it's very unlikely to affect anyone, but it should still be in 3.0, not 2.3.
I'll check in the next two weeks if we have any other potentially breaking changes we'd like to make for a 3.0 version (we'd like to avoid releasing major too frequently), if not this will be the only change.
Ok, thanks, looking forward for the release |
Recently I came across why it's faster:
|
Hey @AMekss , Thanks for adding this PR to this project. For fun, I thought I'd show you our graph after shipping this. |
Hey there,
First of all thank you for your effort in maintaining this gem.
We're using this gem in production and observed some weird performance issues when statsd wasn't available during the maintenance. We're still investigating what exactly happened. Anyway I played a bit with UDPSockets and did some benchmarks using this script
Here is what it looked like:
When statsd was available
When statsd was down
This PR implements performance improvements based on my findings (also I fixed deprecation warnings for the spec run)