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

Gather concurrently from snmp agents #3365

Merged
merged 2 commits into from
Oct 25, 2017
Merged

Conversation

danielnelson
Copy link
Contributor

Adds concurrent collection for each agent, each agent is still gathered sequentially.

I changed the connection cache to hold connections by index, in case the agent list contains multiples of the same destination.

#1665

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@danielnelson danielnelson added this to the 1.5.0 milestone Oct 19, 2017
if s.initialized {
return nil
}

s.connectionCache = make(map[int]snmpConnection)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're changing the cache key to be the agent's index in the list, we can turn this into a slice instead, using the index in s.Agents as the index for s.connectionCache. And then since we'd be using a slice, we can pre-allocate it here as we know the size of s.Agents. And then once we pre-allocate it, we can do away with the mutex since it'll never change during runtime. The only change will be to individual elements, which the updated description for getConnection says is an error to access in more than 1 goroutine.

None of that is required, just throwing it out there :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll do this.

// result using `agentIndex` as the cache key. This is done to allow multiple
// connections to a single address. It is an error to use a connection in
// more than one goroutine.
func (s *Snmp) getConnection(agentIndex int, agent string) (snmpConnection, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

agent param is redundant. You can get it from s.Agents[agentIndex].

@danielnelson
Copy link
Contributor Author

@phemmer I updated the pull request with your suggestions, can you take a second look?

@phemmer
Copy link
Contributor

phemmer commented Oct 25, 2017

Looks good to me

@danielnelson danielnelson merged commit a519abf into master Oct 25, 2017
@danielnelson danielnelson deleted the snmp-input-concurrent-agents branch October 25, 2017 22:28
maxunt pushed a commit that referenced this pull request Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants