mirror of
https://github.com/fankes/beszel.git
synced 2025-10-20 10:19:27 +08:00
remove semaphore and limit docker host connections to 10
This commit is contained in:
@@ -20,7 +20,6 @@ type Agent struct {
|
|||||||
cpuModel string // CPU model of the system
|
cpuModel string // CPU model of the system
|
||||||
cores int // Number of cores of the system
|
cores int // Number of cores of the system
|
||||||
threads int // Number of threads of the system
|
threads int // Number of threads of the system
|
||||||
sem chan struct{} // Semaphore to limit concurrent access to docker api
|
|
||||||
debug bool // true if LOG_LEVEL is set to debug
|
debug bool // true if LOG_LEVEL is set to debug
|
||||||
fsNames []string // List of filesystem device names being monitored
|
fsNames []string // List of filesystem device names being monitored
|
||||||
fsStats map[string]*system.FsStats // Keeps track of disk stats for each filesystem
|
fsStats map[string]*system.FsStats // Keeps track of disk stats for each filesystem
|
||||||
@@ -35,7 +34,6 @@ type Agent struct {
|
|||||||
|
|
||||||
func NewAgent() *Agent {
|
func NewAgent() *Agent {
|
||||||
return &Agent{
|
return &Agent{
|
||||||
sem: make(chan struct{}, 15),
|
|
||||||
containerStatsMap: make(map[string]*container.Stats),
|
containerStatsMap: make(map[string]*container.Stats),
|
||||||
containerStatsMutex: sync.RWMutex{},
|
containerStatsMutex: sync.RWMutex{},
|
||||||
netIoStats: system.NetIoStats{},
|
netIoStats: system.NetIoStats{},
|
||||||
|
@@ -47,9 +47,7 @@ func (a *Agent) getDockerStats() ([]*container.Stats, error) {
|
|||||||
a.deleteContainerStatsSync(ctr.IdShort)
|
a.deleteContainerStatsSync(ctr.IdShort)
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
a.acquireSemaphore()
|
|
||||||
go func() {
|
go func() {
|
||||||
defer a.releaseSemaphore()
|
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
stats, err := a.getContainerStats(ctr)
|
stats, err := a.getContainerStats(ctr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -177,8 +175,8 @@ func newDockerClient() *http.Client {
|
|||||||
ForceAttemptHTTP2: false,
|
ForceAttemptHTTP2: false,
|
||||||
IdleConnTimeout: 90 * time.Second,
|
IdleConnTimeout: 90 * time.Second,
|
||||||
DisableCompression: true,
|
DisableCompression: true,
|
||||||
MaxConnsPerHost: 20,
|
MaxConnsPerHost: 10,
|
||||||
MaxIdleConnsPerHost: 20,
|
MaxIdleConnsPerHost: 10,
|
||||||
DisableKeepAlives: false,
|
DisableKeepAlives: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,14 +2,6 @@ package agent
|
|||||||
|
|
||||||
import "math"
|
import "math"
|
||||||
|
|
||||||
func (a *Agent) acquireSemaphore() {
|
|
||||||
a.sem <- struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Agent) releaseSemaphore() {
|
|
||||||
<-a.sem
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete container stats from map using mutex
|
// delete container stats from map using mutex
|
||||||
func (a *Agent) deleteContainerStatsSync(id string) {
|
func (a *Agent) deleteContainerStatsSync(id string) {
|
||||||
a.containerStatsMutex.Lock()
|
a.containerStatsMutex.Lock()
|
||||||
|
Reference in New Issue
Block a user