Browse Source

Add basic benchmarks for Gotham/Rust (#3886)

* Add base benchmarks for Gotham

* Fix a bad binary name in the Dockerfile

* Remove bad copy clause from Dockerfile

* Add a README containing implemented tests
Isaac Whitfield 7 years ago
parent
commit
c951de5cb6

+ 17 - 0
frameworks/Rust/gotham/Cargo.toml

@@ -0,0 +1,17 @@
+[package]
+name = "gotham_techempower"
+version = "0.1.0"
+authors = ["Isaac Whitfield <[email protected]>"]
+
+[dependencies]
+gotham = "0.2"
+hyper = "0.11"
+mime = "0.3"
+serde = "1.0"
+serde_derive = "1.0"
+serde_json = "1.0"
+
+[profile.release]
+codegen-units = 1
+opt-level = 3
+lto = true

+ 15 - 0
frameworks/Rust/gotham/README.md

@@ -0,0 +1,15 @@
+# Gotham Benchmarking Test
+
+### Test Type Implementation Source Code
+
+* [JSON](src/main.rs)
+* [PLAINTEXT](src/main.rs)
+
+## Test URLs
+### JSON
+
+http://localhost:8080/json
+
+### PLAINTEXT
+
+http://localhost:8080/plaintext

+ 26 - 0
frameworks/Rust/gotham/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+  "framework": "gotham",
+  "tests": [
+    {
+      "default": {
+        "json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "None",
+        "framework": "Gotham",
+        "language": "Rust",
+        "flavor": "None",
+        "orm": "None",
+        "platform": "Rust",
+        "webserver": "Hyper",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Gotham",
+        "notes": "",
+        "versus": "None"
+      }
+    }
+  ]
+}

+ 10 - 0
frameworks/Rust/gotham/gotham.dockerfile

@@ -0,0 +1,10 @@
+FROM rust:1.26
+
+WORKDIR /gotham
+COPY ./src ./src
+COPY ./Cargo.toml ./Cargo.toml
+
+ENV RUSTFLAGS "-C target-cpu=native"
+RUN cargo build --release
+
+CMD ["./target/release/gotham_techempower"]

+ 56 - 0
frameworks/Rust/gotham/src/main.rs

@@ -0,0 +1,56 @@
+extern crate gotham;
+extern crate hyper;
+extern crate mime;
+extern crate serde;
+extern crate serde_json;
+#[macro_use]
+extern crate serde_derive;
+
+use gotham::http::response::create_response;
+use gotham::router::builder::*;
+use gotham::state::State;
+use hyper::{header, Response, StatusCode};
+
+static HELLO_WORLD: &'static [u8] = b"Hello, world!";
+
+#[derive(Serialize)]
+struct Message<'a> {
+    message: &'a str,
+}
+
+fn json(state: State) -> (State, Response) {
+    let message = Message {
+        message: "Hello, World!",
+    };
+
+    let body = serde_json::to_vec(&message).unwrap();
+    let mut res = create_response(&state, StatusCode::Ok, Some((body, mime::APPLICATION_JSON)));
+
+    res.headers_mut().set(header::Server::new("Gotham"));
+
+    (state, res)
+}
+
+fn plaintext(state: State) -> (State, Response) {
+    let mut res = create_response(
+        &state,
+        StatusCode::Ok,
+        Some((HELLO_WORLD.to_vec(), mime::TEXT_PLAIN)),
+    );
+
+    res.headers_mut().set(header::Server::new("Gotham"));
+
+    (state, res)
+}
+
+pub fn main() {
+    let addr = "0.0.0.0:8080";
+    println!("Listening for requests at http://{}", addr);
+
+    let router = build_simple_router(|route| {
+        route.get("/plaintext").to(plaintext);
+        route.get("/json").to(json);
+    });
+
+    gotham::start(addr, router)
+}