Skip to content

Commit

Permalink
change: default COMMON_THREAD_CORES=1, and some clippy code (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
CherishCai authored Nov 19, 2023
1 parent 4d41599 commit 5fc96c7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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" }


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

## 开发说明
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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();

Expand Down
2 changes: 1 addition & 1 deletion src/api/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/api/plugin/auth/auth_by_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/common/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<usize>().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::<usize>().ok().filter(|n| *n > 0))
.unwrap_or(1);
static ref RT: Runtime = Builder::new_multi_thread()
.enable_all()
.thread_name("nacos-client-thread-pool")
Expand Down
2 changes: 1 addition & 1 deletion src/common/remote/grpc/nacos_grpc_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 5fc96c7

Please sign in to comment.