forked from LesnyRumcajs/grpc_bench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request LesnyRumcajs#96 from trezm/feat/add_mt_and_st_for_…
…thruster Add multi and single threaded thruster examples
- Loading branch information
Showing
12 changed files
with
118 additions
and
1,453 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM rust:1.44.1-stretch | ||
|
||
WORKDIR /app | ||
COPY rust_thruster_mt_bench /app | ||
COPY proto /app/proto | ||
|
||
RUN rustup component add rustfmt --toolchain 1.44.1-x86_64-unknown-linux-gnu | ||
|
||
RUN cat Cargo.toml | ||
RUN cargo build --release | ||
RUN cargo build --release | ||
|
||
ENTRYPOINT cargo run --release |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[package] | ||
name = "rust_thruster" | ||
version = "0.1.0" | ||
authors = ["trezm <[email protected]>"] | ||
edition = "2018" | ||
|
||
[profile.release] | ||
opt-level = 3 | ||
codegen-units = 1 | ||
lto = true | ||
|
||
[dependencies] | ||
async-trait = "0.1" | ||
bytes = "0.5.3" | ||
dotenv = "0.13.0" | ||
env_logger = "0.7.1" | ||
log = "0.4" | ||
hyper = "0.13.1" | ||
http = "0.2" | ||
http-body = "0.3.1" | ||
prost = "0.6" | ||
thruster = { version = "1.0.0", features = ["hyper_server"] } | ||
thruster-grpc = { git = "https://github.com/thruster-rs/thruster-grpc" } | ||
tokio = { version = "0.2", features = ["full"] } | ||
|
||
futures = "0.3.5" | ||
|
||
[build-dependencies] | ||
prost-build = "0.6" | ||
|
||
[[bin]] | ||
name = "helloworld-server" | ||
path = "src/main.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM rust:1.44.1-stretch | ||
|
||
WORKDIR /app | ||
COPY rust_thruster_st_bench /app | ||
COPY proto /app/proto | ||
|
||
RUN rustup component add rustfmt --toolchain 1.44.1-x86_64-unknown-linux-gnu | ||
RUN cargo build --release | ||
RUN cargo build --release | ||
|
||
ENTRYPOINT cargo run --release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
prost_build::compile_protos(&["proto/helloworld/helloworld.proto"], &["proto/"]).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use dotenv::dotenv; | ||
use log::info; | ||
use std::env; | ||
use thruster::context::hyper_request::HyperRequest; | ||
use thruster::{async_middleware, middleware_fn}; | ||
use thruster::{App, ThrusterServer}; | ||
use thruster::{MiddlewareNext, MiddlewareResult}; | ||
use thruster_grpc::context::{generate_context, ProtoContext as Ctx}; | ||
use thruster_grpc::server::ProtoServer; | ||
use thruster_grpc::util::{context_to_message, message_to_context}; | ||
|
||
mod hello_world { | ||
include!(concat!(env!("OUT_DIR"), "/helloworld.rs")); | ||
} | ||
|
||
#[middleware_fn] | ||
pub async fn say_hello(mut context: Ctx, _next: MiddlewareNext<Ctx>) -> MiddlewareResult<Ctx> { | ||
let hello_world_request = context_to_message::<hello_world::HelloRequest>(&mut context) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(message_to_context( | ||
context, | ||
hello_world::HelloReply { | ||
message: hello_world_request.name, | ||
}, | ||
) | ||
.await) | ||
} | ||
|
||
#[tokio::main(core_threads = 1)] | ||
async fn main() { | ||
let _ = dotenv(); | ||
|
||
env_logger::init(); | ||
|
||
let host = env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string()); | ||
let port = env::var("PORT").unwrap_or_else(|_| "50051".to_string()); | ||
|
||
info!("Starting server at {}:{}!", host, port); | ||
|
||
let mut app = App::<HyperRequest, Ctx, ()>::create(generate_context, ()); | ||
app.post( | ||
"/helloworld.Greeter/SayHello", | ||
async_middleware!(Ctx, [say_hello]), | ||
); | ||
|
||
ProtoServer::new(app).build(&host, port.parse::<u16>().unwrap()).await; | ||
} |