Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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
ppworks
最近は主にrailsです!
http://ppworks.jp
esaLLC
esa.io や pplog.net などのWebサービスを開発・デザイン・運営しています
https://team.esa.io
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away