From 3f2a31c957375d6c62542a92eedff1be6d7d745a Mon Sep 17 00:00:00 2001 From: CherishCai <785427346@qq.com> Date: Fri, 17 Nov 2023 21:32:39 +0800 Subject: [PATCH] change: default COMMON_THREAD_CORES=1, and some clippy code --- Cargo.toml | 8 ++++---- README.md | 2 +- examples/simple_app.rs | 2 ++ src/api/constants.rs | 2 +- src/api/plugin/auth/auth_by_http.rs | 2 +- src/common/executor/mod.rs | 10 +++++----- src/common/remote/grpc/nacos_grpc_connection.rs | 2 +- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fc59d8b..b970087 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,8 +51,8 @@ thiserror = "1.0" tokio = { version = "1", features = ["full"] } futures = "0.3" -prost = "0.11" -prost-types = "0.11" +prost = "0.12" +prost-types = "0.12" serde = { version = "1", features = ["derive"] } serde_json = "1" lazy_static = "1.4" @@ -66,7 +66,7 @@ reqwest = { version = "0.11", default-features = false, features = [], optional async-trait = "0.1" async-stream = "0.3.5" -tonic = "0.9.2" +tonic = "0.10" tower = { version = "0.4.13", features = ["filter", "log"] } futures-util = "0.3.28" want = "0.3.0" @@ -77,7 +77,7 @@ dotenvy = "0.15" [dev-dependencies] tracing-subscriber = { version = "0.3", features = ["default"] } -tonic-build = "0.9.2" +tonic-build = "0.10" mockall = { version = "0.11" } diff --git a/README.md b/README.md index 8a55db2..65e0519 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ nacos-sdk = { version = "0.3", features = ["default"] } Props count be set by `ClientProps`, or Environment variables (Higher priority). See them in `nacos_sdk::api::props::ClientProps` or `nacos_sdk::api::constants::ENV_NACOS_CLIENT_*`. e.g. -- env `NACOS_CLIENT_COMMON_THREAD_CORES` to set num when multi-cpus, default is num_cpus +- env `NACOS_CLIENT_COMMON_THREAD_CORES` to set nacos-client-thread-pool num, default 1 - env `NACOS_CLIENT_NAMING_PUSH_EMPTY_PROTECTION` for naming empty data notify protection, default true ## 开发说明 diff --git a/examples/simple_app.rs b/examples/simple_app.rs index 12de0aa..ae47eed 100644 --- a/examples/simple_app.rs +++ b/examples/simple_app.rs @@ -17,6 +17,8 @@ async fn main() -> Result<(), Box> { // all spans/events with a level higher than TRACE (e.g, info, warn, etc.) // will be written to stdout. .with_max_level(tracing::Level::DEBUG) + .with_thread_names(true) + .with_thread_ids(true) // sets this to be the default, global collector for this application. .init(); diff --git a/src/api/constants.rs b/src/api/constants.rs index 72a13ee..647e7b0 100644 --- a/src/api/constants.rs +++ b/src/api/constants.rs @@ -29,7 +29,7 @@ pub(crate) mod common_remote { pub const LABEL_MODULE_CONFIG: &str = "config"; } -/// env `NACOS_CLIENT_COMMON_THREAD_CORES` to set num when multi-cpus, default is num_cpus +/// env `NACOS_CLIENT_COMMON_THREAD_CORES` to set nacos-client-thread-pool num, default 1 pub const ENV_NACOS_CLIENT_COMMON_THREAD_CORES: &str = "NACOS_CLIENT_COMMON_THREAD_CORES"; pub const ENV_NACOS_CLIENT_COMMON_SERVER_ADDRESS: &str = "NACOS_CLIENT_SERVER_ADDRESS"; diff --git a/src/api/plugin/auth/auth_by_http.rs b/src/api/plugin/auth/auth_by_http.rs index c475c62..b53273f 100644 --- a/src/api/plugin/auth/auth_by_http.rs +++ b/src/api/plugin/auth/auth_by_http.rs @@ -90,7 +90,7 @@ impl AuthPlugin for HttpLoginAuthPlugin { .add_context(ACCESS_TOKEN, login_response.access_token); unsafe { - #[warn(clippy::cast_ref_to_mut)] + #[warn(invalid_reference_casting)] let mut_self = &mut *(self as *const Self as *mut Self); mut_self.next_login_refresh = Instant::now().add(Duration::from_secs(delay_sec)); mut_self.login_identity = new_login_identity; diff --git a/src/common/executor/mod.rs b/src/common/executor/mod.rs index 28d422e..be6698e 100644 --- a/src/common/executor/mod.rs +++ b/src/common/executor/mod.rs @@ -9,11 +9,11 @@ use tokio::{ use tracing::{error, Instrument}; lazy_static! { - static ref COMMON_THREAD_CORES: usize = std::env::var(crate::api::constants::ENV_NACOS_CLIENT_COMMON_THREAD_CORES) - .ok() - .and_then(|v| v.parse::().ok().filter(|n| *n > 0)) - .unwrap_or_else(|| std::thread::available_parallelism().unwrap().get()); // default is num_cpus - + static ref COMMON_THREAD_CORES: usize = + std::env::var(crate::api::constants::ENV_NACOS_CLIENT_COMMON_THREAD_CORES) + .ok() + .and_then(|v| v.parse::().ok().filter(|n| *n > 0)) + .unwrap_or(1); static ref RT: Runtime = Builder::new_multi_thread() .enable_all() .thread_name("nacos-client-thread-pool") diff --git a/src/common/remote/grpc/nacos_grpc_connection.rs b/src/common/remote/grpc/nacos_grpc_connection.rs index c5d1c74..1d129b4 100644 --- a/src/common/remote/grpc/nacos_grpc_connection.rs +++ b/src/common/remote/grpc/nacos_grpc_connection.rs @@ -801,7 +801,7 @@ where .in_current_span() .await?; let ret = svc.call(request).in_current_span().await; - ret.map_err(|error| GrpcBufferRequest(error)) + ret.map_err(GrpcBufferRequest) } }