Skip to content
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

Set buffer size in bytes #86

Merged
merged 1 commit into from
Jun 7, 2018
Merged

Conversation

grosser
Copy link
Contributor

@grosser grosser commented May 24, 2018

Default buffer size matches dd-agent read buffer

@Antti @jonmoter

as replacement for #82 and #65

@grosser
Copy link
Contributor Author

grosser commented May 24, 2018

@gmmeyer @masci @degemer

@@ -93,16 +93,19 @@ def self.VERSION
# @param [Integer] port your statsd port
# @option opts [String] :namespace set a namespace to be prepended to every metric name
# @option opts [Array<String>] :tags tags to be added to every metric
# @option opts [Integer] :max_buffer_size max messages to buffer
# @option opts [Integer] :max_buffer_bytes max messages to buffer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this option was never released, so it should be fine to change it
users that used the additional argument before will get a "ArgumentError" and then have to read the docs on how to upgrade

@buffer = Array.new
return if @buffer_bytes.zero?
send_to_socket(@buffer)
@buffer = String.new
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not using "" since that breaks the tests on ruby 2.3+ where we use frozen strings

@gmmeyer
Copy link
Contributor

gmmeyer commented May 31, 2018

Hey @grosser I'll merge this after you rebase, this looks pretty good to me. Do you mind if I close #82 since this replaces it?

@grosser
Copy link
Contributor Author

grosser commented May 31, 2018

rebased!
can close #82 and #65

@grosser
Copy link
Contributor Author

grosser commented May 31, 2018

after that the only missing things is thread-safety, that can be another minor release or just added to 4.0

@grosser
Copy link
Contributor Author

grosser commented May 31, 2018

thread safe batching will need some rework to not be a big mess ... so prefer getting 4.0 out ...
... afaik multi-threaded udp sending already works fine ... we used that for a few years without issues

@masci masci added this to the 4.0.0 milestone Jun 5, 2018
@@ -432,17 +434,28 @@ def send_stats(stat, delta, type, opts=EMPTY_OPTIONS)

def send_stat(message)
if @batch_nesting_depth > 0
message_bytes = message.bytesize
Copy link

@humzashah humzashah Jun 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this leaves open the (unlikely) possibility of message_bytes being greater than @max_buffer_size.

What do you think about raising an error if that ever happens?

if message_bytes >= @max_buffer_bytes
  raise ArgumentError.new("Expected message bytesize to be under #{@max_buffer_bytes} but was #{message_size}")
end

@buffer = Array.new
@max_buffer_size = opts[:max_buffer_size] || 50
# batching
@max_buffer_bytes = opts[:max_buffer_bytes] || 8192

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on warning somebody when they set max_buffer_bytes greater than this default?

@@ -432,17 +434,28 @@ def send_stats(stat, delta, type, opts=EMPTY_OPTIONS)

def send_stat(message)
if @batch_nesting_depth > 0
message_bytes = message.bytesize
unless @buffer_bytes.zero?
Copy link

@humzashah humzashah Jun 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO if @buffer_bytes != 0 would be much clearer. Admittedly however, this is subjective.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, updated

@grosser
Copy link
Contributor Author

grosser commented Jun 5, 2018 via email

@grosser
Copy link
Contributor Author

grosser commented Jun 5, 2018 via email

@grosser grosser force-pushed the grosser/bytes branch 2 times, most recently from 0579178 to c534ec7 Compare June 7, 2018 18:11
@grosser
Copy link
Contributor Author

grosser commented Jun 7, 2018

needs #93 to be merged first

Default buffer size matches dd-agent read buffer
@grosser
Copy link
Contributor Author

grosser commented Jun 7, 2018

@gmmeyer rebased and green 🎉

@gmmeyer
Copy link
Contributor

gmmeyer commented Jun 7, 2018

I agree with your assessment @grosser that the raise wouldn't be necessary for this, that is configurable on the agent size

@gmmeyer gmmeyer merged commit aeea888 into DataDog:master Jun 7, 2018
@grosser grosser deleted the grosser/bytes branch June 7, 2018 20:20
@grosser
Copy link
Contributor Author

grosser commented Jun 7, 2018

maybe good enough for a 4.0 release ...
thread-safety can wait :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants