Skip to content

Commit b646ab2

Browse files
committed
Altera número de goroutines padrão
Adiciona função para definir quantidade com base na variável de ambiente. Utiliza número de CPUs como fallback para valores inválidos ou não definidos.
1 parent fd0a5a9 commit b646ab2

File tree

1 file changed

+16
-1
lines changed
  • wrapper/publisher/driver/contrib/cloud.google.com/pubsub/v1

1 file changed

+16
-1
lines changed

wrapper/publisher/driver/contrib/cloud.google.com/pubsub/v1/config.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package pubsub
22

33
import (
4+
"os"
5+
"runtime"
6+
"strconv"
47
"time"
58

69
"github.com/xgodev/boost/wrapper/config"
@@ -30,14 +33,26 @@ func init() {
3033
ConfigAdd(root)
3134
}
3235

36+
func getMaxProcs() int {
37+
val := os.Getenv("GOMAXPROCS")
38+
if val == "" {
39+
return runtime.NumCPU() // fallback padrão
40+
}
41+
n, err := strconv.Atoi(val)
42+
if err != nil || n <= 0 {
43+
return runtime.NumCPU() // fallback se inválido
44+
}
45+
return n
46+
}
47+
3348
func ConfigAdd(path string) {
3449
config.Add(path+level, "DEBUG", "defines log level")
3550
config.Add(path+orderingKey, false, "defines ordering key")
3651

3752
config.Add(path+delayThreshold, 10*time.Millisecond, "the maximum duration to wait before sending a batch of messages")
3853
config.Add(path+countThreshold, 100, "the maximum number of messages to include in a batch")
3954
config.Add(path+byteThreshold, 1e6, "the maximum total size of messages to include in a batch")
40-
config.Add(path+numGoroutines, 1, "the number of goroutines that process batches of messages")
55+
config.Add(path+numGoroutines, getMaxProcs(), "the number of goroutines that process batches of messages")
4156
config.Add(path+timeout, 60*time.Second, "the maximum duration to block Publish calls")
4257
config.Add(path+bufferedByteLimit, 10*1e7, "the maximum number of bytes that can be pending in memory across all topics")
4358
config.Add(path+maxOutstandingMessages, 1000, "the maximum number of messages that can be pending in memory for publishing")

0 commit comments

Comments
 (0)