相关疑难解决方法(0)

增加 GO 中的堆大小

有没有办法指示 GO 运行时使用更大的堆?我在跑步GO 1.5

我的 GO 进程目前在 GC 上花费了 34% 的时间,但它只使用了可用系统内存的 1/3。

我知道ulimit可以用来限制最大堆大小。我已将 ulimit 设置为 ~16GB ( ulimit -v 17179869184),但堆大小永远不会超过 5GB。

使用GODEBUG=gctrace=1我可以看到高 GC 开销 (34%):

20160719-220359.169294 :: gc 665 @5484.983s 34%: 3.3+2504+188+1635+8.0 ms clock, 26+2504+0+26950/3271/3.5+64 ms cpu, 4825->4964->2623 MB, 4948 MB goal, 8 P
20160719-220406.322354 :: gc 666 @5492.411s 34%: 2.9+212+2111+1749+8.3 ms clock, 23+212+0+25010/3496/146+67 ms cpu, 4846->4990->2657 MB, 4970 MB goal, 8 P
20160719-220413.703514 :: gc 667 @5499.452s 34%: 4.4+4411+0.021+0.25+8.4 ms clock, 35+4411+0+29365/0.054/38+67 …
Run Code Online (Sandbox Code Playgroud)

garbage-collection go

8
推荐指数
1
解决办法
1万
查看次数

如何在Golang中为进程设置内存限制

我使用syscall prlimit设置资源限制来处理,它适用于限制CPU时间,但是当测试内存使用时,我遇到了问题.

package sandbox

import (
    "syscall"
    "unsafe"
)

func prLimit(pid int, limit uintptr, rlimit *syscall.Rlimit) error {
    _, _, errno := syscall.RawSyscall6(syscall.SYS_PRLIMIT64, uintptr(pid), limit, uintptr(unsafe.Pointer(rlimit)), 0, 0, 0)
    var err error
    if errno != 0 {
        err = errno
        return err
    } else {
        return nil
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的考验.

func TestMemoryLimit(t *testing.T) {
    proc, err := os.StartProcess("test/memo", []string{"memo"}, &os.ProcAttr{})
    if err != nil {
        panic(err)
    }
    defer proc.Kill()
    var rlimit syscall.Rlimit
    rlimit.Cur = 10
    rlimit.Max = 10 + 1024 …
Run Code Online (Sandbox Code Playgroud)

unix memory go

4
推荐指数
1
解决办法
3395
查看次数

标签 统计

go ×2

garbage-collection ×1

memory ×1

unix ×1