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

Bugfix for uninterrupted receive loop #18

Merged
merged 3 commits into from
Apr 18, 2016

Conversation

breml
Copy link

@breml breml commented Dec 2, 2015

Replace the uninterrupted receive loop (non-blocking) with
a blocking loop with a default timeout of 1000ms.

Restores compatibility with zeromq output plugin for util/zeromq.rb as well, if logstash-plugins/logstash-output-zeromq#13 is merged.

Closes #17
May also be related to #5

Lucas Bremgartner added 2 commits December 2, 2015 13:59
Adjust implementation of util/zeromq.rb to zeromq output.

logstash-plugins/logstash-output-zeromq#13
Replace the uninterrupted receive loop (non-blocking) with
a blocking loop with a default timeout of 1000ms.
@elasticsearch-release
Copy link

Jenkins standing by to test this. If you aren't a maintainer, you can ignore this comment. Someone with commit access, please review this and clear it for Jenkins to run; then say 'jenkins, test it'.

@@ -20,8 +20,8 @@ def setup(socket, address)
@logger.info("0mq: #{server? ? 'connected' : 'bound'}", :address => address)
end

def error_check(rc, doing)
unless ZMQ::Util.resultcode_ok?(rc)
def error_check(rc, doing, eagain_not_error = false)
Copy link
Author

Choose a reason for hiding this comment

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

Because function signature of error_check is changed and util/zeromq.rb is present in zeromq input and output plugin, this PR has a dependecy to logstash-plugins/logstash-output-zeromq/pull/13.

@breml
Copy link
Author

breml commented Dec 18, 2015

Could please someone give me some feedback?

@erikthorselius
Copy link

This would be really good if any maintainer could have a look on this.

@nukemberg
Copy link
Collaborator

OK, had a look. The patch looks straight forward. I do need to run some tests so it will take a few days to close this. Thanks!

@erikthorselius
Copy link

I'm really interested in this fix. I'm having two zeromq inputs taking up half of the server cpu capacity. So if there is any thing I can do to help, feel free to delegate.

@breml
Copy link
Author

breml commented Jan 6, 2016

@erikthorselius Have you tried this PR in your setup? Did it solve your problem?

@erikthorselius
Copy link

Looks good! I'm new to logstash but here is how I tested. My server is running coreos so I built a docker container.

My dockerfile:

FROM logstash
COPY logstash-input-zeromq-2.0.2.gem /tmp/
RUN /opt/logstash/bin/plugin uninstall logstash-input-zeromq
RUN /opt/logstash/bin/plugin install /tmp/logstash-input-zeromq-2.0.2.gem
CMD ["logstash", "agent"]
gem build logstash-input-zeromq.gemspec
docker build -t logstash-with-zeromq-patch .
docker save -o logstash-with-zeromq-patch logstash-with-zeromq-patch
scp logstash-with-zeromq-patch server:

and on my server

docker load -i logstash-with-zeromq-patch
docker run --rm --name logstash -p 2120:2120 -v /home/logstash/conf:/data logstash-with-zeromq-patch logstash -f /data/logstash.conf

Same process is now down to 1.8% instead of 200%

input {
  zeromq {
    topology => "pushpull"
    tags => ["pushpull"]
  }
  zeromq {
    mode => "client"
    address => ["tcp://192.168.1.3:7555"]
    topology => "pubsub"
    topic => "sensor"
    tags => ["pubsub"]
  }
}
filter {
  date {
    match => ["unix_timestamp", "UNIX"]
  }
}
output {
  elasticsearch {
    hosts => ["192.168.1.3:9200"]
  }
}

#
# defaults to: `sockopt => ["ZMQ::RCVTIMEO", "1000"]`, which has the effect of "interrupting"
# the recv operation at least once every second to allow for properly shutdown handling.
config :sockopt, :validate => :hash, :default => [ "ZMQ::RCVTIMEO", "1000" ]
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be :default => { "ZMQ::RCVTIMEO" => "1000" } right?

Copy link
Author

Choose a reason for hiding this comment

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

I agree, it should be a hash. I just followed the existing example, which provides an array with an even count of elements, which gets converted to a hash in https://github.com/elastic/logstash/blob/master/logstash-core/lib/logstash/config/mixin.rb#L381 (lines 381 - 398). I update the PR, including the existing comment/example.

@jordansissel
Copy link
Contributor

Given @erikthorselius's success report, I'm OK merging this. Code LGTM except for my one comment about the hash default value (should use hash syntax, not array).

@breml Can you address my comment? I'm happy to merge once done. :)

@jordansissel jordansissel self-assigned this Jan 6, 2016
@erikthorselius
Copy link

It fixed my cpu problem but it seems that I don't receive any messages.
screenshot 2016-01-07 08 34 39
I'm at work right now but I can try to debug when I'm home.

@breml
Copy link
Author

breml commented Jan 7, 2016

@erikthorselius Please see my comment regarding lib/logstash/util/zeromq.rb. This file was shared in Logstash prior to version 1.5. Now both plugins, logstash-input-zeromq and logstash-output-zeromq do provide this file. Therefore it is important to update this file in both plugins at the same time because otherwise it could happen that the logstash-input-zeromq plugin is using the wrong version of this file. (see my reference to logstash-plugins/logstash-output-zeromq#13 above)

@jordansissel this is quiet an annoying issue. I suggest to either really duplicate the code by moving lib/logstash/util/zeromq.rb to lib/logstash/inputrespectively lib/logstash/output or by putting lib/logstash/util/zeromq.rb into a separate gem file, which is really shared and therefore present only once.

@erikthorselius
Copy link

Maybe a stupid question but how do I update that? Would it work to uninstall logstash-output-zeromq?

@breml
Copy link
Author

breml commented Jan 7, 2016

@erikthorselius Uninstalling the logstash-output-zeromq plugin may work. If it doesn't, I recommend to rename ./vendor/bundle/jruby/1.9/gems/logstash-output-zeromq-2.0.2/lib/logstash/util/zeromq.rb for example to zeromq.rb.bak. This will prevent ruby from loading this file which will result in ruby loading the correct one from the logstash-input-zeromq plugin.

@erikthorselius
Copy link

I'm so sorry forgetting this. I blame work.

I have tested this again and it works perfect! The cpu goes from 200% to 0.3 % and i still receive logs.

@nukemberg
Copy link
Collaborator

i'm going to start working on refactoring common zeromq code to a new gem, this should ease maintenance of logstash zeromq plugins. i'll update soon.

@suyograo
Copy link
Contributor

suyograo commented Feb 1, 2016

@breml Thanks for this. Could you please bump the version in the gemspec and add a changelog? I can merge this, then and publish a new version

@breml
Copy link
Author

breml commented Feb 2, 2016

@suyograo Sure I would like to update gemspec and changelog, but this change should not be merged without either logstash-plugins/logstash-output-zeromq#13 or the refactoring mentioned by @avishai-ish-shalom, because of https://github.com/logstash-plugins/logstash-input-zeromq/pull/18/files#r47354652.

@nukemberg
Copy link
Collaborator

This PR is on hold until logstash-mixin-zeromq is integrated. cc @breml

@nukemberg nukemberg merged commit d93b0bd into logstash-plugins:master Apr 18, 2016
@breml breml deleted the feature-eagain-not-error branch April 18, 2016 13:46
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.

6 participants