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

performance improvements: squash messages, and NIO #7

Merged

Conversation

michaelsembwever
Copy link

 - fit as many messages (that are in the queue) into the MTU as possible.
 - convert to NIO.

In addition to any NIO improvements,
this will offer a performance improvement when the incoming message rate per the time it takes to call blockingSend() goes above one.

try {
String message = queue.poll(1, TimeUnit.SECONDS);
if(null != message) {
byte[] data = message.getBytes();

Choose a reason for hiding this comment

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

You should always specify the encoding. I think that it would be best to assume that this encoding is UTF-8

Copy link
Author

Choose a reason for hiding this comment

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

I can do that. Although it's strictly not part of this pull request (the original code also uses getBytes()), and i'd rather keep it as a separate commit and pull request (for the sake of bisecting).

Verdict?

Choose a reason for hiding this comment

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

I'm fine with it not being part of this.

@michaelsembwever
Copy link
Author

DONE: i've got a test coming…
DONE: i'm also thinking about replacing the LinkedBlockingQueue with a lmax disruptor.

executor.shutdown();
executor.awaitTermination(30, TimeUnit.SECONDS);
executor.awaitTermination(1, TimeUnit.SECONDS);

Choose a reason for hiding this comment

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

Is this change actually needed. I think I would prefer that it stays at 30 seconds.

Copy link
Author

Choose a reason for hiding this comment

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

Not really (the change isn't needed).
But the test seems to wait the full period. (maybe because the threads are set to daemon?)

In one second the test (on my machine) pushes through 10k statsd messages.
Given that, and the point that udp packets are not crucial, are we worried about consistency of the messages here?

Copy link
Author

Choose a reason for hiding this comment

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

i'd forgotten to call executor.shutdown() in the test.
fixing that fixed this. it's returned to 30 seconds now.

@camerondavison
Copy link

I am not sure that I understand enough about the failure cases of Disruptor to add it as a dependency. I like the NIO and squashing though. Can we maybe make the disruptor stuff a different branch, and change this PULL into only squashing and NIO?

@michaelsembwever
Copy link
Author

sure thing.

i've taken the lmax-disruptor implementation out of this branch. and will put it into a new pull request.
(for now the lmax disruptor implementation lies in finn-no@5df54d1 )

     - fit as many messages (that are in the queue) into the MTU as possible
     - convert to NIO

In addition to any NIO improvements,
     this will offer a performance improvement when the incoming message rate per the time it takes to call blockingSend() goes above one.

Add NonBlockingStatsDClientPerfTest to ensure no messages are lost in a concurrent environment.
@camerondavison
Copy link

okay this LGTM I will work on getting it pulled in.

blockingSend();
}
if(sendBuffer.position() > 0) {
sendBuffer.put( (byte) '\n');

Choose a reason for hiding this comment

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

Just for future reference https://github.com/DataDog/dd-agent/blob/de14dac5f1af5a444cec46cff047ca70fa6e294f/aggregator.py#L398 shows that dogstatsd supports '\n' separated metrics as well.

camerondavison added a commit that referenced this pull request Apr 9, 2014
performance improvements: squash messages, and NIO
@camerondavison camerondavison merged commit 3c94364 into indeedeng:master Apr 9, 2014
@michaelsembwever michaelsembwever deleted the feature/automatic-multi-metrics branch April 30, 2014 10:39
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.

2 participants