@@ -16,7 +16,7 @@ func init() {
16
16
}
17
17
// RegisterTargets 一次性最大支持同时绑定 20 个 target: https://cloud.tencent.com/document/api/214/30676
18
18
go startRegisterTargetsProccessor (20 )
19
- go startCreateListenerProccessor (concurrency )
19
+ go startCreateListenerProccessor (800 )
20
20
// DescribeListeners 一次性最大支持查 100 个监听器: https://cloud.tencent.com/document/api/214/30686
21
21
go startDescribeListenerProccessor (100 )
22
22
// DescribeTargets 一次性最大支持同时查 20 个监听器: https://cloud.tencent.com/document/api/214/30684
@@ -40,7 +40,9 @@ type Task interface {
40
40
GetRegion () string
41
41
}
42
42
43
- func StartBatchProccessor [T Task ](maxAccumulatedTask int , apiName string , writeOp bool , taskChan chan T , doBatch func (region , lbId string , tasks []T )) {
43
+ const maxAccumulatedTask = 800
44
+
45
+ func StartBatchProccessor [T Task ](maxTaskOneBatch int , apiName string , writeOp bool , taskChan chan T , doBatch func (region , lbId string , tasks []T )) {
44
46
tasks := []T {}
45
47
timer := time .NewTimer (MaxBatchInternal )
46
48
batchRequest := func () {
@@ -60,14 +62,19 @@ func StartBatchProccessor[T Task](maxAccumulatedTask int, apiName string, writeO
60
62
// 将合并后的 task 通过 clb 的 BatchXXX 接口批量操作
61
63
// TODO: 能否细化到部分成功的场景?
62
64
for lb , tasks := range groupTasks {
63
- go func (region , lbId string , tasks []T ) {
64
- if writeOp { // 写操作加实例锁
65
- mu := getLbLock (lbId )
66
- mu .Lock ()
67
- defer mu .Unlock ()
68
- }
69
- doBatch (region , lbId , tasks )
70
- }(lb .Region , lb .LbId , tasks )
65
+ for len (tasks ) > 0 {
66
+ num := min (len (tasks ), maxTaskOneBatch )
67
+ t := tasks [:num ]
68
+ tasks = tasks [num :]
69
+ go func (region , lbId string , tasks []T ) {
70
+ if writeOp { // 写操作加实例锁
71
+ mu := getLbLock (lbId )
72
+ mu .Lock ()
73
+ defer mu .Unlock ()
74
+ }
75
+ doBatch (region , lbId , tasks )
76
+ }(lb .Region , lb .LbId , t )
77
+ }
71
78
}
72
79
}
73
80
for {
0 commit comments