1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-08-06 17:40:59 +00:00

performance tests

This commit is contained in:
Timo Kösters 2021-11-25 20:59:54 +01:00
parent afa5d449c6
commit c1dd19265d
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
3 changed files with 18 additions and 16 deletions

View file

@ -314,11 +314,11 @@ impl Database {
.try_into() .try_into()
.expect("pdu cache capacity fits into usize"), .expect("pdu cache capacity fits into usize"),
)), )),
auth_chain_cache: Mutex::new(LruCache::new(1_000_000)), auth_chain_cache: Mutex::new(LruCache::new(10_000_000)),
shorteventid_cache: Mutex::new(LruCache::new(1_000_000)), shorteventid_cache: Mutex::new(LruCache::new(10_000_000)),
eventidshort_cache: Mutex::new(LruCache::new(1_000_000)), eventidshort_cache: Mutex::new(LruCache::new(10_000_000)),
shortstatekey_cache: Mutex::new(LruCache::new(1_000_000)), shortstatekey_cache: Mutex::new(LruCache::new(10_000_000)),
statekeyshort_cache: Mutex::new(LruCache::new(1_000_000)), statekeyshort_cache: Mutex::new(LruCache::new(10_000_000)),
our_real_users_cache: RwLock::new(HashMap::new()), our_real_users_cache: RwLock::new(HashMap::new()),
appservice_in_room_cache: RwLock::new(HashMap::new()), appservice_in_room_cache: RwLock::new(HashMap::new()),
stateinfo_cache: Mutex::new(LruCache::new(1000)), stateinfo_cache: Mutex::new(LruCache::new(1000)),

View file

@ -21,7 +21,7 @@ thread_local! {
struct PreparedStatementIterator<'a> { struct PreparedStatementIterator<'a> {
pub iterator: Box<dyn Iterator<Item = TupleOfBytes> + 'a>, pub iterator: Box<dyn Iterator<Item = TupleOfBytes> + 'a>,
pub statement_ref: NonAliasingBox<rusqlite::Statement<'a>>, pub statement_ref: NonAliasingBox<rusqlite::CachedStatement<'a>>,
} }
impl Iterator for PreparedStatementIterator<'_> { impl Iterator for PreparedStatementIterator<'_> {
@ -52,7 +52,7 @@ impl Engine {
fn prepare_conn(path: &Path, cache_size_kb: u32) -> Result<Connection> { fn prepare_conn(path: &Path, cache_size_kb: u32) -> Result<Connection> {
let conn = Connection::open(&path)?; 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), "journal_mode", &"WAL")?;
conn.pragma_update(Some(Main), "synchronous", &"NORMAL")?; conn.pragma_update(Some(Main), "synchronous", &"NORMAL")?;
conn.pragma_update(Some(Main), "cache_size", &(-i64::from(cache_size_kb)))?; 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<Option<Vec<u8>>> { fn get_with_guard(&self, guard: &Connection, key: &[u8]) -> Result<Option<Vec<u8>>> {
//dbg!(&self.name); //dbg!(&self.name);
Ok(guard 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)) .query_row([key], |row| row.get(0))
.optional()?) .optional()?)
} }
@ -161,7 +161,7 @@ impl SqliteTable {
) -> Box<dyn Iterator<Item = TupleOfBytes> + 'a> { ) -> Box<dyn Iterator<Item = TupleOfBytes> + 'a> {
let statement = Box::leak(Box::new( let statement = Box::leak(Box::new(
guard guard
.prepare(&format!( .prepare_cached(&format!(
"SELECT key, value FROM {} ORDER BY key ASC", "SELECT key, value FROM {} ORDER BY key ASC",
&self.name &self.name
)) ))
@ -290,7 +290,7 @@ impl Tree for SqliteTable {
if backwards { if backwards {
let statement = Box::leak(Box::new( let statement = Box::leak(Box::new(
guard guard
.prepare(&format!( .prepare_cached(&format!(
"SELECT key, value FROM {} WHERE key <= ? ORDER BY key DESC", "SELECT key, value FROM {} WHERE key <= ? ORDER BY key DESC",
&self.name &self.name
)) ))
@ -315,7 +315,7 @@ impl Tree for SqliteTable {
} else { } else {
let statement = Box::leak(Box::new( let statement = Box::leak(Box::new(
guard guard
.prepare(&format!( .prepare_cached(&format!(
"SELECT key, value FROM {} WHERE key >= ? ORDER BY key ASC", "SELECT key, value FROM {} WHERE key >= ? ORDER BY key ASC",
&self.name &self.name
)) ))

View file

@ -47,7 +47,6 @@ use ruma::{
}, },
AnyEphemeralRoomEvent, EventType, AnyEphemeralRoomEvent, EventType,
}, },
int,
receipt::ReceiptType, receipt::ReceiptType,
serde::JsonObject, serde::JsonObject,
signatures::{CanonicalJsonObject, CanonicalJsonValue}, signatures::{CanonicalJsonObject, CanonicalJsonValue},
@ -751,14 +750,14 @@ pub async fn send_transaction_message_route(
.roomid_mutex_federation .roomid_mutex_federation
.write() .write()
.unwrap() .unwrap()
.entry(room_id.clone()) .entry(RoomId::try_from("!asdf:asfd.asdf").unwrap())
.or_default(), .or_default(),
); );
let mutex_lock = mutex.lock().await; let mutex_lock = mutex.lock().await;
let start_time = Instant::now(); let start_time = Instant::now();
resolved_map.insert( resolved_map.insert(
event_id.clone(), event_id.clone(),
handle_incoming_pdu( dbg!(handle_incoming_pdu(
&body.origin, &body.origin,
&event_id, &event_id,
&room_id, &room_id,
@ -767,7 +766,7 @@ pub async fn send_transaction_message_route(
&db, &db,
&pub_key_map, &pub_key_map,
) )
.await .await)
.map(|_| ()), .map(|_| ()),
); );
drop(mutex_lock); drop(mutex_lock);
@ -956,6 +955,7 @@ pub(crate) async fn handle_incoming_pdu<'a>(
db: &'a Database, db: &'a Database,
pub_key_map: &'a RwLock<BTreeMap<String, BTreeMap<String, String>>>, pub_key_map: &'a RwLock<BTreeMap<String, BTreeMap<String, String>>>,
) -> Result<Option<Vec<u8>>, String> { ) -> Result<Option<Vec<u8>>, String> {
warn!("Handling incoming pdu: {:?}", value);
match db.rooms.exists(room_id) { match db.rooms.exists(room_id) {
Ok(true) => {} Ok(true) => {}
_ => { _ => {
@ -1000,6 +1000,7 @@ pub(crate) async fn handle_incoming_pdu<'a>(
return Ok(None); 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 // 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 graph = HashMap::new();
let mut eventid_info = 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( upgrade_outlier_to_timeline_pdu(
incoming_pdu, incoming_pdu,
@ -2838,7 +2840,7 @@ async fn create_join_event(
.roomid_mutex_federation .roomid_mutex_federation
.write() .write()
.unwrap() .unwrap()
.entry(room_id.clone()) .entry(RoomId::try_from("!asdf:asfd.asdf").unwrap()) // make all rooms share the same lock for now
.or_default(), .or_default(),
); );
let mutex_lock = mutex.lock().await; let mutex_lock = mutex.lock().await;