-
Notifications
You must be signed in to change notification settings - Fork 16
/
env.go
50 lines (44 loc) · 1.52 KB
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package plugin
import (
"log"
"math"
"os"
"strconv"
)
const (
envMaxConcurrentConnection = "STEAMPIPE_MAX_CONCURRENT_CONNECTIONS"
envMaxMemoryMb = "STEAMPIPE_MAX_MEMORY_MB"
envFreeMemInterval = "STEAMPIPE_FREE_MEM_INTERVAL"
defaultMaxConcurrentConnections = 25 // default to 25 concurrent connections
defaultMaxMemoryMb = math.MaxInt64 // default to no memory limit
defaultFreeMemInterval = 100 // default to freeing memory every 100 rows
)
func getMaxConcurrentConnections() int {
maxConcurrentConnections, _ := strconv.Atoi(os.Getenv(envMaxConcurrentConnection))
if maxConcurrentConnections == 0 {
maxConcurrentConnections = defaultMaxConcurrentConnections
}
log.Printf("[INFO] Setting max concurrent connections to %d", maxConcurrentConnections)
return maxConcurrentConnections
}
func GetMaxMemoryBytes() int64 {
maxMemoryMb, _ := strconv.Atoi(os.Getenv(envMaxMemoryMb))
if maxMemoryMb == 0 {
log.Printf("[TRACE] No memory limit set")
maxMemoryMb = defaultMaxMemoryMb
} else {
log.Printf("[TRACE] Setting max memory %dMb", maxMemoryMb)
}
return int64(1024 * 1024 * maxMemoryMb)
}
func GetFreeMemInterval() int64 {
freeMemInterval := defaultFreeMemInterval
intervalEnv, ok := os.LookupEnv(envFreeMemInterval)
if ok {
if parsedInterval, err := strconv.Atoi(intervalEnv); err == nil {
freeMemInterval = parsedInterval
}
}
log.Printf("[INFO] Setting free memory interval to %d rows", freeMemInterval)
return int64(freeMemInterval)
}