mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 10:14:35 +00:00
release dashmap memory (#1485)
This commit is contained in:
@@ -10,6 +10,7 @@ use tokio::task::JoinSet;
|
||||
use tokio::time::timeout;
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
use crate::common::shrink_dashmap;
|
||||
use crate::common::{
|
||||
stats_manager::{LabelSet, LabelType, MetricName, StatsManager},
|
||||
PeerId,
|
||||
@@ -131,6 +132,7 @@ impl Client {
|
||||
}
|
||||
true
|
||||
});
|
||||
peer_infos.shrink_to_fit();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -245,7 +247,7 @@ impl Client {
|
||||
.with_label_type(LabelType::ServiceName(desc.name().to_string()))
|
||||
.with_label_type(LabelType::MethodName(method.name().to_string()));
|
||||
|
||||
defer!(self.inflight_requests.remove(&key););
|
||||
defer!(self.inflight_requests.remove(&key); shrink_dashmap(&self.inflight_requests, Some(4)););
|
||||
self.inflight_requests.insert(
|
||||
key.clone(),
|
||||
InflightRequest {
|
||||
|
||||
@@ -82,16 +82,9 @@ impl Server {
|
||||
registry: Arc<ServiceRegistry>,
|
||||
stats_manager: Arc<StatsManager>,
|
||||
) -> Self {
|
||||
let (ring_a, ring_b) = create_ring_tunnel_pair();
|
||||
|
||||
Self {
|
||||
registry,
|
||||
mpsc: Mutex::new(Some(MpscTunnel::new(ring_a, None))),
|
||||
transport: Mutex::new(MpscTunnel::new(ring_b, None)),
|
||||
tasks: Arc::new(Mutex::new(JoinSet::new())),
|
||||
packet_mergers: Arc::new(DashMap::new()),
|
||||
stats_manager: Some(stats_manager),
|
||||
}
|
||||
let mut ret = Self::new_with_registry(registry);
|
||||
ret.stats_manager = Some(stats_manager);
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn registry(&self) -> &ServiceRegistry {
|
||||
@@ -176,6 +169,7 @@ impl Server {
|
||||
loop {
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
|
||||
packet_mergers.retain(|_, v| v.last_updated().elapsed().as_secs() < 10);
|
||||
packet_mergers.shrink_to_fit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user