CircleCIでメモリ上限値越えエラー #circleci

現象

CircleCIのビルドが TIMED OUT で失敗して、見に行ってみたら下記のようなメッセージが表示されていた。

Your build has exceeded the memory limit of 4G on 1 container. The results of this build are likely invalid. We have taken a snapshot of the memory usage at the time, which you can find in a build artifact named memory-usage.txt. The RSS column in this file shows the amount of memory used by each process, measured in kilobytes.

原因

どうやらCircleCIのビルドコンテナのメモリ上限は4Gらしく、それをオーバーしてしまったよう。 circleci.com

対応

前述のページを参考に、 circle.ymlJVMのオプションを設定する。
これでJVMのメモリ使用上限は抑えられるはず。
数値は適宜見直す。

machine:
  environment:
    _JAVA_OPTIONS: "-Xms512m -Xmx1024m"

補足

メモリ上限値越えの場合、CircleCIが memory-usage.txt というartifactsを生成してくれる。 どこにコストがかかっているか分かるので、調査の際に役立つ。