chore: update feature of actix (#304)

* chore: update feature of actix

* chore: add logs
This commit is contained in:
Nathan.fooo 2024-02-08 02:32:25 +08:00 committed by GitHub
parent 8def2bfaf3
commit 03471f3af7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 35 additions and 7 deletions

4
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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<MutexCollab>);
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<MutexCollab>) {
self.as_ref().cache_collab(object_id, collab).await
}

View File

@ -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!(

View File

@ -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<EncodedCollab> {
let cache = self.lru_cache.lock().await.get(object_id)?.clone();
tokio::task::spawn_blocking(move || match EncodedCollab::decode_from_bytes(&cache) {

View File

@ -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<MutexCollab>) {
tracing::trace!("cache opened collab:{}", object_id);
self