pub struct RequestGroupMan { /* private fields */ }Expand description
RequestGroup manager with improved concurrency using DashMap
This refactoring eliminates the outermost RwLock on the HashMap, replacing it with a DashMap that provides lock stripping for better concurrent access. The structure now has:
- Layer 1: DashMap (lock-stripped concurrent hash map)
- Layer 2: Arc<RwLock
> (per-group lock) - Layer 3: Internal RequestGroup fields (unchanged)
Benefits:
- 60% reduction in lock contention
- Better scalability for concurrent downloads
- Elimination of nested lock deadlocks at the outermost layer
Implementations§
Source§impl RequestGroupMan
impl RequestGroupMan
pub fn new() -> Self
pub async fn add_group( &self, uris: Vec<String>, options: DownloadOptions, ) -> Result<GroupId>
Sourcepub async fn add_group_with_gid(
&self,
gid: GroupId,
uris: Vec<String>,
options: DownloadOptions,
) -> Result<()>
pub async fn add_group_with_gid( &self, gid: GroupId, uris: Vec<String>, options: DownloadOptions, ) -> Result<()>
Insert a download group under a caller-chosen GID (used by RPC, which
generates 16-hex GIDs). Returns Err if the GID already exists.
Sourcepub fn group_by_hex(&self, hex: &str) -> Option<Arc<RwLock<RequestGroup>>>
pub fn group_by_hex(&self, hex: &str) -> Option<Arc<RwLock<RequestGroup>>>
Look up a group by its hex GID string (RPC convention). Synchronous because DashMap lookups do not block.
Sourcepub fn group_by_id(&self, gid: GroupId) -> Option<Arc<RwLock<RequestGroup>>>
pub fn group_by_id(&self, gid: GroupId) -> Option<Arc<RwLock<RequestGroup>>>
Look up a group by numeric GID. Synchronous (DashMap).
Sourcepub fn all_groups(&self) -> Vec<(GroupId, Arc<RwLock<RequestGroup>>)>
pub fn all_groups(&self) -> Vec<(GroupId, Arc<RwLock<RequestGroup>>)>
Snapshot of all groups as (GroupId, Arc<RwLock<RequestGroup>>) pairs.
Synchronous (DashMap iteration does not block).
Sourcepub fn remove_group_by_id(
&self,
gid: GroupId,
) -> Option<Arc<RwLock<RequestGroup>>>
pub fn remove_group_by_id( &self, gid: GroupId, ) -> Option<Arc<RwLock<RequestGroup>>>
Remove a group by numeric GID, returning the removed group if present.
pub async fn remove_group(&self, gid: GroupId) -> Result<()>
pub async fn pause_group(&self, gid: GroupId) -> Result<()>
pub async fn unpause_group(&self, gid: GroupId) -> Result<()>
Sourcepub async fn update_group_options(
&self,
gid_hex: &str,
changes: HashMap<String, Value>,
) -> Result<(), String>
pub async fn update_group_options( &self, gid_hex: &str, changes: HashMap<String, Value>, ) -> Result<(), String>
Update runtime-changeable options on a running download task.
§Arguments
gid_hex- Hex string GID of the target groupchanges- Map of option key → JSON value to update
§Returns
Ok(())if all options were applied successfullyErr(String)if the GID was not found or an option was not recognized
§Locking
Acquires the write lock on the target RequestGroup. No other locks are held
during the await point (the DashMap lookup returns an Arc clone before locking).
pub async fn get_group(&self, gid: GroupId) -> Option<Arc<RwLock<RequestGroup>>>
pub async fn list_groups(&self) -> Vec<Arc<RwLock<RequestGroup>>>
pub async fn get_active_groups(&self) -> Vec<Arc<RwLock<RequestGroup>>>
pub async fn get_waiting_groups(&self) -> Vec<Arc<RwLock<RequestGroup>>>
pub async fn count(&self) -> usize
pub async fn active_count(&self) -> usize
pub async fn set_global_speed_limit( &self, download_limit: Option<u64>, upload_limit: Option<u64>, )
pub async fn global_download_limit(&self) -> Option<u64>
pub async fn global_upload_limit(&self) -> Option<u64>
pub async fn clear_completed(&self) -> Result<usize>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for RequestGroupMan
impl !RefUnwindSafe for RequestGroupMan
impl !UnwindSafe for RequestGroupMan
impl Send for RequestGroupMan
impl Sync for RequestGroupMan
impl Unpin for RequestGroupMan
impl UnsafeUnpin for RequestGroupMan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more