diff --git a/Cargo.lock b/Cargo.lock index 761043a0287..ada2a6f0bb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -679,6 +679,16 @@ dependencies = [ "serde", ] +[[package]] +name = "bytesize-serde" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d1eb2fd2668859e9785b99700c66b7ea9fdeda35d99f95827a4e5493440178" +dependencies = [ + "bytesize", + "serde", +] + [[package]] name = "bzip2-sys" version = "0.1.11+1.0.8" @@ -1108,7 +1118,7 @@ dependencies = [ [[package]] name = "dragonfly-client" -version = "0.1.87" +version = "0.1.88" dependencies = [ "anyhow", "blake3", @@ -1175,7 +1185,7 @@ dependencies = [ [[package]] name = "dragonfly-client-backend" -version = "0.1.87" +version = "0.1.88" dependencies = [ "dragonfly-api", "dragonfly-client-core", @@ -1196,8 +1206,10 @@ dependencies = [ [[package]] name = "dragonfly-client-config" -version = "0.1.87" +version = "0.1.88" dependencies = [ + "bytesize", + "bytesize-serde", "dragonfly-client-core", "home", "hostname", @@ -1215,7 +1227,7 @@ dependencies = [ [[package]] name = "dragonfly-client-core" -version = "0.1.87" +version = "0.1.88" dependencies = [ "hyper 1.4.0", "hyper-util", @@ -1230,7 +1242,7 @@ dependencies = [ [[package]] name = "dragonfly-client-init" -version = "0.1.87" +version = "0.1.88" dependencies = [ "anyhow", "clap", @@ -1246,7 +1258,7 @@ dependencies = [ [[package]] name = "dragonfly-client-storage" -version = "0.1.87" +version = "0.1.88" dependencies = [ "base16ct", "blake3", @@ -1270,7 +1282,7 @@ dependencies = [ [[package]] name = "dragonfly-client-util" -version = "0.1.87" +version = "0.1.88" dependencies = [ "base16ct", "blake3", @@ -1739,7 +1751,7 @@ dependencies = [ [[package]] name = "hdfs" -version = "0.1.87" +version = "0.1.88" dependencies = [ "dragonfly-client-backend", "dragonfly-client-core", diff --git a/Cargo.toml b/Cargo.toml index 4536ddb496d..6714ce4a20a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ ] [workspace.package] -version = "0.1.87" +version = "0.1.88" authors = ["The Dragonfly Developers"] homepage = "https://d7y.io/" repository = "https://github.com/dragonflyoss/client.git" @@ -22,13 +22,13 @@ readme = "README.md" edition = "2021" [workspace.dependencies] -dragonfly-client = { path = "dragonfly-client", version = "0.1.87" } -dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.87" } -dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.87" } -dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.87" } -dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.87" } -dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.87" } -dragonfly-client-init = { path = "dragonfly-client-init", version = "0.1.87" } +dragonfly-client = { path = "dragonfly-client", version = "0.1.88" } +dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.88" } +dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.88" } +dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.88" } +dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.88" } +dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.88" } +dragonfly-client-init = { path = "dragonfly-client-init", version = "0.1.88" } thiserror = "1.0" dragonfly-api = "2.0.138" reqwest = { version = "0.12.4", features = ["stream", "native-tls", "default-tls", "rustls-tls"] } @@ -84,6 +84,7 @@ toml_edit = "0.22.14" toml = "0.8.13" base16ct = { version = "0.2", features = ["alloc"] } bytesize = {version = "1.2.0", features = ["serde"]} +bytesize-serde = "0.2.1" [profile.release] debug = true diff --git a/dragonfly-client-config/Cargo.toml b/dragonfly-client-config/Cargo.toml index f792f60bb9f..004057a9032 100644 --- a/dragonfly-client-config/Cargo.toml +++ b/dragonfly-client-config/Cargo.toml @@ -18,6 +18,8 @@ validator.workspace = true humantime.workspace = true serde_yaml.workspace = true tokio.workspace = true +bytesize.workspace = true +bytesize-serde.workspace = true home = "0.5.4" local-ip-address = "0.6.1" hostname = "^0.4" diff --git a/dragonfly-client-config/src/dfdaemon.rs b/dragonfly-client-config/src/dfdaemon.rs index 6cd8e7e1772..f88eaedd0ce 100644 --- a/dragonfly-client-config/src/dfdaemon.rs +++ b/dragonfly-client-config/src/dfdaemon.rs @@ -14,6 +14,7 @@ * limitations under the License. */ +use bytesize::ByteSize; use dragonfly_client_core::error::{ErrorType, OrErr}; use dragonfly_client_core::Result; use local_ip_address::{local_ip, local_ipv6}; @@ -77,11 +78,11 @@ fn default_upload_grpc_server_port() -> u16 { 4000 } -// default_upload_rate_limit is the default rate limit of the upload speed in bps(bytes per second). +// default_upload_rate_limit is the default rate limit of the upload speed in GiB/Mib/Kib per second. #[inline] -fn default_upload_rate_limit() -> u64 { - // Default rate limit is 10Gbps. - 10_000_000_000 +fn default_upload_rate_limit() -> ByteSize { + // Default rate limit is 10GiB/s. + ByteSize::gib(10) } // default_health_server_port is the default port of the health server. @@ -102,11 +103,11 @@ fn default_stats_server_port() -> u16 { 4004 } -// default_download_rate_limit is the default rate limit of the download speed in bps(bytes per second). +// default_download_rate_limit is the default rate limit of the download speed in GiB/Mib/Kib per second. #[inline] -fn default_download_rate_limit() -> u64 { - // Default rate limit is 10Gbps. - 10_000_000_000 +fn default_download_rate_limit() -> ByteSize { + // Default rate limit is 10GiB/s. + ByteSize::gib(10) } // default_download_piece_timeout is the default timeout for downloading a piece from source. @@ -388,9 +389,9 @@ pub struct Download { // server is the download server configuration for dfdaemon. pub server: DownloadServer, - // rate_limit is the rate limit of the download speed in bps(bytes per second). - #[serde(default = "default_download_rate_limit")] - pub rate_limit: u64, + // rate_limit is the rate limit of the download speed in GiB/Mib/Kib per second. + #[serde(with = "bytesize_serde", default = "default_download_rate_limit")] + pub rate_limit: ByteSize, // piece_timeout is the timeout for downloading a piece from source. #[serde(default = "default_download_piece_timeout", with = "humantime_serde")] @@ -443,9 +444,9 @@ pub struct Upload { // server is the upload server configuration for dfdaemon. pub server: UploadServer, - // rate_limit is the rate limit of the upload speed in bps(bytes per second). - #[serde(default = "default_upload_rate_limit")] - pub rate_limit: u64, + // rate_limit is the rate limit of the upload speed in GiB/Mib/Kib per second. + #[serde(with = "bytesize_serde", default = "default_upload_rate_limit")] + pub rate_limit: ByteSize, } // Upload implements Default. @@ -1044,6 +1045,12 @@ impl Config { // convert converts the configuration. fn convert(&mut self) { + println!( + "convert download rate limit: {:?}", + self.download.rate_limit + ); + println!("convert upload rate limit: {:?}", self.upload.rate_limit); + // Convert advertise ip. if self.host.ip.is_none() { self.host.ip = if self.network.enable_ipv6 { diff --git a/dragonfly-client/src/resource/piece.rs b/dragonfly-client/src/resource/piece.rs index d29679c1e51..609b3d17741 100644 --- a/dragonfly-client/src/resource/piece.rs +++ b/dragonfly-client/src/resource/piece.rs @@ -71,16 +71,16 @@ impl Piece { backend_factory, download_rate_limiter: Arc::new( RateLimiter::builder() - .initial(config.download.rate_limit as usize) - .refill(config.download.rate_limit as usize) + .initial(config.download.rate_limit.as_u64() as usize) + .refill(config.download.rate_limit.as_u64() as usize) .interval(Duration::from_secs(1)) .fair(false) .build(), ), upload_rate_limiter: Arc::new( RateLimiter::builder() - .initial(config.upload.rate_limit as usize) - .refill(config.upload.rate_limit as usize) + .initial(config.upload.rate_limit.as_u64() as usize) + .refill(config.upload.rate_limit.as_u64() as usize) .interval(Duration::from_secs(1)) .build(), ),