-
Notifications
You must be signed in to change notification settings - Fork 41
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
Exit worker threads early when there are no tasks after a while #377
Comments
@byhashdong Here it is, sir! |
|
Hopefully one day we understand why!
Ah yes, the scope should end immediately when all threads join. The original idea is more about starting to post-process when
While looking for a Lines 118 to 119 in bed6f22
We can add a counter here to return a |
Do you mean that still keep |
@byhashdong Yes, something like that. FYI, |
Adding some stats code and running
Test code is attached as below: diff --git a/src/pevm.rs b/src/pevm.rs
index a42f46c..9557aee 100644
--- a/src/pevm.rs
+++ b/src/pevm.rs
@@ -172,7 +172,8 @@ impl Pevm {
thread::scope(|scope| {
for _ in 0..concurrency_level.into() {
scope.spawn(|| {
- let mut task = scheduler.next_task();
+ let mut task_none_counter = 0;
+ let mut task = scheduler.next_task(&mut task_none_counter);
while task.is_some() {
task = match task.unwrap() {
Task::Execution(tx_version) => {
@@ -194,9 +195,15 @@ impl Pevm {
}
if task.is_none() {
- task = scheduler.next_task();
+ task = scheduler.next_task(&mut task_none_counter);
}
}
+
+ println!(
+ "Thread {:?} task_none_counter: {}",
+ thread::current().id(),
+ task_none_counter
+ );
});
}
});
diff --git a/src/scheduler.rs b/src/scheduler.rs
index 6c0e764..e5b3136 100644
--- a/src/scheduler.rs
+++ b/src/scheduler.rs
@@ -105,7 +105,7 @@ impl Scheduler {
None
}
- pub(crate) fn next_task(&self) -> Option<Task> {
+ pub(crate) fn next_task(&self, task_none_counter: &mut usize) -> Option<Task> {
while !self.aborted.load(Ordering::Acquire) {
let execution_idx = self.execution_idx.load(Ordering::Acquire);
let validation_idx = self.validation_idx.load(Ordering::Acquire);
@@ -115,6 +115,8 @@ impl Scheduler {
{
break;
}
+
+ *task_none_counter += 1;
thread::yield_now();
continue;
}
@@ -161,6 +163,7 @@ impl Scheduler {
return Some(Task::Execution(tx_version));
}
}
+
None
} |
Will do benchmark tests to determine the |
Tried some runs of
🟢: improved
|
rayon
thread pool in Pevm
between runs
@byhashdong Is I've also played with a few numbers and cannot find a sweet spot. There are always strong wins (no late dependencies so exiting workers early removes tail latency) and losses (many dependencies so when we exit threads early we lack workers when we reset the execution index way back early in the block). I think we should bring more variables to the equation. For instance, to only count empty tasks and exit threads when |
Yes So sad to hear no positives on your side. I think it maybe related to the counter in/out |
@byhashdong For micro-benchmarks like this it's best to close most processes (especially large ones like browsers and code editors with |
No description provided.
The text was updated successfully, but these errors were encountered: