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

Multicore collapsing #128

Merged
merged 95 commits into from
Jul 24, 2019
Merged

Multicore collapsing #128

merged 95 commits into from
Jul 24, 2019

Conversation

bcmyers
Copy link
Contributor

@bcmyers bcmyers commented Jun 8, 2019

So after a bit more time working on this, I got collapse-perf, collapse-dtrace and collapse-guess to all work with multiple cores.

The speedup is pretty good. The collapse/perf benchmark on my machine went from 186 MiB/s throughput to 421 MiB/s (+226% improvement).

All the test pass. That said, because we're testing log messages you need to run the test suite with cargo test -- --test-threads=1 to ensure the global test logger is not being trampled on by multiple tests running at the same time.

There are a lot of changes here; so I'll give you a chance to look over the code. Of course, if you have any questions at any time, please don't hesitate to reach out.

At a high level, what has changed is that we now have two code paths for each folder: a "single threaded" code path, which hasn't changed, and a new, "multi-threaded" code path. Which one is taken depends on a configuration option (nthreads).

In the multi-threaded code path, we do an initial pass over the data in order to figure out how to chunk it up. I've tried to make this initial pass as efficient as possible, as it's extra work that doesn't need to be done in the single-threaded situation.

After that's done, we spin up several threads and send the chunked input data to each (actually, we just send a reference). Each thread then uses the single-threaded code path on their chunk.

To bring all the output together ... instead of getting back output from each thread and then "reducing" these outputs, I elected to just use a concurrent hashmap; so there's no need to collate the results after each thread has done it's work. It's sufficient to just write out the contents of the shared hashmap in the same way we were writing out the contents of the single-threaded hashmap in the old code.

It might be interesting to experiment later with a model that doesn't use a concurrent hashmap but instead gives each thread it's own "regular" hashmap and then reduces them in the end. Not sure if that would be faster or slower.

@bcmyers
Copy link
Contributor Author

bcmyers commented Jun 8, 2019

I'm pretty sure Travis is failing only because I don't know how to get it to run cargo test --verbose -- --test-threads=1 instead of cargo test --verbose. Do you know how to tweak the .travis.yml to get it to run tests with only one thread?

@jonhoo
Copy link
Owner

jonhoo commented Jun 10, 2019

Should just be a matter of adding:

script: cargo test --no-fail-fast --verbose --all -- --test-threads=1

just below os: linux I think.

I'll try to get around to reviewing this some time this week :)

@bcmyers
Copy link
Contributor Author

bcmyers commented Jun 10, 2019

Good stuff. Definitely take your time. In the meantime I'll try to fix the .travis.yml.

src/collapse/mod.rs Outdated Show resolved Hide resolved
@bcmyers
Copy link
Contributor Author

bcmyers commented Jun 12, 2019

FYI - Don't take a look at this yet. Still working on getting the commits split out. Will shoot you a note once that's finished.

@bcmyers bcmyers force-pushed the multicore-collapsing branch 2 times, most recently from 355517b to 1e7277d Compare June 12, 2019 21:07
@bcmyers
Copy link
Contributor Author

bcmyers commented Jun 12, 2019

Ok - I think that should be much better (although probably not perfect). The substantive commit is add concurrency to collapse operations.

@jonhoo
Copy link
Owner

jonhoo commented Jun 12, 2019

I'm still seeing basically all of those code blocks moved around in 3a3e669. Am I missing something?

@bcmyers
Copy link
Contributor Author

bcmyers commented Jun 12, 2019

Ah - missed the bins, I think. One sec.

@bcmyers
Copy link
Contributor Author

bcmyers commented Jun 12, 2019

Ok - This should be better.

src/collapse/dtrace.rs Outdated Show resolved Hide resolved
src/collapse/dtrace.rs Outdated Show resolved Hide resolved
src/collapse/mod.rs Outdated Show resolved Hide resolved
src/collapse/mod.rs Outdated Show resolved Hide resolved
src/collapse/mod.rs Outdated Show resolved Hide resolved
src/collapse/mod.rs Outdated Show resolved Hide resolved
src/collapse/dtrace.rs Outdated Show resolved Hide resolved
src/collapse/common.rs Outdated Show resolved Hide resolved
src/collapse/common.rs Outdated Show resolved Hide resolved
Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

This is looking really good now! I left a few inline comments, but nothing too bad I think!

@bcmyers
Copy link
Contributor Author

bcmyers commented Jul 23, 2019

Ok. I think I'm done working on the most recent comments (assuming the CI keeps passing). There are still a couple of open conversations (see above), but hopefully I addressed everything else at least somewhat adequately. Looking forward to your feedback.

Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

Loving the detailed commits -- makes it so easy to review 👍

Changes all look good to me. I think the one case highlighted above should be made an error as you suggest, and I think we should probably not implement Clone as discussed in the other comment chain, but beyond that I think this is ready to land 🎉

@bcmyers
Copy link
Contributor Author

bcmyers commented Jul 24, 2019

Pending CI, I think all is incorporated!

@bcmyers
Copy link
Contributor Author

bcmyers commented Jul 24, 2019

Using your machines for the benchmarks, you should probably update the Comparison to the Perl implementation section of the readme.

@jonhoo jonhoo merged commit b6fb150 into jonhoo:master Jul 24, 2019
@jonhoo
Copy link
Owner

jonhoo commented Jul 24, 2019

Merged! 🎉
Thanks for all your hard work on this :D

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

Successfully merging this pull request may close these issues.

3 participants