Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 64 additions & 22 deletions frameworks/wtx-grpc-tls/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frameworks/wtx-grpc-tls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pb-rs = { default-features = false, version = "0.10" }
[dependencies]
quick-protobuf = { default-features = false, version = "0.8" }
tokio = { default-features = false, features = ["macros", "rt-multi-thread"], version = "1.0" }
wtx = { default-features = false, features = ["crypto-ring", "grpc-server", "optimizations-std", "quick-protobuf", "tokio", "getrandom"], version = "0.48" }
wtx = { default-features = false, features = ["crypto-ring", "grpc-server", "optimizations-std", "quick-protobuf", "secret-0", "tokio", "getrandom"], version = "0.51" }

[profile.release]
codegen-units = 1
Expand Down
1 change: 1 addition & 0 deletions frameworks/wtx-grpc-tls/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"repo": "https://github.com/c410-f3r/wtx",
"enabled": true,
"tests": [
"stream-grpc-tls",
"unary-grpc-tls"
]
}
6 changes: 6 additions & 0 deletions frameworks/wtx-grpc-tls/proto/benchmark.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ message SumRequest {
int32 b = 2;
}

message StreamRequest {
int32 a = 1;
int32 b = 2;
int32 count = 3;
}

message SumReply {
int32 result = 1;
}
37 changes: 30 additions & 7 deletions frameworks/wtx-grpc-tls/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,60 @@
pub mod grpc_bindings;

use grpc_bindings::benchmark::{SumReply, SumRequest};
use grpc_bindings::benchmark::{StreamRequest, SumReply, SumRequest};
use tokio::net::tcp::OwnedWriteHalf;
use wtx::{
codec::format::QuickProtobuf,
grpc::{GrpcManager, GrpcMiddleware},
http::{
HttpRecvParams,
HttpRecvParams, ManualStream,
http2_server_framework::{Http2ServerFramework, HttpRouter, State, post},
},
http2::{Http2RecvStatus, ServerStream},
misc::SecretContext,
rng::{ChaCha20, CryptoSeedableRng},
tls::{TlsConfig, TlsModeVerified},
};

fn main() -> wtx::Result<()> {
let cert_path = wtx::misc::var("TLS_CERT").unwrap_or_else(|_| "/certs/server.crt".to_string());
let key_path = wtx::misc::var("TLS_KEY").unwrap_or_else(|_| "/certs/server.key".to_string());
let cert_file = std::fs::read_to_string(&cert_path)?.into_bytes();
let key_file = std::fs::read_to_string(&key_path)?.into_bytes();
let tls_config = TlsConfig::from_keys_pem(TlsModeVerified::new(), &cert_file, &key_file)?;
let mut key_file = std::fs::read_to_string(&key_path)?.into_bytes();
let mut rng = ChaCha20::from_std_random()?;
let secret_context = SecretContext::new(&mut rng)?;
let tls_config = TlsConfig::from_keys_pem(&cert_file, &mut rng, (secret_context, &mut key_file))?;
let router = HttpRouter::new(
wtx::paths!(("/benchmark.BenchmarkService/GetSum", post(endpoint_grpc_unary))),
wtx::paths!(
("/benchmark.BenchmarkService/GetSum", post(endpoint_grpc_unary)),
("/benchmark.BenchmarkService/StreamSum", post(endpoint_grpc_stream))
),
GrpcMiddleware,
)?;
Http2ServerFramework::tokio(tls_config)?
.set_data(GrpcManager::from_drsr(QuickProtobuf))
.set_error_cb(|el| eprintln!("{el}"))
.set_http_recv_params(HttpRecvParams::with_permissive_params())
.run_in_threads("0.0.0.0:8443", router)
}

async fn endpoint_grpc_unary(state: State<'_, GrpcManager<QuickProtobuf>>) -> wtx::Result<()> {
let sr = state.data.des_from_req_bytes::<SumRequest>(&mut state.req.msg_data.body.as_slice())?;
let sr = state.data.des_from_req_bytes::<SumRequest>(state.req.msg_data.body.as_slice())?;
state.req.clear();
let result = sr.a.wrapping_add(sr.b);
state.data.ser_to_res_bytes(&mut state.req.msg_data.body, SumReply { result })?;
Ok(())
}

async fn endpoint_grpc_stream(
mut ms: ManualStream<GrpcManager<QuickProtobuf>, ServerStream<OwnedWriteHalf, TlsModeVerified>>,
) -> wtx::Result<()> {
let mut common = ms.stream.common();
let Http2RecvStatus::Eos(mut bytes) = common.recv_data(|_| Ok(())).await? else {
panic!();
};
let sr = ms.data.des_from_req_bytes::<StreamRequest>(bytes.as_slice())?;
bytes.clear();
let result = sr.a.wrapping_add(sr.b);
ms.data.ser_to_res_bytes(&mut bytes, SumReply { result })?;
common.send_data_concurrent::<_, 5000>((0..sr.count).map(|_| &bytes[..])).await?;
Ok(())
}
47 changes: 33 additions & 14 deletions site/data/results/wtx.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,25 @@
"status_4xx": 0,
"status_5xx": 0
},
"stream-grpc-tls-64": {
"framework": "wtx",
"language": "Rust",
"rps": 0,
"avg_latency": "4.89s",
"p99_latency": "0ns",
"cpu": "81.5%",
"memory": "146MiB",
"connections": 64,
"threads": 64,
"duration": "5s",
"pipeline": 1,
"bandwidth": "0",
"reconnects": 0,
"status_2xx": 0,
"status_3xx": 0,
"status_4xx": 0,
"status_5xx": 4
},
"unary-grpc-1024": {
"framework": "wtx",
"language": "Rust",
Expand Down Expand Up @@ -289,37 +308,37 @@
"unary-grpc-tls-1024": {
"framework": "wtx",
"language": "Rust",
"rps": 2371712,
"avg_latency": "39.56ms",
"p99_latency": "1.17s",
"cpu": "6417.3%",
"memory": "904MiB",
"rps": 2105996,
"avg_latency": "46.39ms",
"p99_latency": "1.24s",
"cpu": "5844.4%",
"memory": "2.7GiB",
"connections": 1024,
"threads": 64,
"duration": "5s",
"pipeline": 1,
"bandwidth": "103.02MB/s",
"bandwidth": "91.84MB/s",
"reconnects": 0,
"status_2xx": 12000866,
"status_2xx": 10698462,
"status_3xx": 0,
"status_4xx": 0,
"status_5xx": 0
},
"unary-grpc-tls-256": {
"framework": "wtx",
"language": "Rust",
"rps": 2409735,
"avg_latency": "10.27ms",
"p99_latency": "328.46ms",
"cpu": "6207.2%",
"memory": "542MiB",
"rps": 2295308,
"avg_latency": "11.02ms",
"p99_latency": "335.80ms",
"cpu": "6168.8%",
"memory": "1.8GiB",
"connections": 256,
"threads": 64,
"duration": "5s",
"pipeline": 1,
"bandwidth": "104.25MB/s",
"bandwidth": "99.30MB/s",
"reconnects": 0,
"status_2xx": 12145065,
"status_2xx": 11568355,
"status_3xx": 0,
"status_4xx": 0,
"status_5xx": 0
Expand Down
Empty file.
Loading