From 4806c62ca10996aedc20dc7165d73031bea3a93b Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Fri, 3 Mar 2017 22:26:29 -0800 Subject: [PATCH] reuse reqwest client in serve_camera_html bench This makes a huge difference in the reported time - 863 usec rather than 6 milliseconds on my laptop. Part of the difference is in reqwest client setup (it apparently initializes a SSL_CTX that is never used in this test), part fresh connections vs keepalive, part I don't know what. None of it seems relevant to the logic I want to test. --- Cargo.lock | 9 ++++++++- Cargo.toml | 1 + src/web.rs | 8 +++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6891542..8b10587 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,7 +267,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/scottlamb/hyper?branch=moonfire-on-0.10.x#601e52f7decfbe4b34f278058383f774fba7cb4f" dependencies = [ "httparse 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -283,6 +283,12 @@ dependencies = [ "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hyper" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +replace = "hyper 0.10.5 (git+https://github.com/scottlamb/hyper?branch=moonfire-on-0.10.x)" + [[package]] name = "hyper" version = "0.11.0-a.0" @@ -1230,6 +1236,7 @@ dependencies = [ "checksum gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0912515a8ff24ba900422ecda800b52f4016a56251922d397c576bf92c690518" "checksum http-entity 0.0.1 (git+https://github.com/scottlamb/http-entity?branch=hyper-0.11.x)" = "" "checksum httparse 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a6e7a63e511f9edffbab707141fbb8707d1a3098615fb2adbd5769cdfcc9b17d" +"checksum hyper 0.10.5 (git+https://github.com/scottlamb/hyper?branch=moonfire-on-0.10.x)" = "" "checksum hyper 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)" = "43a15e3273b2133aaac0150478ab443fb89f15c3de41d8d93d8f3bb14bf560f6" "checksum hyper 0.11.0-a.0 (git+https://github.com/hyperium/hyper)" = "" "checksum hyper 0.11.0-a.0 (git+https://github.com/scottlamb/hyper?branch=moonfire-on-0.11.x)" = "" diff --git a/Cargo.toml b/Cargo.toml index 820191a..a47cf6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,3 +72,4 @@ debug = true [replace] "https://github.com/hyperium/hyper#hyper:0.11.0-a.0" = { git = "https://github.com/scottlamb/hyper", branch = "moonfire-on-0.11.x" } +"hyper:0.10.5" = { git = "https://github.com/scottlamb/hyper", branch = "moonfire-on-0.10.x" } diff --git a/src/web.rs b/src/web.rs index 351016e..bf69b50 100644 --- a/src/web.rs +++ b/src/web.rs @@ -652,13 +652,15 @@ mod bench { let url = reqwest::Url::parse(&format!("{}/cameras/{}/", server.base_url, *testutil::TEST_CAMERA_UUID)).unwrap(); let mut buf = Vec::new(); - b.iter(|| { - let client = reqwest::Client::new().unwrap(); + let client = reqwest::Client::new().unwrap(); + let mut f = || { let mut resp = client.get(url.clone()).send().unwrap(); assert_eq!(*resp.status(), reqwest::StatusCode::Ok); buf.clear(); use std::io::Read; resp.read_to_end(&mut buf).unwrap(); - }); + }; + f(); // warm. + b.iter(f); } }