Skip to content

Commit

Permalink
use goroutine pool in throttleProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
juliens authored and traefiker committed Mar 15, 2018
1 parent b1e3444 commit e2f1887
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (s *Server) preLoadConfiguration(configMsg types.ConfigMessage) {
providerConfigUpdateCh = make(chan types.ConfigMessage)
s.providerConfigUpdateMap[configMsg.ProviderName] = providerConfigUpdateCh
s.routinesPool.Go(func(stop chan bool) {
throttleProviderConfigReload(providersThrottleDuration, s.configurationValidatedChan, providerConfigUpdateCh, stop)
s.throttleProviderConfigReload(providersThrottleDuration, s.configurationValidatedChan, providerConfigUpdateCh, stop)
})
}
providerConfigUpdateCh <- configMsg
Expand All @@ -378,11 +378,11 @@ func (s *Server) preLoadConfiguration(configMsg types.ConfigMessage) {
// It will immediately publish a new configuration and then only publish the next configuration after the throttle duration.
// Note that in the case it receives N new configs in the timeframe of the throttle duration after publishing,
// it will publish the last of the newly received configurations.
func throttleProviderConfigReload(throttle time.Duration, publish chan<- types.ConfigMessage, in <-chan types.ConfigMessage, stop chan bool) {
func (s *Server) throttleProviderConfigReload(throttle time.Duration, publish chan<- types.ConfigMessage, in <-chan types.ConfigMessage, stop chan bool) {
ring := channels.NewRingChannel(1)
defer ring.Close()

safe.Go(func() {
s.routinesPool.Go(func(stop chan bool) {
for {
select {
case <-stop:
Expand Down
5 changes: 4 additions & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ func TestThrottleProviderConfigReload(t *testing.T) {
stop <- true
}()

go throttleProviderConfigReload(throttleDuration, publishConfig, providerConfig, stop)
globalConfig := configuration.GlobalConfiguration{}
server := NewServer(globalConfig)

go server.throttleProviderConfigReload(throttleDuration, publishConfig, providerConfig, stop)

publishedConfigCount := 0
stopConsumeConfigs := make(chan bool)
Expand Down

0 comments on commit e2f1887

Please sign in to comment.