From c1dd19265d5b20e5e1b5aabbb25d2604bb7f8349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Thu, 25 Nov 2021 20:59:54 +0100 Subject: [PATCH] performance tests --- src/database.rs | 10 +++++----- src/database/abstraction/sqlite.rs | 12 ++++++------ src/server_server.rs | 12 +++++++----- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/database.rs b/src/database.rs index 080e24b3..ae7298a9 100644 --- a/src/database.rs +++ b/src/database.rs @@ -314,11 +314,11 @@ impl Database { .try_into() .expect("pdu cache capacity fits into usize"), )), - auth_chain_cache: Mutex::new(LruCache::new(1_000_000)), - shorteventid_cache: Mutex::new(LruCache::new(1_000_000)), - eventidshort_cache: Mutex::new(LruCache::new(1_000_000)), - shortstatekey_cache: Mutex::new(LruCache::new(1_000_000)), - statekeyshort_cache: Mutex::new(LruCache::new(1_000_000)), + auth_chain_cache: Mutex::new(LruCache::new(10_000_000)), + shorteventid_cache: Mutex::new(LruCache::new(10_000_000)), + eventidshort_cache: Mutex::new(LruCache::new(10_000_000)), + shortstatekey_cache: Mutex::new(LruCache::new(10_000_000)), + statekeyshort_cache: Mutex::new(LruCache::new(10_000_000)), our_real_users_cache: RwLock::new(HashMap::new()), appservice_in_room_cache: RwLock::new(HashMap::new()), stateinfo_cache: Mutex::new(LruCache::new(1000)), diff --git a/src/database/abstraction/sqlite.rs b/src/database/abstraction/sqlite.rs index 1d2038c5..cb8cad49 100644 --- a/src/database/abstraction/sqlite.rs +++ b/src/database/abstraction/sqlite.rs @@ -21,7 +21,7 @@ thread_local! { struct PreparedStatementIterator<'a> { pub iterator: Box + 'a>, - pub statement_ref: NonAliasingBox>, + pub statement_ref: NonAliasingBox>, } impl Iterator for PreparedStatementIterator<'_> { @@ -52,7 +52,7 @@ impl Engine { fn prepare_conn(path: &Path, cache_size_kb: u32) -> Result { let conn = Connection::open(&path)?; - conn.pragma_update(Some(Main), "page_size", &2048)?; + conn.pragma_update(Some(Main), "page_size", &32768)?; conn.pragma_update(Some(Main), "journal_mode", &"WAL")?; conn.pragma_update(Some(Main), "synchronous", &"NORMAL")?; conn.pragma_update(Some(Main), "cache_size", &(-i64::from(cache_size_kb)))?; @@ -136,7 +136,7 @@ impl SqliteTable { fn get_with_guard(&self, guard: &Connection, key: &[u8]) -> Result>> { //dbg!(&self.name); Ok(guard - .prepare(format!("SELECT value FROM {} WHERE key = ?", self.name).as_str())? + .prepare_cached(format!("SELECT value FROM {} WHERE key = ?", self.name).as_str())? .query_row([key], |row| row.get(0)) .optional()?) } @@ -161,7 +161,7 @@ impl SqliteTable { ) -> Box + 'a> { let statement = Box::leak(Box::new( guard - .prepare(&format!( + .prepare_cached(&format!( "SELECT key, value FROM {} ORDER BY key ASC", &self.name )) @@ -290,7 +290,7 @@ impl Tree for SqliteTable { if backwards { let statement = Box::leak(Box::new( guard - .prepare(&format!( + .prepare_cached(&format!( "SELECT key, value FROM {} WHERE key <= ? ORDER BY key DESC", &self.name )) @@ -315,7 +315,7 @@ impl Tree for SqliteTable { } else { let statement = Box::leak(Box::new( guard - .prepare(&format!( + .prepare_cached(&format!( "SELECT key, value FROM {} WHERE key >= ? ORDER BY key ASC", &self.name )) diff --git a/src/server_server.rs b/src/server_server.rs index 482edf0f..f96244f1 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -47,7 +47,6 @@ use ruma::{ }, AnyEphemeralRoomEvent, EventType, }, - int, receipt::ReceiptType, serde::JsonObject, signatures::{CanonicalJsonObject, CanonicalJsonValue}, @@ -751,14 +750,14 @@ pub async fn send_transaction_message_route( .roomid_mutex_federation .write() .unwrap() - .entry(room_id.clone()) + .entry(RoomId::try_from("!asdf:asfd.asdf").unwrap()) .or_default(), ); let mutex_lock = mutex.lock().await; let start_time = Instant::now(); resolved_map.insert( event_id.clone(), - handle_incoming_pdu( + dbg!(handle_incoming_pdu( &body.origin, &event_id, &room_id, @@ -767,7 +766,7 @@ pub async fn send_transaction_message_route( &db, &pub_key_map, ) - .await + .await) .map(|_| ()), ); drop(mutex_lock); @@ -956,6 +955,7 @@ pub(crate) async fn handle_incoming_pdu<'a>( db: &'a Database, pub_key_map: &'a RwLock>>, ) -> Result>, String> { + warn!("Handling incoming pdu: {:?}", value); match db.rooms.exists(room_id) { Ok(true) => {} _ => { @@ -1000,6 +1000,7 @@ pub(crate) async fn handle_incoming_pdu<'a>( return Ok(None); } + /* stop fetching prev events for now // 9. Fetch any missing prev events doing all checks listed here starting at 1. These are timeline events let mut graph = HashMap::new(); let mut eventid_info = HashMap::new(); @@ -1114,6 +1115,7 @@ pub(crate) async fn handle_incoming_pdu<'a>( ); } } + */ upgrade_outlier_to_timeline_pdu( incoming_pdu, @@ -2838,7 +2840,7 @@ async fn create_join_event( .roomid_mutex_federation .write() .unwrap() - .entry(room_id.clone()) + .entry(RoomId::try_from("!asdf:asfd.asdf").unwrap()) // make all rooms share the same lock for now .or_default(), ); let mutex_lock = mutex.lock().await;