LoginSignup
13
12

More than 5 years have passed since last update.

俺のconsulがこんなに仮想メモリを食う訳が無い

Posted at

あまりにショックだったので釣りタイトルになってしまった...

consul の検証をしようと、ちょっくらバイナリを落としてサーバを立ち上げようとしたら以下のようなエラーになった。

[root@manage001 /]# consul agent -server -bootstrap -data-dir /var/consul/data
==> WARNING: Bootstrap mode enabled! Do not enable unless necessary
==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1
==> Starting Consul agent...
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x98 pc=0x40559a]

runtime stack:
runtime: unexpected return pc for runtime.sigpanic called from 0x40559a
runtime.throw(0x1063e05runtime/cgo: out of memory in thread_start
)
        /opt/go/src/pkg/runtime/panic.c:520 +0x69
runtime: unexpected return pc for runtime.sigpanic called from 0x40559a
runtime.sigpanic()
        /opt/go/src/pkg/runtime/os_linux.c:222 +0x3d

goroutine 16 [syscall]:
runtime.cgocall(0x403ad0, 0x7f3abb3f4050)
        /opt/go/src/pkg/runtime/cgocall.c:143 +0xe5 fp=0x7f3abb3f4038 sp=0x7f3abb3f3ff0
github.com/armon/gomdb._Cfunc_mdb_env_open(0x1492c30, 0x1491170, 0x1ed00200000, 0x0)
        github.com/armon/gomdb/_obj/_cgo_defun.c:232 +0x31 fp=0x7f3abb3f4050 sp=0x7f3abb3f4038
github.com/armon/gomdb.(*Env).Open(0xc2080363b8, 0xc2080358e0, 0x19, 0x200000, 0x1ed, 0x0, 0x0)
        /opt/gopath/src/github.com/armon/gomdb/env.go:88 +0xa6 fp=0x7f3abb3f4090 sp=0x7f3abb3f4050
github.com/hashicorp/raft-mdb.(*MDBStore).initialize(0xc208035960, 0x0, 0x0)
        /opt/gopath/src/github.com/hashicorp/raft-mdb/mdb_store.go:84 +0x10d fp=0x7f3abb3f4168 sp=0x7f3abb3f4090

怖!!! なんだこれ...

よく見ると out of memory と書いてある。いやいやメモリ普通に1GBぐらいは空いてますから...、と思って同僚氏(というか @hiboma さん)のアドバイスに従い sysctl -w vm.overcommit_memory=0 した(vm.overcommit_memory=2 だったので)。

立ち上がった様子

一応これで立ち上がったが、そんなにメモリ使うの...??

[root@manage001 ~]# ps alx | grep -e consul -e RSS
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
0     0  7494  7294  20   0 107456   952 pipe_w S+   pts/2      0:00 grep -e consul -e RSS
4     0 24991 24687  20   0 42447616 11892 epoll_ Sl pts/0      0:01 /usr/local/bin/consul agent -server -bootstrap -data-dir /var/consul/data

フーン 12MB ぐらいか〜と思って見逃していたがVSZが半端無い。仮想メモリを40GB(4GBではない)近く要求している......それは、 vm.overcommit_memory=2 では立ち上がらんやつですね...。

なんでこうなってるの

理由は公式FAQにあって、雑に言うとLMDBのパフォーマンスをアジャイルに最大化するため大量にバッファしているもよう。in practiceではそんなに使わないよって言われても...

具体的には、以下の箇所でハードコードしている容量を確保する(これも hiboma さんが見つけたんですが...)。

server.go
const (
    //...
    raftDBSize64bit uint64 = 8 * 1024 * 1024 * 1024 // Limit Raft log to 8GB
)
state_store.go
const (
    //...
    dbMaxMapSize64bit uint64 = 32 * 1024 * 1024 * 1024 // 32GB maximum size
)

なので 設定できない 。設定できるようにPRでも出せば良いだろうけど、なんか、設定無しで動くよ!と言うのが大事な気もするのでなんとも。

まとめ

  • consul server はガツっとメモリを用意しとく、もしくは vm.overcommit_memory=0 で...良いと思う...
  • consul client はこんなに気合いの入ったmmapはしない模様。

参考記事(とてもタイムリー)

13
12
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12