Skip to content

Commit ea8db48

Browse files
authored
Merge pull request #59 from vmihailenco/fix/sysinfo-linux
Move linux dependency under build tag
2 parents ba58917 + 3e56e33 commit ea8db48

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

consumer_config.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package taskq
33
import (
44
"fmt"
55
"math/rand"
6-
"runtime"
76
"time"
87

9-
"github.com/capnm/sysinfo"
108
"github.com/vmihailenco/taskq/v3/internal"
119
)
1210

@@ -317,25 +315,3 @@ func (r *configRoulette) withMoreFetchers(cfg *consumerConfig) *consumerConfig {
317315
func significant(n float64) bool {
318316
return n > 0.05
319317
}
320-
321-
func hasFreeSystemResources() bool {
322-
si := sysinfo.Get()
323-
free := si.FreeRam + si.BufferRam
324-
325-
// at least 200MB of RAM is free
326-
if free < 2e5 {
327-
return false
328-
}
329-
330-
// at least 5% of RAM is free
331-
if float64(free)/float64(si.TotalRam) < 0.05 {
332-
return false
333-
}
334-
335-
// avg load is not too high
336-
if si.Loads[0] > 1.5*float64(runtime.NumCPU()) {
337-
return false
338-
}
339-
340-
return true
341-
}

sysinfo_linux.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// +build linux
2+
3+
package taskq
4+
5+
import (
6+
"runtime"
7+
8+
"github.com/capnm/sysinfo"
9+
)
10+
11+
func hasFreeSystemResources() bool {
12+
si := sysinfo.Get()
13+
free := si.FreeRam + si.BufferRam
14+
15+
// at least 200MB of RAM is free
16+
if free < 2e5 {
17+
return false
18+
}
19+
20+
// at least 5% of RAM is free
21+
if float64(free)/float64(si.TotalRam) < 0.05 {
22+
return false
23+
}
24+
25+
// avg load is not too high
26+
if si.Loads[0] > 1.5*float64(runtime.NumCPU()) {
27+
return false
28+
}
29+
30+
return true
31+
}

sysinfo_other.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// +build !linux
2+
3+
package taskq
4+
5+
func hasFreeSystemResources() bool {
6+
return true
7+
}

0 commit comments

Comments
 (0)