[groonga-dev,04081] Re: Mroongaストレージモードでメモリリークの可能性

Back to archive index

Kouhei Sutou kou****@clear*****
2016年 7月 18日 (月) 18:48:01 JST


須藤です。

In <3C2B5****@gmail*****>
  "[groonga-dev,04079] Mroongaストレージモードでメモリリークの可能性" on Mon, 18 Jul 2016 01:22:38 +0900,
  murata satoshi <murat****@gmail*****> wrote:

> Mroongaストレージモードにて、メモリリークと思われる現象がありましたので報告させて頂きます。

報告ありがとうございます。
とても助かります。

再現するために必要な情報をすべて含めてもらっていたのも助かり
ました。

MroongaのDockerイメージ(*)を使って再現できた気がします。

(*) https://hub.docker.com/r/groonga/mroonga/

  % docker run --rm -p 3306:3306 groonga/mroonga:mysql5713_mroonga606

で起動して

  % mysql -h 127.0.0.1 -u root

で接続して

  CREATE DATABASE x;
  USE x;
  CREATE TABLE `items` (
    `item_id` int(10) unsigned NOT NULL,
    `category_id` smallint(5) unsigned NOT NULL DEFAULT '0',
    `keyword` text,
    PRIMARY KEY (`item_id`),
    KEY `idx_category_id` (`category_id`),
    FULLTEXT KEY `fti_keyword` (`keyword`) COMMENT 'parser "TokenBigramSplitSymbolAlphaDigit", normalizer "NormalizerAuto"'
  ) ENGINE=Mroonga DEFAULT CHARSET=utf8mb4
  ;

  INSERT INTO `items` (`item_id`, `category_id`, `keyword`)
      VALUES (1, 1, 'テストその01'),
             (2, 1, 'テストその02'),
             (3, 1, 'テストその03'),
             (4, 2, 'テストその04'),
             (5, 2, 'テストその05'),
             (6, 2, 'テストその06'),
             (7, 2, 'テストその07'),
             (8, 3, 'テストその08'),
             (9, 3, 'テストその09'),
             (10,3, 'テストその10')
     ;

で準備をしました。

その後、再現SQLを繰り返し実行しました。

  select mroonga_command("status");
  --- {"alloc_count":586,...}
  select * from items where match(keyword) against('+04' IN BOOLEAN MODE) order by item_id desc limit 2;
  select mroonga_command("status");
  --- {"alloc_count":13899,...}
  select * from items where match(keyword) against('+04' IN BOOLEAN MODE) order by item_id desc limit 2;
  select mroonga_command("status");
  --- {"alloc_count":27212,...}
  select * from items where match(keyword) against('+04' IN BOOLEAN MODE) order by item_id desc limit 2;
  select mroonga_command("status");
  --- {"alloc_count":40525,...}

たしかに、実行するたびにalloc_countが増えています。

さらに続けていると

  select mroonga_command("status");
  --- {"alloc_count":107079,...}
  select * from items where match(keyword) against('+04' IN BOOLEAN MODE) order by item_id desc limit 2;
  select mroonga_command("status");
  --- {"alloc_count":107080,...}
  select * from items where match(keyword) against('+04' IN BOOLEAN MODE) order by item_id desc limit 2;
  select mroonga_command("status");
  --- {"alloc_count":107081,...}
  select * from items where match(keyword) against('+04' IN BOOLEAN MODE) order by item_id desc limit 2;
  select mroonga_command("status");
  --- {"alloc_count":107082,...}

1ずつしか増えなくなりました。

さらに1000回以上続けていると

  select mroonga_command("status");
  --- {"alloc_count":108222,...}
  select * from items where match(keyword) against('+04' IN BOOLEAN MODE) order by item_id desc limit 2;
  select mroonga_command("status");
  --- {"alloc_count":108223,...}
  select * from items where match(keyword) against('+04' IN BOOLEAN MODE) order by item_id desc limit 2;
  select mroonga_command("status");
  --- {"alloc_count":106802,...}
  select * from items where match(keyword) against('+04' IN BOOLEAN MODE) order by item_id desc limit 2;
  select mroonga_command("status");
  --- {"alloc_count":105381,...}

今度はalloc_countが減り始めました。


手元ではこのようになったのですが、これは村田さんの環境の現象
と同じでしょうか?

(OOMで落ちているということなのでもしかしたら違うかも、とは
思っています。)


もし、この現象であれば、Groongaが内部で使っているmrubyのGCの
タイミングによるものです。mrubyはある程度不要なオブジェクト
が溜まった段階でGCを動かすので、GCが動くまでの間は一時的に作
成したオブジェクトが増えていくのです。↑でalloc_countが減り
始めたのはmrubyのGCが動き始めたからです。

そもそもmrubyのGCが必要にならないように、一時的に作るオブジェ
クトを減らしておきました。次のリリースからは、このケースでは
alloc_countが増えなくなるはずです。


mrubyのGCが原因の場合はOOMで落ちる前にalloc_count(メモリー
使用量)が減ると思うので妙なんですよね。。。


-- 
須藤 功平 <kou****@clear*****>
株式会社クリアコード <http://www.clear-code.com/>
10周年祝いイベント: http://www.clear-code.com/blog/2016/7/13.html

Groongaベースの全文検索システムを総合サポート:
  http://groonga.org/ja/support/
パッチ採用 - プログラミングが楽しい人向けの採用プロセス:
  http://www.clear-code.com/recruitment/




groonga-dev メーリングリストの案内
Back to archive index