14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CircleCIでexceeded the memory limit of 4G on 1 containerが出た際の対処方法の1つ

Last updated at Posted at 2016-01-15

CircleCI

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.

というエラーでRSpecdied unexpectedlyで死んでしまってつらかった。

artifactsmemory-usage.txtを見てねと言われて見てみたら、

phantomjsがメモリリークしてた。

PID   RSS %CPU COMMAND
 31187 1970560 30.4 /usr/local/bin/phantomjs

poltergeistのREADME
にも書いてあったので、Using Poltergeist, Phantom JS instances are not exiting during every rspec run · Issue #419 · teampoltergeist/poltergeistを参考にしながらrails_helper.rbへ、以下を追加。

rails_helper.rb
  # Phantomjsのmemory leakを防ぐ
  config.append_after(:all) do
    # see https://github.com/teampoltergeist/poltergeist/issues/419#issuecomment-31065045
    session_pool = Capybara.instance_variable_get('@session_pool') || {}
    session_pool.each do |_, session|
      # https://github.com/teampoltergeist/poltergeist#memory-leak
      session.driver.quit if session.mode == :poltergeist
    end
    session_pool.clear
  end

session_pool.clearしちゃっているので、Driver生成のオーバーヘッドがかかるであろうから、元記事の:eachより:allぐらいがいいかなという判断です。

if session.mode == :poltergeistは以下のようなpoltergeistをdriverとしてCapybaraに登録するところの第一引数と合わせて下さい。

rails_helper.rb
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app)
end
14
12
0

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
14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?