Prefer using Tokio as the main task runtime#33
Prefer using Tokio as the main task runtime#33Xanewok merged 9 commits intobernhard-futures-migrationfrom
Conversation
Since Tokio 0.2, spawning the `tokio::process::Command` must be done in the Tokio context, so make sure to spawn the compilation root task in the Tokio runtime that's now available in the `SccacheService`. This fixes a hang in the `sccache_cargo` integration test.
It seems entirely synchronous, as it doesn't hit any await points and additionally seems to be trigger-happy with mutex locks in inner calls, so better be safe and prevent the future reader from thinking that this function is async-safe.
|
Hmm, I am not entirely sure this is a good idea. In my mental model we want a thread pool for some blocking tasks, which might take "long" and thus block the entire system because of blocking all execution threads - so a separate thread pool for those actually would make sense imho. But I think you are correct that the thread pool usage was bleeding into a few places where it was not needed. This is up for discussion though, so don't take this as the ground truth, but rather a data point. |
|
In principle I agree, but in this specific case I think it's better to use a single solution rather than trying to combine two. Most of the intermediate tasks need access to Tokio runtime anyway, because of how pervasive Currently, the blocking thread pool is mostly to perform disk I/O or to use blocking HTTP (for simplicity?). In the context of our usage, using
The majority of other use cases is just regular Until (if?) we use an executor-agnostic child process support, I think simplifying the implementation here gives us more than we'd get by seemingly separating concerns when using An alternative is to create our own executor abstraction that'd wrap Tokio-enabled IO futures that we'd spawn on the separate thread pool but poll inside the Tokio context. I propose to (in no specific order):
@drahnr WDYT? |
A shait, I forgot about this tokio specific thingy.
That sounds like quite a bit of work for not much gain right now.
Given the above, I think I want to land this as is.
I'd defer this one until we see if we practically run into the upper thread count limit.
I think this is a cluster, that should be migrated to tokio/hyper in one go and is on the agenda to get rid of |
The reason for that being not to mix the Tokio runtime and the `futures` executor. While it's reasonable and possible to do so, I believe there's bigger benefit for now to stick to a single executor. It would be great if we could keep the code using 'vanilla' `futures` crate but Tokio support is so baked in (e.g. child process harness) that it seems that it'd require a lot more change for questionable benefit in this case. Doing so may yield another benefit - currently, there seems to be a lot of disk I/O being done on a dedicated, blocking thread pool. It's possible, now that we use a single executor, to use Tokio facilities for async I/O if this proves to be faster when supported properly by the native environment at some point (e.g. with `io_uring` on Linux).
This lets test pass locally on Ubuntu 20.10 with: gcc (Ubuntu 10.2.0-13ubuntu1) 10.2.0 Ubuntu clang version 11.0.0-2
78038d4 to
8fbab2f
Compare
|
Fixed up 78fc70f with diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs
index 93f995d..269ec02 100644
--- a/src/compiler/compiler.rs
+++ b/src/compiler/compiler.rs
@@ -1599,7 +1599,7 @@ LLVM version: 6.0",
cwd.to_path_buf(),
vec![],
CacheControl::Default,
- pool.clone(),
+ pool,
).await
})
.unwrap();to minimize the diff (I added that mistakingly) and added the last expected test change commit 788832b with a more descriptive info as 8fbab2f |
afe17c0 to
12f21d6
Compare
|
I'm merging this as per #34 (comment) and I verified locally that stuff works, as well as in the CI docker container. Left a #23 (comment), I'd be happy to resolve that separately as it doesn't block the future work of splitting the branch into digestible commits in preparation to merge either it to our main branch or upstream in some form. @drahnr thanks for taking a look! |
Most notably this:
sccache_cargointegration test (edce5ab)ClientToolchains::put_toolchainas synchronous (77828ad)futures::executor::ThreadPoolentirely and replaces it with (blocking calls to) Tokio executor all overI tried to put some context/rationale into corresponding commits; let me know if I should squash the last threadpool/Tokio executor commits.
This still fails the tests (but on a new one now 🙃):
interestingly enough, when testing locally, it seems that the new expected value seems from before ac6baf0. Maybe that's a difference in environment? I'm on Ubuntu 20.10 with relevant
gcc -v:Closes #34