-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Upgrade to tokio v0.2
and std::future::Future
#1142
Comments
cc @hawkw I know you've been working on some of these blocking issues but there might be more info here that you find interesting and could be helpful. |
Sounds great! I think the compat runtime is definitely the way to go. If we can slip it in with minimal changes, we can start to run some tests against that diff alone before tackling any conversions.
It looks like this link is broken. |
I've started working on this. So far everything's going great!
Looks like in the last version of tokio that's gone. We can use |
While working on the update, I realized we also need to update |
In the interest of determining the scope, I propose we add an outline of a complete transition to futures 0.3 and tokio 0.2, and determine which parts of the we should address in the near future (i.e. before/after 1.0). The proposal written by @LucioFranco is a good starting point, but I think we need a kind of roadmap to be able to plan ahead. |
Agree. There will be some uphill work, which you’ve already done some of. But we need to outline, at least, the first few small changes that are isolated and will result in focused PRs. |
The strategy I've been thinking about is roughly the following:
Items (1) and (2) seem like the only ones that should be done before 1.0. The last item will happen over time and is less urgent. |
@lukesteensen I feel like (2) and (3) are the same. I fell like most of the dependencies we'll be able to upgrade pretty easily with So, this is my suggestion for the plan:
We do this by doing small PRs - smaller than each step - to avoid stalling code. Migrations like this are extremely painful if done entirely in a feature-branch, but if they're merged incrementally - they're actually easy. Just a bit more "turbulence" than usual. Steps don't have to be sequential, we can actually interleave them. They're more like milestones. Steps 1 and partially 2 are already in progress - I'm doing some tests to ensure there will be no regressions. What do you think? |
Yeah, (2) is definitely a subset of (3), I just know that it's the higher priority subset that we want to make sure to tackle sooner rather than later. I like what you've laid out here! I definitely appreciate the focus on small, incremental steps. Other than making sure we prioritize the |
As a side topic: I think it'd be a good idea to have a stable list of reviewers for this task. Let's keep it in this message. Please edit this message and add yourself if you're interested - I'll make sure to add you as a reviewer at all the relevant PRs. |
Yeah, def link me on migration PRs please. |
I'll leave the in-depth reviews to @LucioFranco, but would definitely like to keep an eye on these. |
Yeah, this plan looks mostly good. The big thing is our transition of http/hyper/bytes/tower that will cause plenty of issues. This will need to be done quick as well or else we might hit tons of merge conflicts with other work. |
Reopening this as it's more of a tracking issue for global progress. |
Progress update: we've completed steps 1 and 2 from #1142 (comment). I'm now working on |
A list of crates for step 3 is done! See it here: #2118. |
Is there anything remaining to be done here before doing #2108? |
@ktff not that I know of, my plan in general was to start with sinks, so touching the sources now should be fine. |
Background
Current runtime and futures version
Originally, when we first started working on
vector
onlyfutures 0.1
andtokio 0.1
was released. There was no language level support for futures norasync/await
. In that time since we first started working on vector, we have seen the addition ofstd::future::Future
,std::task::{Context, Poll}
, and theasync_await
feature (which lands on stable Nov 7th).Async/await itself is a huge shift in how we write futures and in my experience has reduced the amount of code by up to 40-60%. The biggest benefit is that it allows us to write more "rusty" code because we can now borrow accross yield points which was not possible before without a lot of work.
Tokio 0.2
As some of you may have seen
tokio
has recently implemented a new scheduler along with its upgrade fromfutures 0.1
tostd::future::Future
. This new scheduler has a couple of improvements that impact us directly. Notably less aggressive work-stealing and better optimizations around sendings on channels. You can read more in thisblog
post.The biggest issue with moving to
tokio 0.2
will be the fact that we have a lot of code that usestokio-reactor 0.1
. Alltokio 0.2
runtimes do not provide access to this reactor and thus our code will not work if we just swap out runtimes. To fix this issue the tokio team has written atokio-compat
runtime which uses thetokio 0.2
executor/scheduler,tokio-net
(which is the new reactor for 0.2),tokio-timer 0.2
and a backgroundtokio-reactor 0.1
/tokio-timer 0.1
. This allows us to execute futures that are written in bothfutures 0.1
andstd::future::Future
as well as futures that are fromtokio 0.1
andtokio 0.2
.Performance
During my benchmarking this weekend I was able to see up to
6x
performance increases and on average at least a 100% increase in performance in just upgrading the executor totokio 0.2
.Benchmarks comparing
tokio v0.1.22
andtokio-compat rev f64aee
/tokio rev e699d4653
Note: tests with a change +/-5 were ignored.
A
c5.4xlarge
was used. Code can be found here https://github.com/timberio/vector/tree/lucio/compat-benchSome of these performance numbers are extremely good and slightly confirm some of the theories we've had about certain performance issues that we've seen with
vector
.Proposal
I suggest that we start moving to the
tokio-compat
runtime which will allow us to supporttokio 0.1
andtokio 0.2
items. This will also enable us to spawnstd::future::Future
andfuture 0.1
futures at the same time. This should then allow us to incrementally move to the new futures version and async/await.The actual code change can be done in about 10 lines of code since we already refactored the runtimes out in #1098. That said there are a few blockers:
file
sink will need a rewrite since it usestokio 0.1
blocking annotations which are not currently supported intokio-compat
. This is probably the biggest change that we will need but the sink is very new and I don't think its in a very mature state like some of our others. I have a couple ideas how to refactor this sink easily but it should not be much work since the sink is very simple.tokio_threadpool::blocking
is used which will not work intokio-compat
. We can just upgrade these to the newtokio::executor::thread_pool::blocking
fn that was added recently.Topologly::stop
to use our own shutdown mechanism.tokio 0.2
will not provide the sameshutdown
api thattokio 0.1
did. Our current shutdown code andTopology::stop
implementation has already show some issues and this would be good to combine with Implement a proper topology stop strategy #1091.Beyond these few blockers, I was able to run almost all our tests and most of our benchmarks this weekend with no changes done to them.
Before we move to this new runtime I would also like to ensure that we run it under a week of validation using @lukesteensen's reliability work and run it against our test harness that @binarylogic wrote.
You can look here to see how easy it was to move to the new runtime d56a945
This content would also be a great technical blog post talking about how the new executor improved performance and other novel rust futures-based things.
cc @a-rodin @Jeffail @lukesteensen @binarylogic
The text was updated successfully, but these errors were encountered: