Cucumber with celerity running under capybara and celerity was erroring out with Java OutOfMemory exceptions. In looking to fix the problem, I also decided to look at how various jruby invocation switches would alter the performance.
First, to set your jruby invocation options, in your cucumber environment file, add the following:
require 'culerity' Culerity.jruby_invocation = 'jruby -J-Xmx2500m -J-Xms2500m -J-Xmn512m'
I recommend setting the Xmx and Xms options, the maximum and minimum Java heap sizes, to the same value, tailored to your environment. Xmn controls the generation size for the garbage collector. 20% or so of the total heap size seems to be the sweet spot, and allows the garbage collector to run effectively over this memory.
While increasing the java heap size temporarily alleviated the issue, it didn’t address it entirely, there seemed to be a memory leak. I started poking around, and found this commit, https://github.com/langalex/culerity/commit/5eb7d6e557f86acdeb865af2180629930629bd26, in the culerity repository. After some experimentation, I settled on adding the following to my environment file:
After do if page.driver.is_a?(Capybara::Driver::Culerity) page.driver.class.server.clear_proxies end end
clearproxies can be replaced without closebrowsers, but it impacts performance more than clear proxies and increases memory usage. The clear_proxies method frees the rjuby remote object proxies, which in turn allows the garbage collector to reclaim the memory that they occupy. This reduced my overall memory usage for the testing suite by over a gigabyte, and had a very minor runtime improvement. At the same time, I also tried both the –fast and the –server options on the rjuby invocation, and found that they didn’t seem to have any significant positive impact on either memory usage or runtime.
jruby -J-Xmx2500m -J-Xms2500m -J-Xmn512m Mem 1,066,412MB 19m28.724s with page.driver.class.server.clear_proxies Mem 2,111,728MB 19m54.007s without page.driver.class.server.clear_proxies Mem 1,549,804MB 23m10.708s with page.driver.class.server.close_browsers jruby -J-Xmx2500m -J-Xms2500m -J-Xmn512m --fast --server Mem 1,068,840MB 21m45.931s with page.driver.class.server.clear_proxies Mem 2,945,160MB 21m8.971s without page.driver.class.server.clear_proxies jruby -J-Xmx2500m -J-Xms2500m -J-Xmn512m --fast Mem 1,081,064MB 19m57.935s with page.driver.class.server.clear_proxies jruby -J-Xmx2500m -J-Xms2500m -J-Xmn512m --server Mem 1,089,388MB 20m14.662s with page.driver.class.server.clear_proxies
This wasn’t scientific, but it did stop cucumber from leaking so much memory.
Use the following link to trackback from your own site: