Skip to content

Commit 4daca61

Browse files
authored
add multi concurrency (#57)
1 parent cace1d4 commit 4daca61

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ replace (
3333

3434
require (
3535
github.com/Masterminds/sprig/v3 v3.2.3
36+
github.com/alitto/pond v1.8.3
3637
github.com/argoproj/gitops-engine v0.7.1-0.20230906152414-b0fffe419a0f
3738
github.com/go-logr/logr v1.2.4
3839
github.com/orcaman/concurrent-map/v2 v2.0.1

go.sum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
8383
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
8484
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
8585
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
86+
github.com/alitto/pond v1.8.3 h1:ydIqygCLVPqIX/USe5EaV/aSRXTRXDEI9JwuDdu+/xs=
87+
github.com/alitto/pond v1.8.3/go.mod h1:CmvIIGd5jKLasGI3D87qDkQxjzChdKMmnXMg3fG6M6Q=
8688
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
8789
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
8890
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
@@ -541,12 +543,6 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
541543
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
542544
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
543545
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
544-
github.com/pluralsh/console-client-go v0.0.5 h1:+L7I3QLMWNBiuZlWe/YJfUMMZGnpKhEAlbs9sL+hiSc=
545-
github.com/pluralsh/console-client-go v0.0.5/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU=
546-
github.com/pluralsh/console-client-go v0.0.8 h1:BwWOt1ggBX/fxzY2+01dk8sBTz1jqT57o2y1Iz9Zxzk=
547-
github.com/pluralsh/console-client-go v0.0.8/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU=
548-
github.com/pluralsh/console-client-go v0.0.11 h1:2fchZE6qlSQmHTeuH54hAzJJpgKpx2Kbl8HhJNugbns=
549-
github.com/pluralsh/console-client-go v0.0.11/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU=
550546
github.com/pluralsh/console-client-go v0.0.14 h1:vpvC6SR7A0MIrpeyR78hM6IreOLKgg+moRIEjyUnKZo=
551547
github.com/pluralsh/console-client-go v0.0.14/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU=
552548
github.com/pluralsh/polly v0.1.4 h1:Kz90peCgvsfF3ERt8cujr5TR9z4wUlqQE60Eg09ZItY=

pkg/sync/loop.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"runtime/debug"
77

8+
"github.com/alitto/pond"
89
"github.com/argoproj/gitops-engine/pkg/sync"
910
"github.com/argoproj/gitops-engine/pkg/sync/common"
1011
"github.com/samber/lo"
@@ -27,18 +28,19 @@ func (engine *Engine) ControlLoop() {
2728

2829
wait.PollInfinite(syncDelay, func() (done bool, err error) {
2930
log.Info("Polling for new service updates")
30-
31-
item, shutdown := engine.svcQueue.Get()
32-
if shutdown {
33-
return true, nil
34-
}
35-
36-
if err := engine.processItem(item); err != nil {
37-
log.Error(err, "found unprocessable error")
31+
pool := pond.New(20, 100, pond.MinWorkers(20))
32+
for i := 0; i < engine.svcQueue.Len(); i++ {
33+
item, shutdown := engine.svcQueue.Get()
34+
if shutdown {
35+
return true, nil
36+
}
37+
pool.TrySubmit(func() {
38+
if err := engine.processItem(item); err != nil {
39+
log.Error(err, "found unprocessable error")
40+
}
41+
})
3842
}
39-
40-
engine.syncing = ""
41-
43+
pool.StopAndWait()
4244
return false, nil
4345
})
4446
}

0 commit comments

Comments
 (0)