Skip to content

Commit 1b9af22

Browse files
seanmonstarUrhengulashawkw
authored
Tokio 0.3 Upgrade (#2319)
Co-authored-by: Urhengulas <[email protected]> Co-authored-by: Eliza Weisman <[email protected]>
1 parent cc7d305 commit 1b9af22

File tree

24 files changed

+477
-482
lines changed

24 files changed

+477
-482
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- stable
4040
- beta
4141
- nightly
42-
- 1.39.0
42+
- 1.45.2
4343

4444
os:
4545
- ubuntu-latest

Cargo.toml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
[package]
23
name = "hyper"
34
version = "0.14.0-dev" # don't forget to update html_root_url
@@ -30,12 +31,12 @@ http = "0.2"
3031
http-body = "0.3.1"
3132
httpdate = "0.3"
3233
httparse = "1.0"
33-
h2 = "0.2.2"
34+
h2 = { git = "https://github.com/hyperium/h2" }
3435
itoa = "0.4.1"
3536
tracing = { version = "0.1", default-features = false, features = ["log", "std"] }
3637
pin-project = "1.0"
3738
tower-service = "0.3"
38-
tokio = { version = "0.2.11", features = ["sync"] }
39+
tokio = { version = "0.3", features = ["sync", "stream"] }
3940
want = "0.3"
4041

4142
# Optional
@@ -51,9 +52,18 @@ spmc = "0.3"
5152
serde = "1.0"
5253
serde_derive = "1.0"
5354
serde_json = "1.0"
54-
tokio = { version = "0.2.2", features = ["fs", "macros", "io-std", "rt-util", "sync", "time", "test-util"] }
55-
tokio-test = "0.2"
56-
tokio-util = { version = "0.3", features = ["codec"] }
55+
tokio = { version = "0.3", features = [
56+
"fs",
57+
"macros",
58+
"io-std",
59+
"rt",
60+
"rt-multi-thread", # so examples can use #[tokio::main]
61+
"sync",
62+
"time",
63+
"test-util",
64+
] }
65+
tokio-test = "0.3"
66+
tokio-util = { version = "0.4", features = ["codec"] }
5767
tower-util = "0.3"
5868
url = "1.0"
5969

@@ -67,12 +77,12 @@ default = [
6777
]
6878
runtime = [
6979
"tcp",
70-
"tokio/rt-core",
80+
"tokio/rt",
7181
]
7282
tcp = [
7383
"socket2",
74-
"tokio/blocking",
75-
"tokio/tcp",
84+
"tokio/net",
85+
"tokio/rt",
7686
"tokio/time",
7787
]
7888

@@ -219,4 +229,3 @@ required-features = ["runtime", "stream"]
219229
name = "server"
220230
path = "tests/server.rs"
221231
required-features = ["runtime"]
222-

benches/body.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use hyper::body::Body;
1010

1111
macro_rules! bench_stream {
1212
($bencher:ident, bytes: $bytes:expr, count: $count:expr, $total_ident:ident, $body_pat:pat, $block:expr) => {{
13-
let mut rt = tokio::runtime::Builder::new()
14-
.basic_scheduler()
13+
let rt = tokio::runtime::Builder::new_current_thread()
1514
.build()
1615
.expect("rt build");
1716

benches/connect.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ use tokio::net::TcpListener;
1212
#[bench]
1313
fn http_connector(b: &mut test::Bencher) {
1414
let _ = pretty_env_logger::try_init();
15-
let mut rt = tokio::runtime::Builder::new()
15+
let rt = tokio::runtime::Builder::new_current_thread()
1616
.enable_all()
17-
.basic_scheduler()
1817
.build()
1918
.expect("rt build");
20-
let mut listener = rt
19+
let listener = rt
2120
.block_on(TcpListener::bind(&SocketAddr::from(([127, 0, 0, 1], 0))))
2221
.expect("bind");
2322
let addr = listener.local_addr().expect("local_addr");

benches/end_to_end.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,16 @@ impl Opts {
270270
}
271271

272272
fn bench(self, b: &mut test::Bencher) {
273+
use std::sync::Arc;
273274
let _ = pretty_env_logger::try_init();
274275
// Create a runtime of current thread.
275-
let mut rt = tokio::runtime::Builder::new()
276-
.enable_all()
277-
.basic_scheduler()
278-
.build()
279-
.expect("rt build");
280-
let exec = rt.handle().clone();
276+
let rt = Arc::new(
277+
tokio::runtime::Builder::new_current_thread()
278+
.enable_all()
279+
.build()
280+
.expect("rt build"),
281+
);
282+
let exec = rt.clone();
281283

282284
let req_len = self.request_body.map(|b| b.len()).unwrap_or(0) as u64;
283285
let req_len = if self.request_chunks > 0 {
@@ -288,7 +290,7 @@ impl Opts {
288290
let bytes_per_iter = (req_len + self.response_body.len() as u64) * self.parallel_cnt as u64;
289291
b.bytes = bytes_per_iter;
290292

291-
let addr = spawn_server(&mut rt, &self);
293+
let addr = spawn_server(&rt, &self);
292294

293295
let connector = HttpConnector::new();
294296
let client = hyper::Client::builder()
@@ -351,7 +353,7 @@ impl Opts {
351353
}
352354
}
353355

354-
fn spawn_server(rt: &mut tokio::runtime::Runtime, opts: &Opts) -> SocketAddr {
356+
fn spawn_server(rt: &tokio::runtime::Runtime, opts: &Opts) -> SocketAddr {
355357
use hyper::service::{make_service_fn, service_fn};
356358
let addr = "127.0.0.1:0".parse().unwrap();
357359

benches/pipeline.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ fn hello_world(b: &mut test::Bencher) {
3131
}))
3232
});
3333

34-
let mut rt = tokio::runtime::Builder::new()
34+
let rt = tokio::runtime::Builder::new_current_thread()
3535
.enable_all()
36-
.basic_scheduler()
3736
.build()
3837
.expect("rt build");
3938
let srv = rt.block_on(async move {

benches/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ macro_rules! bench_server {
3434
}))
3535
});
3636

37-
let mut rt = tokio::runtime::Builder::new()
37+
let rt = tokio::runtime::Builder::new_current_thread()
3838
.enable_all()
39-
.basic_scheduler()
4039
.build()
4140
.expect("rt build");
4241

@@ -185,6 +184,7 @@ fn raw_tcp_throughput_large_payload(b: &mut test::Bencher) {
185184
let mut buf = [0u8; 8192];
186185
while rx.try_recv().is_err() {
187186
let r = sock.read(&mut buf).unwrap();
187+
extern crate test;
188188
if r == 0 {
189189
break;
190190
}

examples/single_threaded.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ fn main() {
1010
pretty_env_logger::init();
1111

1212
// Configure a runtime that runs everything on the current thread
13-
let mut rt = tokio::runtime::Builder::new()
13+
let rt = tokio::runtime::Builder::new_current_thread()
1414
.enable_all()
15-
.basic_scheduler()
1615
.build()
1716
.expect("build runtime");
1817

1918
// Combine it with a `LocalSet, which means it can spawn !Send futures...
2019
let local = tokio::task::LocalSet::new();
21-
local.block_on(&mut rt, run());
20+
local.block_on(&rt, run());
2221
}
2322

2423
async fn run() {

0 commit comments

Comments
 (0)