Skip to content

Commit

Permalink
add better management of concurrent tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
door7302 committed Jan 17, 2024
1 parent 1c9905e commit 3ee4779
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions plugins/inputs/netconf_junos/netcong.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,16 @@ func (c *NETCONF) subscribeNETCONF(ctx context.Context, address string, u string
jitter := time.Duration(1000 + rand.Intn(10))
tick := jitter * time.Millisecond

// Init counter per RPC
counters := make(map[string]uint64)
// First find out the min interval btw all RPC
min := uint64(100000)
for _, v := range r {
counters[v.rpc] = 0
min = minUint64(min, v.interval)
}
// Init counter per RPC - distribute evently the RPC over the min time frame
taskInterval := uint64(time.Duration((float64(min) / float64(len(r))) * float64(time.Second)))
counters := make(map[string]uint64)
for i, v := range r {
counters[v.rpc] = uint64(i) * taskInterval
}

// Loop until end
Expand Down Expand Up @@ -415,6 +421,14 @@ const sampleConfig = `
sample_interval = "60s"
`

// simple unint64 min func
func minUint64(a, b uint64) uint64 {
if a < b {
return a
}
return b
}

// SampleConfig of plugin
func (c *NETCONF) SampleConfig() string {
return sampleConfig
Expand Down

0 comments on commit 3ee4779

Please sign in to comment.