make service memory_usage()/clear_cache() async trait
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
d8ea8b378c
commit
9ce95a7030
9 changed files with 61 additions and 44 deletions
|
@ -17,6 +17,7 @@ use std::{
|
|||
time::Instant,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
Err, PduEvent, Result, RoomVersion, Server,
|
||||
utils::{MutexMap, TryFutureExtExt},
|
||||
|
@ -54,6 +55,7 @@ struct Services {
|
|||
type RoomMutexMap = MutexMap<OwnedRoomId, ()>;
|
||||
type HandleTimeMap = HashMap<OwnedRoomId, (OwnedEventId, Instant)>;
|
||||
|
||||
#[async_trait]
|
||||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
Ok(Arc::new(Self {
|
||||
|
@ -79,7 +81,7 @@ impl crate::Service for Service {
|
|||
}))
|
||||
}
|
||||
|
||||
fn memory_usage(&self, out: &mut dyn Write) -> Result<()> {
|
||||
async fn memory_usage(&self, out: &mut (dyn Write + Send)) -> Result {
|
||||
let mutex_federation = self.mutex_federation.len();
|
||||
writeln!(out, "federation_mutex: {mutex_federation}")?;
|
||||
|
||||
|
|
|
@ -2,8 +2,9 @@ mod pagination_token;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::{fmt::Write, sync::Arc};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
Err, Error, Result, implement,
|
||||
utils::{
|
||||
|
@ -70,6 +71,7 @@ pub enum Identifier<'a> {
|
|||
|
||||
type Cache = LruCache<OwnedRoomId, Option<CachedSpaceHierarchySummary>>;
|
||||
|
||||
#[async_trait]
|
||||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
let config = &args.server.config;
|
||||
|
@ -90,6 +92,16 @@ impl crate::Service for Service {
|
|||
}))
|
||||
}
|
||||
|
||||
async fn memory_usage(&self, out: &mut (dyn Write + Send)) -> Result {
|
||||
let roomid_spacehierarchy_cache = self.roomid_spacehierarchy_cache.lock().await.len();
|
||||
|
||||
writeln!(out, "roomid_spacehierarchy_cache: {roomid_spacehierarchy_cache}")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn clear_cache(&self) { self.roomid_spacehierarchy_cache.lock().await.clear(); }
|
||||
|
||||
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::{collections::HashMap, fmt::Write, iter::once, sync::Arc};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
PduEvent, Result, err,
|
||||
result::FlatOk,
|
||||
|
@ -56,6 +57,7 @@ struct Data {
|
|||
type RoomMutexMap = MutexMap<OwnedRoomId, ()>;
|
||||
pub type RoomMutexGuard = MutexMapGuard<OwnedRoomId, ()>;
|
||||
|
||||
#[async_trait]
|
||||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
Ok(Arc::new(Self {
|
||||
|
@ -79,7 +81,7 @@ impl crate::Service for Service {
|
|||
}))
|
||||
}
|
||||
|
||||
fn memory_usage(&self, out: &mut dyn Write) -> Result {
|
||||
async fn memory_usage(&self, out: &mut (dyn Write + Send)) -> Result {
|
||||
let mutex = self.mutex.len();
|
||||
writeln!(out, "state_mutex: {mutex}")?;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::{
|
|||
sync::{Arc, Mutex as StdMutex, Mutex},
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
Result, err, utils,
|
||||
utils::math::{Expected, usize_from_f64},
|
||||
|
@ -57,6 +58,7 @@ struct Data {
|
|||
shorteventid_shortstatehash: Arc<Map>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
let config = &args.server.config;
|
||||
|
@ -86,7 +88,7 @@ impl crate::Service for Service {
|
|||
}))
|
||||
}
|
||||
|
||||
fn memory_usage(&self, out: &mut dyn Write) -> Result {
|
||||
async fn memory_usage(&self, out: &mut (dyn Write + Send)) -> Result {
|
||||
use utils::bytes::pretty;
|
||||
|
||||
let (svc_count, svc_bytes) = self.server_visibility_cache.lock()?.iter().fold(
|
||||
|
@ -119,7 +121,7 @@ impl crate::Service for Service {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_cache(&self) {
|
||||
async fn clear_cache(&self) {
|
||||
self.server_visibility_cache.lock().expect("locked").clear();
|
||||
self.user_visibility_cache.lock().expect("locked").clear();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
|||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
Result,
|
||||
arrayvec::ArrayVec,
|
||||
|
@ -65,6 +66,7 @@ type ParentStatesVec = Vec<ShortStateInfo>;
|
|||
pub type CompressedState = BTreeSet<CompressedStateEvent>;
|
||||
pub type CompressedStateEvent = [u8; 2 * size_of::<ShortId>()];
|
||||
|
||||
#[async_trait]
|
||||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
let config = &args.server.config;
|
||||
|
@ -82,7 +84,7 @@ impl crate::Service for Service {
|
|||
}))
|
||||
}
|
||||
|
||||
fn memory_usage(&self, out: &mut dyn Write) -> Result {
|
||||
async fn memory_usage(&self, out: &mut (dyn Write + Send)) -> Result {
|
||||
let (cache_len, ents) = {
|
||||
let cache = self.stateinfo_cache.lock().expect("locked");
|
||||
let ents = cache.iter().map(at!(1)).flat_map(|vec| vec.iter()).fold(
|
||||
|
@ -108,7 +110,7 @@ impl crate::Service for Service {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_cache(&self) { self.stateinfo_cache.lock().expect("locked").clear(); }
|
||||
async fn clear_cache(&self) { self.stateinfo_cache.lock().expect("locked").clear(); }
|
||||
|
||||
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
Err, Error, Result, Server, at, debug, debug_warn, err, error, implement, info,
|
||||
pdu::{EventHash, PduBuilder, PduCount, PduEvent, gen_event_id},
|
||||
|
@ -109,6 +110,7 @@ struct Services {
|
|||
type RoomMutexMap = MutexMap<OwnedRoomId, ()>;
|
||||
pub type RoomMutexGuard = MutexMapGuard<OwnedRoomId, ()>;
|
||||
|
||||
#[async_trait]
|
||||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
Ok(Arc::new(Self {
|
||||
|
@ -142,7 +144,7 @@ impl crate::Service for Service {
|
|||
}))
|
||||
}
|
||||
|
||||
fn memory_usage(&self, out: &mut dyn Write) -> Result<()> {
|
||||
async fn memory_usage(&self, out: &mut (dyn Write + Send)) -> Result {
|
||||
let mutex_insert = self.mutex_insert.len();
|
||||
writeln!(out, "insert_mutex: {mutex_insert}")?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue