-
Notifications
You must be signed in to change notification settings - Fork 18
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
Multithreading #4
base: master
Are you sure you want to change the base?
Conversation
tyleretzel
commented
Jun 8, 2018
- Multiple mixers now run concurrently
- Mixer sends allocations made by a producer to be freed by other threads
- mixer selects which producers to run - two different producers with different allocation patterns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good; just some C++ style things.
stress_test/Main.cpp
Outdated
producers.push_back(std::move(std::make_unique<VectorProducer>( | ||
100000, std::chrono::duration<double>(1.0)))); | ||
// Initialize producers | ||
vector<shared_ptr<Producer>> producers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change to shared_ptr? I'd expect this to be a unique_ptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this iteration, the producers were basically immutable configuration objects, and each mixer ran the same set of producers, so it made sense to share producers. I've since changed this back to unique because these assumptions are no longer true.
stress_test/Main.cpp
Outdated
vector<std::thread> threads; | ||
vector<shared_ptr<ToFreeQueue>> toFreeQueues; | ||
for (int i = 0; i < FLAGS_num_threads; i++) { | ||
shared_ptr<ToFreeQueue> toFreeQ = make_shared<ToFreeQueue>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually in a situation like this, you'd say auto toFreeQ = make_shared<ToFreeQueue>();
; the idea being that you only say the type once.
(Some people go even further, and put auto
wherever they can).
stress_test/Main.cpp
Outdated
high_resolution_clock::time_point beginTime = high_resolution_clock::now(); | ||
m.run(); | ||
for (auto it = begin(threads); it != end(threads); ++it) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More idiomatically:
for (auto& thread : threads) {
stress_test/Mixer.cpp
Outdated
|
||
// Picks next producer for the mixer to run. Currently uniform random choice | ||
const Producer &Mixer::pick() { | ||
int producerIndex = this->producerIndexPicker_(this->generator_); | ||
const Producer &Mixer::pickProducer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More idiomatic is for the &
to go on the left (I know this isn't jemalloc "core" style, but it's more idiomatic in C++).
- Mixer creates producer consumer relations: picks a random producer, and then a random consumer to free the memory allocated in the producer.
7e1c6ff
to
59366ed
Compare