Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(grpc): grpc优化调整 #49

Merged
merged 4 commits into from
Jul 9, 2024
Merged
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
4 changes: 2 additions & 2 deletions examples/candle_whisper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bindgen_cuda = { version = "0.1.5", optional = true }


[dependencies]
clap = { version = "4.5.7", features = ["derive"] }
clap = { version = "4.5.8", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
silent = { path = "../../silent", features = ["multipart"] }
symphonia = { version = "0.5.4", features = ["all"] }
Expand All @@ -38,5 +38,5 @@ candle-transformers = { git = "https://github.com/huggingface/candle" }

tokenizers = { version = "0.19.1", features = ["onig"] }
rand = "0.8.5"
serde_json = "1.0.117"
serde_json = "1.0.120"
byteorder = "1.5.0"
2 changes: 1 addition & 1 deletion examples/configs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
async-trait = "0.1.80"
async-trait = "0.1.81"
2 changes: 1 addition & 1 deletion examples/custom_handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
async-trait = "0.1.80"
async-trait = "0.1.81"
2 changes: 1 addition & 1 deletion examples/custom_tokio_listener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
async-trait = "0.1.80"
async-trait = "0.1.81"
tokio = { version = "1.38.0", features = ["full"] }
2 changes: 1 addition & 1 deletion examples/custom_tokio_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
async-trait = "0.1.80"
async-trait = "0.1.81"
tokio = { version = "1.38.0", features = ["full"] }
2 changes: 1 addition & 1 deletion examples/exception_handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
serde = { version = "1.0.203", features = ["derive"] }
serde = { version = "1.0.204", features = ["derive"] }
2 changes: 1 addition & 1 deletion examples/form/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
serde = { version = "1.0.203", features = ["derive"] }
serde = { version = "1.0.204", features = ["derive"] }
17 changes: 4 additions & 13 deletions examples/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,11 @@ name = "example-grpc-client"
path = "src/client.rs"

[dependencies]
tonic = { git = "https://github.com/alexrudy/tonic", branch = "hyper-1.0" }
tonic-reflection = { git = "https://github.com/alexrudy/tonic", branch = "hyper-1.0" }
prost = "0.12"
tonic = { version = "0.12.0" }
prost = "0.13"
tokio = { version = "1.38", features = ["macros", "rt-multi-thread"] }
silent = { path = "../../silent", features = ["grpc"] }
axum = "0.7"
async-trait = "0.1.80"
hyper = "1.3.1"
hyper-util = "0.1.5"
bytes = "1.6.0"
pin-project-lite = "0.2.14"
http-body = "1.0.0"
http = "1.1.0"
http-body-util = "0.1.2"
async-trait = "0.1.81"

[build-dependencies]
tonic-build = { git = "https://github.com/alexrudy/tonic", branch = "hyper-1.0" }
tonic-build = { version = "0.12.0" }
14 changes: 8 additions & 6 deletions examples/grpc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use async_trait::async_trait;
use tonic::{Request, Response, Status};

use hello_world::greeter_server::{Greeter, GreeterServer};
use hello_world::{HelloReply, HelloRequest};
use silent::prelude::{logger, HandlerAppend, Level, Route, RouteService, Server};
use tonic::{transport::Server as TonicServer, Request, Response, Status};

mod client;

Expand Down Expand Up @@ -35,12 +36,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let greeter = MyGreeter::default();
logger::fmt().with_max_level(Level::INFO).init();
let greeter_server = GreeterServer::new(greeter);
let grpc = TonicServer::builder()
// Wrap all services in the middleware stack
.add_service(greeter_server)
.into_router();
// let grpc = TonicServer::builder()
// // Wrap all services in the middleware stack
// .add_service(greeter_server)
// .into_router();
let route = Route::new("").get(|_req| async { Ok("hello world") });
let root = route.route().with_grpc(grpc.into());
let root = route.route().with_grpc(greeter_server.into());
println!("route: \n{:?}", root);
Server::new()
.bind("0.0.0.0:50051".parse().unwrap())
.serve(root)
Expand Down
18 changes: 4 additions & 14 deletions examples/grpc_h2c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,11 @@ name = "example-grpc-client"
path = "src/client.rs"

[dependencies]
tonic = { git = "https://github.com/alexrudy/tonic", branch = "hyper-1.0" }
tonic-reflection = { git = "https://github.com/alexrudy/tonic", branch = "hyper-1.0" }
prost = "0.12"
tonic = { version = "0.12.0" }
prost = "0.13"
tokio = { version = "1.38", features = ["macros", "rt-multi-thread"] }
silent = { path = "../../silent", features = ["grpc"] }
axum = "0.7"
async-trait = "0.1.80"
hyper = "1.3.1"
hyper-util = "0.1.5"
bytes = "1.6.0"
pin-project-lite = "0.2.14"
http-body = "1.0.0"
http = "1.1.0"
http-body-util = "0.1.2"
tower = "0.4.13"
async-trait = "0.1.81"

[build-dependencies]
tonic-build = { git = "https://github.com/alexrudy/tonic", branch = "hyper-1.0" }
tonic-build = { version = "0.12.0" }
7 changes: 2 additions & 5 deletions examples/grpc_h2c/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// use tonic::transport::server::TowerToHyperService;
use tonic::{transport::Server, Request, Response, Status};
use tonic::{Request, Response, Status};

use hello_world::greeter_server::{Greeter, GreeterServer};
use hello_world::{HelloReply, HelloRequest};
Expand Down Expand Up @@ -32,11 +32,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let greeter = MyGreeter::default();
logger::fmt().with_max_level(Level::INFO).init();

let grpc = Server::builder()
.add_service(GreeterServer::new(greeter))
.into_router();
let route = Route::new("").get(|_req| async { Ok("hello world") });
let root = route.route().with_grpc(grpc.into());
let root = route.route().with_grpc(GreeterServer::new(greeter).into());
silent::prelude::Server::new()
.bind("0.0.0.0:50051".parse().unwrap())
.serve(root)
Expand Down
17 changes: 4 additions & 13 deletions examples/grpc_streaming/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,13 @@ name = "example-grpc-client"
path = "src/client.rs"

[dependencies]
tonic = { git = "https://github.com/alexrudy/tonic", branch = "hyper-1.0" }
tonic-reflection = { git = "https://github.com/alexrudy/tonic", branch = "hyper-1.0" }
prost = "0.12"
tonic = { version = "0.12.0" }
prost = "0.13"
tokio = { version = "1.38", features = ["macros", "rt-multi-thread"] }
silent = { path = "../../silent", features = ["grpc"] }
axum = "0.7"
async-trait = "0.1.80"
hyper = "1.3.1"
hyper-util = "0.1.5"
bytes = "1.6.0"
pin-project-lite = "0.2.14"
http-body = "1.0.0"
http = "1.1.0"
http-body-util = "0.1.2"
async-trait = "0.1.81"
tokio-stream = "0.1.15"
h2 = "0.4.5"

[build-dependencies]
tonic-build = { git = "https://github.com/alexrudy/tonic", branch = "hyper-1.0" }
tonic-build = { version = "0.12.0" }
22 changes: 10 additions & 12 deletions examples/grpc_streaming/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
use std::{error::Error, io::ErrorKind, pin::Pin, time::Duration};

use tokio::sync::mpsc;
use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt};
use tonic::{Request, Response, Status, Streaming};

use pb::{EchoRequest, EchoResponse};
use silent::prelude::{logger, HandlerAppend, Level, Route, RouteService, Server};

mod client;
Expand All @@ -6,13 +13,6 @@ pub mod pb {
tonic::include_proto!("grpc.examples.echo");
}

use std::{error::Error, io::ErrorKind, pin::Pin, time::Duration};
use tokio::sync::mpsc;
use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt};
use tonic::{transport::Server as TonicServer, Request, Response, Status, Streaming};

use pb::{EchoRequest, EchoResponse};

type EchoResult<T> = Result<Response<T>, Status>;
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send>>;

Expand Down Expand Up @@ -149,12 +149,10 @@ impl pb::echo_server::Echo for EchoServer {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
logger::fmt().with_max_level(Level::INFO).init();
let server = EchoServer {};
let grpc = TonicServer::builder()
// Wrap all services in the middleware stack
.add_service(pb::echo_server::EchoServer::new(server))
.into_router();
let route = Route::new("").get(|_req| async { Ok("hello world") });
let root = route.route().with_grpc(grpc.into());
let root = route
.route()
.with_grpc(pb::echo_server::EchoServer::new(server).into());
Server::new()
.bind("0.0.0.0:50051".parse().unwrap())
.serve(root)
Expand Down
2 changes: 1 addition & 1 deletion examples/middleware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.80"
async-trait = "0.1.81"
silent = { path = "../../silent" }
2 changes: 1 addition & 1 deletion examples/multipart-form/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent", features = ["multipart"] }
serde = { version = "1.0.203", features = ["derive"] }
serde = { version = "1.0.204", features = ["derive"] }
2 changes: 1 addition & 1 deletion examples/sse-chat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ once_cell = "1"
parking_lot = "0.12"
tokio = { version = "1", features = ["macros"] }
tokio-stream = { version = "0.1", features = ["net"] }
serde = { version = "1.0.203", features = ["derive"] }
serde = { version = "1.0.204", features = ["derive"] }
2 changes: 1 addition & 1 deletion examples/templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.203", features = ["derive"] }
serde = { version = "1.0.204", features = ["derive"] }
silent = { path = "../../silent", features = ["template"] }
6 changes: 3 additions & 3 deletions examples/todo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
serde = { version = "1.0.203", features = ["derive"] }
uuid = { version = "1.8.0", features = ["serde", "v4"] }
async-trait = "0.1.80"
serde = { version = "1.0.204", features = ["derive"] }
uuid = { version = "1.9.1", features = ["serde", "v4"] }
async-trait = "0.1.81"
2 changes: 1 addition & 1 deletion examples/websocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.80"
async-trait = "0.1.81"
silent = { path = "../../silent", features = ["upgrade"] }
tokio = { version = "1.38.0", features = ["full"] }
tokio-tungstenite = "0.23.1"
Expand Down
21 changes: 10 additions & 11 deletions silent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ template = ["dep:tera"]
#wasi = ["tokio/sync"]
test = ["tokio/macros", "tokio/rt"]
scheduler = ["dep:cron"]
grpc = ["upgrade", "dep:axum", "dep:tower-service", "dep:pin-project-lite", "dep:pin-project", "dep:tokio-stream"]
grpc = ["upgrade", "dep:tonic", "dep:pin-project-lite", "dep:pin-project", "dep:tokio-stream"]

[dependencies]
# Basic dependencies
thiserror = "1.0.61"
hyper = { version = "1.3.1", features = ["full"] }
hyper-util = { version = "0.1.5", features = ["server-auto", "tokio"] }
hyper = { version = "1.4.0", features = ["full"] }
hyper-util = { version = "0.1.6", features = ["server-auto", "tokio"] }
tokio = { version = "1.38.0", optional = true }
bytes = "1.6.0"
http-body-util = "0.1.2"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["chrono"] }
async-trait = "0.1.80"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
uuid = "1.8.0"
tracing-subscriber = { version = "0.3.18", features = ["local-time"] }
async-trait = "0.1.81"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.120"
uuid = "1.9.1"
url = "2.5.2"
serde_urlencoded = "0.7.1"
mime = "0.3.17"
Expand Down Expand Up @@ -80,13 +80,12 @@ async-session = { version = "3.0.0", optional = true }
cookie = { version = "0.18.1", features = ["secure", "percent-encode"], optional = true }

# Grpc
axum = { version = "0.7.5", optional = true }
tower-service = { version = "0.3.2", optional = true }
tonic = { version = "0.12.0", optional = true }

# Security
argon2 = { version = "0.5.3", optional = true }
pbkdf2 = { version = "0.12", features = ["simple"], optional = true }
aes-gcm = { version = "0.10.3", optional = true }
aes = { version = "0.8", optional = true }
rsa = { version = "0.9.6", optional = true }
mime_guess = "2.0.4"
mime_guess = "2.0.5"
Loading
Loading