|
1 | 1 | package pubsub |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "os" |
| 5 | + "runtime" |
| 6 | + "strconv" |
4 | 7 | "time" |
5 | 8 |
|
6 | 9 | "github.com/xgodev/boost/wrapper/config" |
@@ -30,14 +33,26 @@ func init() { |
30 | 33 | ConfigAdd(root) |
31 | 34 | } |
32 | 35 |
|
| 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 | + |
33 | 48 | func ConfigAdd(path string) { |
34 | 49 | config.Add(path+level, "DEBUG", "defines log level") |
35 | 50 | config.Add(path+orderingKey, false, "defines ordering key") |
36 | 51 |
|
37 | 52 | config.Add(path+delayThreshold, 10*time.Millisecond, "the maximum duration to wait before sending a batch of messages") |
38 | 53 | config.Add(path+countThreshold, 100, "the maximum number of messages to include in a batch") |
39 | 54 | 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") |
41 | 56 | config.Add(path+timeout, 60*time.Second, "the maximum duration to block Publish calls") |
42 | 57 | config.Add(path+bufferedByteLimit, 10*1e7, "the maximum number of bytes that can be pending in memory across all topics") |
43 | 58 | config.Add(path+maxOutstandingMessages, 1000, "the maximum number of messages that can be pending in memory for publishing") |
|
0 commit comments