diff --git a/Cargo.lock b/Cargo.lock index 0abe1b58..ab74bfa1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "actix" -version = "0.13.1" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cba56612922b907719d4a01cf11c8d5b458e7d3dba946d0435f20f58d6795ed2" +checksum = "fb72882332b6d6282f428b77ba0358cb2687e61a6f6df6a6d3871e8a177c2d4f" dependencies = [ "actix-macros", "actix-rt", diff --git a/Cargo.toml b/Cargo.toml index 01e19fc7..1f23e2ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,10 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix = "0.13" -actix-web = { version = "4.4.1", features = ["openssl"] } -actix-http = "3.5.1" -actix-rt = "2" +actix = "0.13.3" +actix-web = { version = "4.4.1", default-features = false, features = ["openssl", "compress-brotli", "compress-gzip"] } +actix-http = { version = "3.5.1", default-features = false, features = ["openssl", "compress-brotli", "compress-gzip"] } +actix-rt = "2.9.0" actix-web-actors = { version = "4.2.0" } actix-service = "2.0.2" actix-identity = "0.6.0" @@ -86,6 +86,10 @@ workspace-template = { workspace = true } realtime-entity.workspace = true +# profiling +#puffin = "0.16.0" +#prometheus = { version = "0.13.3", features = ["process"] } + [dev-dependencies] once_cell = "1.19.0" tempfile = "3.9.0" diff --git a/libs/database/src/collab/collab_storage.rs b/libs/database/src/collab/collab_storage.rs index 4dcf4710..352bbb3a 100644 --- a/libs/database/src/collab/collab_storage.rs +++ b/libs/database/src/collab/collab_storage.rs @@ -59,6 +59,8 @@ pub trait CollabStorageAccessControl: Send + Sync + 'static { pub trait CollabStorage: Send + Sync + 'static { fn config(&self) -> &WriteConfig; + async fn status(&self) -> String; + async fn cache_collab(&self, object_id: &str, collab: Weak); async fn remove_collab_cache(&self, object_id: &str); @@ -131,6 +133,10 @@ where self.as_ref().config() } + async fn status(&self) -> String { + self.as_ref().status().await + } + async fn cache_collab(&self, object_id: &str, collab: Weak) { self.as_ref().cache_collab(object_id, collab).await } diff --git a/libs/realtime/src/collaborate/server.rs b/libs/realtime/src/collaborate/server.rs index 565b6e29..feb3174c 100644 --- a/libs/realtime/src/collaborate/server.rs +++ b/libs/realtime/src/collaborate/server.rs @@ -67,10 +67,16 @@ where let edit_collab_by_user = Arc::new(Mutex::new(HashMap::new())); let weak_groups = Arc::downgrade(&groups); + let weak_storage = Arc::downgrade(&storage); tokio::spawn(async move { let mut interval = interval(Duration::from_secs(60)); loop { interval.tick().await; + + if let Some(storage) = weak_storage.upgrade() { + info!("{}", storage.status().await); + } + match weak_groups.upgrade() { Some(groups) => { trace!( diff --git a/src/biz/collab/mem_cache.rs b/src/biz/collab/mem_cache.rs index aa50fc21..d2e8d581 100644 --- a/src/biz/collab/mem_cache.rs +++ b/src/biz/collab/mem_cache.rs @@ -13,12 +13,20 @@ pub struct CollabMemCache { impl CollabMemCache { pub fn new(_redis_client: RedisClient) -> Self { - let lru = LruCache::new(NonZeroUsize::new(5000).unwrap()); + let lru = LruCache::new(NonZeroUsize::new(3000).unwrap()); Self { lru_cache: Arc::new(Mutex::new(lru)), } } + pub async fn len(&self) -> usize { + self + .lru_cache + .try_lock() + .map(|cache| cache.len()) + .unwrap_or(0) + } + pub async fn get_encoded_collab(&self, object_id: &str) -> Option { let cache = self.lru_cache.lock().await.get(object_id)?.clone(); tokio::task::spawn_blocking(move || match EncodedCollab::decode_from_bytes(&cache) { diff --git a/src/biz/collab/storage.rs b/src/biz/collab/storage.rs index f0732f96..b6d90fb1 100644 --- a/src/biz/collab/storage.rs +++ b/src/biz/collab/storage.rs @@ -84,6 +84,10 @@ where self.disk_cache.config() } + async fn status(&self) -> String { + format!("cache collab: {}", self.mem_cache.len().await) + } + async fn cache_collab(&self, object_id: &str, collab: Weak) { tracing::trace!("cache opened collab:{}", object_id); self