Browse Source

hyper: update to newer server dispatcher (#3705)

Sean McArthur 7 years ago
parent
commit
e51fe7f8f4

+ 1 - 2
frameworks/Rust/hyper/Cargo.toml

@@ -9,7 +9,7 @@ authors = [
 
 
 [dependencies]
 [dependencies]
 futures = "0.1"
 futures = "0.1"
-hyper = { version = "0.11.24" } #, default-features = false }
+hyper = { version = "0.11.26", default-features = false }
 num_cpus = "1.2"
 num_cpus = "1.2"
 serde = "1.0"
 serde = "1.0"
 serde_json = "1.0"
 serde_json = "1.0"
@@ -17,7 +17,6 @@ serde_derive = "1.0"
 #tokio = "0.1"
 #tokio = "0.1"
 tokio-core = "=0.1.11"
 tokio-core = "=0.1.11"
 tokio-io = "=0.1.4"
 tokio-io = "=0.1.4"
-tokio-proto = "0.1"
 
 
 [profile.release]
 [profile.release]
 opt-level = 3
 opt-level = 3

+ 1 - 16
frameworks/Rust/hyper/benchmark_config.json

@@ -2,6 +2,7 @@
   "framework": "hyper",
   "framework": "hyper",
   "tests": [{
   "tests": [{
     "default": {
     "default": {
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "json_url": "/json",
       "port": 8080,
       "port": 8080,
       "approach": "Realistic",
       "approach": "Realistic",
@@ -16,22 +17,6 @@
       "database_os": "Linux",
       "database_os": "Linux",
       "display_name": "hyper",
       "display_name": "hyper",
       "notes": ""
       "notes": ""
-    },
-    "pipeline": {
-      "plaintext_url": "/plaintext",
-      "port": 8080,
-      "approach": "Realistic",
-      "classification": "Micro",
-      "database": "Postgres",
-      "framework": "hyper",
-      "language": "Rust",
-      "orm": "Raw",
-      "platform": "Rust",
-      "webserver": "hyper",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "hyper-pipeline",
-      "notes": ""
     }
     }
   }]
   }]
 }
 }

+ 0 - 9
frameworks/Rust/hyper/hyper-pipeline.dockerfile

@@ -1,9 +0,0 @@
-FROM rust:1.25
-
-ADD ./ /hyper
-WORKDIR /hyper
-
-RUN cargo clean
-RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
-
-CMD ["./target/release/hyper-techempower", "pipeline"]

+ 1 - 1
frameworks/Rust/hyper/hyper.dockerfile

@@ -6,4 +6,4 @@ WORKDIR /hyper
 RUN cargo clean
 RUN cargo clean
 RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
 RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
 
 
-CMD ["./target/release/hyper-techempower"]
+CMD ["./target/release/hyper-techempower", "pipeline"]

+ 11 - 10
frameworks/Rust/hyper/src/main.rs

@@ -5,7 +5,6 @@ extern crate num_cpus;
 extern crate serde_derive;
 extern crate serde_derive;
 extern crate serde_json;
 extern crate serde_json;
 //extern crate tokio;
 //extern crate tokio;
-extern crate tokio_proto;
 
 
 use std::env;
 use std::env;
 use std::net::SocketAddr;
 use std::net::SocketAddr;
@@ -19,9 +18,8 @@ use hyper::StatusCode::NotFound;
 use hyper::server::{Http, Service, Request, Response};
 use hyper::server::{Http, Service, Request, Response};
 
 
 //use tokio::net::TcpListener;
 //use tokio::net::TcpListener;
-use tokio_proto::TcpServer;
 
 
-static HELLOWORLD: &'static [u8] = b"Hello, world!";
+static HELLO_WORLD: &'static [u8] = b"Hello, world!";
 
 
 #[derive(Serialize)]
 #[derive(Serialize)]
 struct JsonResponse<'a> {
 struct JsonResponse<'a> {
@@ -40,9 +38,9 @@ impl Service for TechEmpower {
         let response = match (req.method(), req.path()) {
         let response = match (req.method(), req.path()) {
             (&Get, "/plaintext") => {
             (&Get, "/plaintext") => {
                 Response::new()
                 Response::new()
-                    .with_header(ContentLength(HELLOWORLD.len() as u64))
+                    .with_header(ContentLength(HELLO_WORLD.len() as u64))
                     .with_header(ContentType::text())
                     .with_header(ContentType::text())
-                    .with_body(HELLOWORLD)
+                    .with_body(HELLO_WORLD)
             }
             }
             (&Get, "/json") => {
             (&Get, "/json") => {
                 let rep = JsonResponse { message: "Hello, world!" };
                 let rep = JsonResponse { message: "Hello, world!" };
@@ -54,7 +52,7 @@ impl Service for TechEmpower {
             }
             }
             _ => Response::new().with_status(NotFound),
             _ => Response::new().with_status(NotFound),
         };
         };
-        future::ok(response.with_header(Server::new("Hyper")))
+        future::ok(response.with_header(Server::new("hyper")))
     }
     }
 }
 }
 
 
@@ -89,11 +87,14 @@ fn main() {
     // Bind to 0.0.0.0:8080
     // Bind to 0.0.0.0:8080
     let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
     let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
 
 
-    let mut srv = TcpServer::new(http, addr);
-    srv.threads(num_cpus::get());
+    let srv = http
+        .bind(&addr, || Ok(TechEmpower))
+        .expect("bind to address");
 
 
-    println!("Listening on http://{}", addr);
-    srv.serve(|| Ok(TechEmpower));
+    println!("Listening on http://{}", srv.local_addr().unwrap());
+
+    // Use newer hyper dispatcher
+    srv.run_threads(num_cpus::get());
 }
 }
 
 
 /* This is the future, but there's still a few blockers in new tokio,
 /* This is the future, but there's still a few blockers in new tokio,