mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2026-02-07 01:01:24 +01:00
delete useless admin commands
To clear caches, restart the server. We may want to consider adding the cache sizes and database memory usage as metrics in the future.
This commit is contained in:
parent
6a44d0af2b
commit
e0cf163486
7 changed files with 11 additions and 195 deletions
|
|
@ -20,10 +20,6 @@ pub(crate) trait KeyValueDatabaseEngine: Send + Sync {
|
|||
fn cleanup(&self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn memory_usage(&self) -> Result<String> {
|
||||
Ok("Current database engine does not support memory usage reporting."
|
||||
.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait KvTree: Send + Sync {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,9 @@ use std::{
|
|||
};
|
||||
|
||||
use rocksdb::{
|
||||
perf::get_memory_usage_stats, BlockBasedOptions, BoundColumnFamily, Cache,
|
||||
ColumnFamilyDescriptor, DBCompactionStyle, DBCompressionType,
|
||||
DBRecoveryMode, DBWithThreadMode, Direction, IteratorMode, MultiThreaded,
|
||||
Options, ReadOptions, WriteOptions,
|
||||
BlockBasedOptions, BoundColumnFamily, Cache, ColumnFamilyDescriptor,
|
||||
DBCompactionStyle, DBCompressionType, DBRecoveryMode, DBWithThreadMode,
|
||||
Direction, IteratorMode, MultiThreaded, Options, ReadOptions, WriteOptions,
|
||||
};
|
||||
use tracing::Level;
|
||||
|
||||
|
|
@ -143,24 +142,6 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
|
|||
write_lock: RwLock::new(()),
|
||||
}))
|
||||
}
|
||||
|
||||
#[allow(clippy::as_conversions, clippy::cast_precision_loss)]
|
||||
fn memory_usage(&self) -> Result<String> {
|
||||
let stats =
|
||||
get_memory_usage_stats(Some(&[&self.rocks]), Some(&[&self.cache]))?;
|
||||
Ok(format!(
|
||||
"Approximate memory usage of all the mem-tables: {:.3} \
|
||||
MB\nApproximate memory usage of un-flushed mem-tables: {:.3} \
|
||||
MB\nApproximate memory usage of all the table readers: {:.3} \
|
||||
MB\nApproximate memory usage by cache: {:.3} MB\nApproximate \
|
||||
memory usage by cache pinned: {:.3} MB\n",
|
||||
stats.mem_table_total as f64 / 1024.0 / 1024.0,
|
||||
stats.mem_table_unflushed as f64 / 1024.0 / 1024.0,
|
||||
stats.mem_table_readers_total as f64 / 1024.0 / 1024.0,
|
||||
stats.cache_total as f64 / 1024.0 / 1024.0,
|
||||
self.cache.get_pinned_usage() as f64 / 1024.0 / 1024.0,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl RocksDbEngineTree<'_> {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use futures_util::{stream::FuturesUnordered, StreamExt};
|
||||
use lru_cache::LruCache;
|
||||
use ruma::{
|
||||
api::federation::discovery::{OldVerifyKey, ServerSigningKeys},
|
||||
signatures::Ed25519KeyPair,
|
||||
|
|
@ -138,73 +135,6 @@ impl service::globals::Data for KeyValueDatabase {
|
|||
self.db.cleanup()
|
||||
}
|
||||
|
||||
fn memory_usage(&self) -> String {
|
||||
let pdu_cache = self.pdu_cache.lock().unwrap().len();
|
||||
let shorteventid_cache = self.shorteventid_cache.lock().unwrap().len();
|
||||
let auth_chain_cache = self.auth_chain_cache.lock().unwrap().len();
|
||||
let eventidshort_cache = self.eventidshort_cache.lock().unwrap().len();
|
||||
let statekeyshort_cache =
|
||||
self.statekeyshort_cache.lock().unwrap().len();
|
||||
let our_real_users_cache =
|
||||
self.our_real_users_cache.read().unwrap().len();
|
||||
let appservice_in_room_cache =
|
||||
self.appservice_in_room_cache.read().unwrap().len();
|
||||
let lasttimelinecount_cache =
|
||||
self.lasttimelinecount_cache.lock().unwrap().len();
|
||||
|
||||
let mut response = format!(
|
||||
"\
|
||||
pdu_cache: {pdu_cache}
|
||||
shorteventid_cache: {shorteventid_cache}
|
||||
auth_chain_cache: {auth_chain_cache}
|
||||
eventidshort_cache: {eventidshort_cache}
|
||||
statekeyshort_cache: {statekeyshort_cache}
|
||||
our_real_users_cache: {our_real_users_cache}
|
||||
appservice_in_room_cache: {appservice_in_room_cache}
|
||||
lasttimelinecount_cache: {lasttimelinecount_cache}\n"
|
||||
);
|
||||
if let Ok(db_stats) = self.db.memory_usage() {
|
||||
response += &db_stats;
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
|
||||
fn clear_caches(&self, amount: u32) {
|
||||
if amount > 0 {
|
||||
let c = &mut *self.pdu_cache.lock().unwrap();
|
||||
*c = LruCache::new(c.capacity());
|
||||
}
|
||||
if amount > 1 {
|
||||
let c = &mut *self.shorteventid_cache.lock().unwrap();
|
||||
*c = LruCache::new(c.capacity());
|
||||
}
|
||||
if amount > 2 {
|
||||
let c = &mut *self.auth_chain_cache.lock().unwrap();
|
||||
*c = LruCache::new(c.capacity());
|
||||
}
|
||||
if amount > 3 {
|
||||
let c = &mut *self.eventidshort_cache.lock().unwrap();
|
||||
*c = LruCache::new(c.capacity());
|
||||
}
|
||||
if amount > 4 {
|
||||
let c = &mut *self.statekeyshort_cache.lock().unwrap();
|
||||
*c = LruCache::new(c.capacity());
|
||||
}
|
||||
if amount > 5 {
|
||||
let c = &mut *self.our_real_users_cache.write().unwrap();
|
||||
*c = HashMap::new();
|
||||
}
|
||||
if amount > 6 {
|
||||
let c = &mut *self.appservice_in_room_cache.write().unwrap();
|
||||
*c = HashMap::new();
|
||||
}
|
||||
if amount > 7 {
|
||||
let c = &mut *self.lasttimelinecount_cache.lock().unwrap();
|
||||
*c = HashMap::new();
|
||||
}
|
||||
}
|
||||
|
||||
fn load_keypair(&self) -> Result<Ed25519KeyPair> {
|
||||
let keypair_bytes = self.global.get(b"keypair")?.map_or_else(
|
||||
|| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue