Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processes seem to run sequentially for specs, but in parallel for features #66

Closed
sciprog opened this issue Oct 19, 2011 · 12 comments
Closed

Comments

@sciprog
Copy link

sciprog commented Oct 19, 2011

I've followed the installation and setup procedure to the letter. The parallel:create task successfully detects 4 cores, and builds 4 test databases. parallel:prepare runs without a hitch. I see a dramatic improvement in the runtime of my cucumber features, and my system monitor shows all 4 cores chewing away at the tests. However, when I run the specs with "rake parallel:spec", or "parallel_spec" the tests consistently run in slightly more time than it takes to run them sequentially (ie. "rake spec"). Additionally, the system monitor shows all 4 cores fire up during the initialization of the specs, but only 1 core is active while the tests are actually running. Although 4 processes are created, according to the output "4 processes for 41 specs, ~ 10 specs per process", it appears as if these processes are then run sequentially, rather than in parallel. I see the rspec summary output for the first process before the second process begins. I haven't been able to find other posts about this issue, which makes me suspect that I've somehow messed up the configuration, but I have not been able to find the problem. Any thoughts?
Thank you.

@grosser
Copy link
Owner

grosser commented Oct 19, 2011

can you recreate the issue with a very simple setup (e.g. empty folder with 4 test files that each run sleep 10) ?

@sciprog
Copy link
Author

sciprog commented Oct 20, 2011

Thanks, that shed some light on the situation. With 4 test files each running sleep 10, I'm seeing a 10 second increase, over baseline, in the runtime of the tests. When I switch out the sleep statement with a call to a naive fibonacci calculator, I can see all 4 cores operating at 100% while the tests are running. Maybe the parallelization is working correctly, but I've got a bottleneck somewhere that's keeping the CPU waiting between tests, making it appear to be idle. However, the same bottleneck would exist during sequential execution, so I'd expect see at least some improvement when I parallelize. I'll keep looking. Thanks again for the help.

@grosser
Copy link
Owner

grosser commented Oct 23, 2011

maybe try to install parallel_tests as plugin and hack around/scatter some puts to see if the code truly runs in parallel

@sciprog
Copy link
Author

sciprog commented Oct 24, 2011

Got it sorted out. The bottleneck was caused by my DatabaseCleaner configuration. I changed the strategy from truncation to transaction, and now my tests run like they're on fire! Thanks for all the help :-)

@sciprog sciprog closed this as completed Oct 24, 2011
@grosser
Copy link
Owner

grosser commented Oct 24, 2011

sounds very hard to figure out, could you add a bit of into to the wiki, so other people do not run into the same trap

@sciprog
Copy link
Author

sciprog commented Oct 25, 2011

Done. I'm afraid I didn't uncover the root of the problem, so my entry doesn't include much in the way of specifics, but I think it's enough to put others on the right track.

@astjohn
Copy link

astjohn commented Jul 14, 2013

Any thoughts for a mongoid user? DatabaseCleaner requires truncation for mongoid.

@tazsingh
Copy link

@astjohn You'd need separate Mongo databases in order to run parallel tests.

@astjohn
Copy link

astjohn commented Jul 22, 2013

@tazsingh, You can run separate databases for each thread easily, but that still won't help for between tests. The default setup when using DatabaseCleaner is to purge the database before each test using either transaction or truncation method, but with mongoid, you only have truncation.

@tazsingh
Copy link

@astjohn Sorry, I'm not following you. If you have a separate database for each thread/process, then each test can purge/truncate the database and it won't affect the other tests that are running in parallel (assuming your tests are not dependent on each other and could run in random order).

@astjohn
Copy link

astjohn commented Jul 22, 2013

@tazsingh Exactly. This original issue was started because truncating was creating a bottleneck, and with mongoid / databasecleaner, truncating is your only option. Read above comment before this issue was closed. I'm wondering if anyone else out there has experienced a similar bottleneck with mongoid or not?

@tazsingh
Copy link

@astjohn Ah thanks for the clarification, just did a quick read initially. Having used this gem with Mongoid, we haven't noticed the bottleneck and have noticed significant speed improvements :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants