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

[WiP] Parallel Rubocop, fixes #117 #175

Closed
wants to merge 1 commit into from

Conversation

jurriaan
Copy link
Contributor

See #117

Changed a lot of things to get it to work correctly.
Including some hacks in the specs.

Feedback would be appreciated 😄

@coveralls
Copy link

Coverage Status

Coverage decreased (-0%) when pulling ce6599dc0cd0e9327c7bb0d9a3309828cd10985c on jurriaan:parallel into 9f34175 on bbatsov:master.

@jurriaan
Copy link
Contributor Author

It's not bug free, still some bugs left. it is not displaying errors for example.
But it's almost 4 times as fast as the non parallel version on my system

inspect_file(file, source, config, report)
end
report
end.each { |report| report.display unless report.empty? }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd extract this into a separate method display_report to make code a bit more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not integrate it with the display_summary method?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easier to test stuff when they are decoupled, that's why I suggested a separate method.

@bbatsov
Copy link
Collaborator

bbatsov commented May 15, 2013

4 times speedup is most impressive! And we'll get another big boost when @whitequark releases Parser 2.0, since it contains a crucial performance optimization. I'll have a look at the code now. :-)

@bbatsov
Copy link
Collaborator

bbatsov commented May 15, 2013

The code looks good to me.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 4f9515ddebbba99f5801c772a178798258b58261 on jurriaan:parallel into 9f34175 on bbatsov:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-5.02%) when pulling 4f9515ddebbba99f5801c772a178798258b58261 on jurriaan:parallel into 9f34175 on bbatsov:master.

# no more checking in the file.
report << syntax_cop
@total_offences += syntax_cop.offences.count
# In case of a syntax error we just report that error and do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Incorrect indentation, right? Should be two spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing it in next commit. :)

@jurriaan
Copy link
Contributor Author

The run method has way too many lines. I could extract this block into a separate method. What do you think?

@bbatsov
Copy link
Collaborator

bbatsov commented May 15, 2013

@jurriaan Sounds reasonable to me. Breaking big methods into smaller ones is rarely a bad idea :-)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0%) when pulling 021793848f1d43c120be256cd6ff1ccbdbd28e05 on jurriaan:parallel into 9f34175 on bbatsov:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0%) when pulling 70be472 on jurriaan:parallel into 273318c on bbatsov:master.

@jurriaan
Copy link
Contributor Author

@bbatsov I'm having some trouble trying to rebase this on the latest master. Errors are now stored in a instance variable of CLI, which is a problem because this branch uses processes instead of threads (so it uses all cores, even with MRI ruby). When using Kernel#fork the instance variables are not shared between processes, but copied. So, if cops fail, it's not reported correctly.

My previous solution was adding the errors to the reports. Should I change the current functionality so it does add them to the reports again? What do you think?

@bbatsov
Copy link
Collaborator

bbatsov commented May 17, 2013

I think you should do some tests with threads on MRI - IO ops should be parallelized even there. You'd also do well to compare process vs thread performance on MRI/Rubinius and JRuby now that we support them all.

If we decided to use processes storing the errors in the reports is a viable idea.

@jurriaan
Copy link
Contributor Author

It's much faster if you use processes on MRI.
Tested it by running time rubocop in my rubocop branch.
On my system MRI Ruby 2.0.0p0 with 8 threads it runs in 9.6 s, with 8 processes it runs in 4.6 s.

@jurriaan
Copy link
Contributor Author

@bbatsov What do you think? I don't want to wait too long with rebasing.

@bbatsov
Copy link
Collaborator

bbatsov commented May 19, 2013

@jurriaan I'm worried that spawning processes on JRuby(I guess this will spin a few JVMs) might be very slow. Do a test with it to make sure it's performing ok and we can proceed.

Alternatively we might simply check the RUBY_ENGINE and select threads or processes based on it.

@jurriaan
Copy link
Contributor Author

It's not possible to use threads at the moment because of the @parser_tokens which will be overwritten by concurrent threads.
Why not move the parsing away from the CLI class?
If you move the parsing related stuff to their own class (one instance per file) and merge this with the report class it would be much easier to run in parallel and I also think it will be more easy to maintain.

@bbatsov
Copy link
Collaborator

bbatsov commented May 19, 2013

@jurriaan That's a reasonable idea. Go ahead and extract the parsing logic.

@whitequark
Copy link

BTW, I think that parallel gem uses threads on JRuby.

@jurriaan
Copy link
Contributor Author

Correct, fork() doesnt work by default on jruby

On 19 mei 2013, at 21:12, Peter Zotov [email protected] wrote:

BTW, I think that parallel gem uses threads on JRuby.


Reply to this email directly or view it on GitHub.

@bbatsov
Copy link
Collaborator

bbatsov commented May 20, 2013

@jurriaan That means you'll definitely need to extract parsing away.

@jurriaan
Copy link
Contributor Author

@bbatsov I'll create a separate pull request for that when I have time :)

@bbatsov bbatsov closed this Jul 3, 2013
@josh josh mentioned this pull request Dec 16, 2016
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants