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

Introduce harvester_limit to limit number of harvesters #2417

Merged
merged 3 commits into from
Aug 30, 2016

Conversation

ruflin
Copy link
Member

@ruflin ruflin commented Aug 30, 2016

This limits the number of harvesters that are started per prospector.

  • Changelog entry added
  • Docs updated
  • Config file updated

Closes #2236

@ruflin ruflin added in progress Pull request is currently in progress. Filebeat Filebeat labels Aug 30, 2016
This limits the number of harvesters that are started per prospector.

* Changelog entry added
* Docs updated
* Config file updated

Closes elastic#2236
@ruflin ruflin added review and removed in progress Pull request is currently in progress. labels Aug 30, 2016
@ruflin ruflin changed the title Introduce Harvester Limit Introduce harvester_limit to limit number of harvesters Aug 30, 2016
return fmt.Errorf("Harvester limit reached.")
}

atomic.AddUint64(&p.harvesterCounter, 1)
Copy link

Choose a reason for hiding this comment

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

if createHarvester fails counter is off. Either move counter right before p.wg.Add(1) or decrement counter on fail (+ explain why it must be decremented and can not be moved past this place).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a race here if startHarverster can be called concurrently: two threads check the condition when the counter is equal to the limit-1, then they both increment it, so you get to limit+1. Not a big issue, but wouldn't things be simpler with a mutex?

Copy link
Member Author

Choose a reason for hiding this comment

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

@urso @tsg Agree to both comments. Fixing it.

Copy link

Choose a reason for hiding this comment

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

right. Unfortunately atomic does not provide an api to directly get the incremented counter value. Using a mutex for incrementing would be simpler. Otherwise one would need to use CompareAndSwap to atomically update and check counter still being valid.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tsg Just checked the code again and startHarvester cannot be called concurrently. The atomic operation is needed because of the decrementing of the counter inside the go routine.

@@ -155,6 +158,11 @@ func (p *Prospector) createHarvester(state file.State) (*harvester.Harvester, er
}

func (p *Prospector) startHarvester(state file.State, offset int64) error {

if p.config.HarvesterLimit > 0 && atomic.LoadUint64(&p.harvesterCounter) >= p.config.HarvesterLimit {
Copy link

Choose a reason for hiding this comment

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

we should add a comment about atomic ops being safe, due to startHarvester not being executed concurrently and atomic ops only required for harvesters shutting down.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment added in separate commit. Can be squashed.

@tsg
Copy link
Contributor

tsg commented Aug 30, 2016

LGTM.

@tsg tsg merged commit 45202c5 into elastic:master Aug 30, 2016
@shaiknaimuddin
Copy link

Hi,
iam running elasticsearch5.3 and kibana5.3
when i trying yo run filebeats and unable to start the service

i tried with the command PS C:\Program Files\Filebeat> Start-Service filebeat but returning error as
Start-Service : Cannot find any service with service name 'filebeat'.

filebeat.yml

filebeat.prospectors:

  • input_type: log

    Paths that should be crawled and fetched. Glob based paths.

    paths:

    • /var/log/*.log
      #- C:\Program Files\soalogs.txt

output.elasticsearch:

Array of hosts to connect to.

hosts: ["myipaddress:9200"]

please help me in starting Beats.

@ruflin ruflin deleted the max-harvesters branch April 21, 2017 11:04
@ruflin
Copy link
Member Author

ruflin commented Apr 21, 2017

@shaiknaimuddin For questions please use discuss: https://discuss.elastic.co/c/beats/filebeat

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

Successfully merging this pull request may close these issues.

4 participants