Skip to content

Commit

Permalink
Tokio 0.3 Upgrade (#2319)
Browse files Browse the repository at this point in the history
Co-authored-by: Urhengulas <johann.hemmann@code.berlin>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
3 people committed Nov 6, 2020
1 parent cc7d305 commit 1b9af22
Show file tree
Hide file tree
Showing 24 changed files with 477 additions and 482 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Expand Up @@ -39,7 +39,7 @@ jobs:
- stable
- beta
- nightly
- 1.39.0
- 1.45.2

os:
- ubuntu-latest
Expand Down
27 changes: 18 additions & 9 deletions Cargo.toml
@@ -1,3 +1,4 @@

[package]
name = "hyper"
version = "0.14.0-dev" # don't forget to update html_root_url
Expand Down Expand Up @@ -30,12 +31,12 @@ http = "0.2"
http-body = "0.3.1"
httpdate = "0.3"
httparse = "1.0"
h2 = "0.2.2"
h2 = { git = "https://github.com/hyperium/h2" }
itoa = "0.4.1"
tracing = { version = "0.1", default-features = false, features = ["log", "std"] }
pin-project = "1.0"
tower-service = "0.3"
tokio = { version = "0.2.11", features = ["sync"] }
tokio = { version = "0.3", features = ["sync", "stream"] }
want = "0.3"

# Optional
Expand All @@ -51,9 +52,18 @@ spmc = "0.3"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
tokio = { version = "0.2.2", features = ["fs", "macros", "io-std", "rt-util", "sync", "time", "test-util"] }
tokio-test = "0.2"
tokio-util = { version = "0.3", features = ["codec"] }
tokio = { version = "0.3", features = [
"fs",
"macros",
"io-std",
"rt",
"rt-multi-thread", # so examples can use #[tokio::main]
"sync",
"time",
"test-util",
] }
tokio-test = "0.3"
tokio-util = { version = "0.4", features = ["codec"] }
tower-util = "0.3"
url = "1.0"

Expand All @@ -67,12 +77,12 @@ default = [
]
runtime = [
"tcp",
"tokio/rt-core",
"tokio/rt",
]
tcp = [
"socket2",
"tokio/blocking",
"tokio/tcp",
"tokio/net",
"tokio/rt",
"tokio/time",
]

Expand Down Expand Up @@ -219,4 +229,3 @@ required-features = ["runtime", "stream"]
name = "server"
path = "tests/server.rs"
required-features = ["runtime"]

3 changes: 1 addition & 2 deletions benches/body.rs
Expand Up @@ -10,8 +10,7 @@ use hyper::body::Body;

macro_rules! bench_stream {
($bencher:ident, bytes: $bytes:expr, count: $count:expr, $total_ident:ident, $body_pat:pat, $block:expr) => {{
let mut rt = tokio::runtime::Builder::new()
.basic_scheduler()
let rt = tokio::runtime::Builder::new_current_thread()
.build()
.expect("rt build");

Expand Down
5 changes: 2 additions & 3 deletions benches/connect.rs
Expand Up @@ -12,12 +12,11 @@ use tokio::net::TcpListener;
#[bench]
fn http_connector(b: &mut test::Bencher) {
let _ = pretty_env_logger::try_init();
let mut rt = tokio::runtime::Builder::new()
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.basic_scheduler()
.build()
.expect("rt build");
let mut listener = rt
let listener = rt
.block_on(TcpListener::bind(&SocketAddr::from(([127, 0, 0, 1], 0))))
.expect("bind");
let addr = listener.local_addr().expect("local_addr");
Expand Down
18 changes: 10 additions & 8 deletions benches/end_to_end.rs
Expand Up @@ -270,14 +270,16 @@ impl Opts {
}

fn bench(self, b: &mut test::Bencher) {
use std::sync::Arc;
let _ = pretty_env_logger::try_init();
// Create a runtime of current thread.
let mut rt = tokio::runtime::Builder::new()
.enable_all()
.basic_scheduler()
.build()
.expect("rt build");
let exec = rt.handle().clone();
let rt = Arc::new(
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("rt build"),
);
let exec = rt.clone();

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

let addr = spawn_server(&mut rt, &self);
let addr = spawn_server(&rt, &self);

let connector = HttpConnector::new();
let client = hyper::Client::builder()
Expand Down Expand Up @@ -351,7 +353,7 @@ impl Opts {
}
}

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

Expand Down
3 changes: 1 addition & 2 deletions benches/pipeline.rs
Expand Up @@ -31,9 +31,8 @@ fn hello_world(b: &mut test::Bencher) {
}))
});

let mut rt = tokio::runtime::Builder::new()
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.basic_scheduler()
.build()
.expect("rt build");
let srv = rt.block_on(async move {
Expand Down
4 changes: 2 additions & 2 deletions benches/server.rs
Expand Up @@ -34,9 +34,8 @@ macro_rules! bench_server {
}))
});

let mut rt = tokio::runtime::Builder::new()
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.basic_scheduler()
.build()
.expect("rt build");

Expand Down Expand Up @@ -185,6 +184,7 @@ fn raw_tcp_throughput_large_payload(b: &mut test::Bencher) {
let mut buf = [0u8; 8192];
while rx.try_recv().is_err() {
let r = sock.read(&mut buf).unwrap();
extern crate test;
if r == 0 {
break;
}
Expand Down
5 changes: 2 additions & 3 deletions examples/single_threaded.rs
Expand Up @@ -10,15 +10,14 @@ fn main() {
pretty_env_logger::init();

// Configure a runtime that runs everything on the current thread
let mut rt = tokio::runtime::Builder::new()
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.basic_scheduler()
.build()
.expect("build runtime");

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

async fn run() {
Expand Down

0 comments on commit 1b9af22

Please sign in to comment.