perf: debounce store writes and add retry loop on Redb transaction collisions
This commit is contained in:
1 parent
533adfd41b
commit
3efee96230
3 files changed
+22
-9
No files matched your search
@@ -1,6 +1,3 @@
|
||||
[build]
|
||||
rustc-wrapper = "sccache"
|
||||
|
||||
[target.x86_64-pc-windows-msvc]
|
||||
linker = "rust-lld"
|
||||
|
||||
|
||||
@@ -78,14 +78,16 @@ deploy-server:
|
||||
deploy-stub-win:
|
||||
@Write-Host "Deploying Windows Stub..." -ForegroundColor Cyan
|
||||
-Stop-Process -Name mcp-memory-stub -Force -ErrorAction SilentlyContinue
|
||||
-if (Test-Path "C:\Users\reazul.ashraf\.local\bin\mcp-memory-stub.exe") { Move-Item -Force "C:\Users\reazul.ashraf\.local\bin\mcp-memory-stub.exe" "C:\Users\reazul.ashraf\.local\bin\mcp-memory-stub.exe.old" -ErrorAction SilentlyContinue; Remove-Item -Force "C:\Users\reazul.ashraf\.local\bin\mcp-memory-stub.exe.old" -ErrorAction SilentlyContinue }
|
||||
Copy-Item -Force target\release\mcp-memory-stub.exe "C:\Users\reazul.ashraf\.local\bin\"
|
||||
|
||||
|
||||
deploy-nvim-win:
|
||||
@Write-Host "Deploying Windows Nvim..." -ForegroundColor Cyan
|
||||
-Stop-Process -Name mcp-memory-nvim -Force -ErrorAction SilentlyContinue
|
||||
-if (Test-Path "C:\Users\reazul.ashraf\.local\bin\mcp-memory-nvim.exe") { Move-Item -Force "C:\Users\reazul.ashraf\.local\bin\mcp-memory-nvim.exe" "C:\Users\reazul.ashraf\.local\bin\mcp-memory-nvim.exe.old" -ErrorAction SilentlyContinue; Remove-Item -Force "C:\Users\reazul.ashraf\.local\bin\mcp-memory-nvim.exe.old" -ErrorAction SilentlyContinue }
|
||||
Copy-Item -Force target\release\mcp-memory-nvim.exe "C:\Users\reazul.ashraf\.local\bin\"
|
||||
|
||||
|
||||
deploy-rules-win:
|
||||
@Write-Host "Deploying global Agent rules (Windows)..." -ForegroundColor Cyan
|
||||
if (!(Test-Path "C:\Users\reazul.ashraf\.gemini\config\rules")) { New-Item -ItemType Directory -Force -Path "C:\Users\reazul.ashraf\.gemini\config\rules" | Out-Null }
|
||||
@@ -109,6 +111,9 @@ build-nvim:
|
||||
@Write-Host "Building WSL Nvim natively..." -ForegroundColor Cyan
|
||||
wsl.exe -d Ubuntu -e bash -c 'export PATH="/home/riz/.cargo/bin:$PATH" && cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && cargo build --release -p mcp-memory-nvim'
|
||||
|
||||
|
||||
|
||||
|
||||
deploy-nvim:
|
||||
@Write-Host "Deploying WSL Nvim natively..." -ForegroundColor Cyan
|
||||
wsl.exe -d Ubuntu -e bash -c 'export PATH="/home/riz/.cargo/bin:$PATH" && cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && cp target/release/mcp-memory-nvim /home/riz/.local/bin/'
|
||||
|
||||
+16
-5
@@ -21,7 +21,9 @@ impl<T: DeserializeOwned + Default + Serialize + Clone + Send + Sync + 'static>
|
||||
|
||||
tokio::spawn(async move {
|
||||
while rx.recv().await.is_some() {
|
||||
// Drain any other pending notifications so we batch writes
|
||||
// Debounce window: wait 150ms to batch rapid sequential mutations
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(150)).await;
|
||||
// Drain any pending notifications accumulated during the debounce window
|
||||
while rx.try_recv().is_ok() {}
|
||||
|
||||
let db_inner = db_clone.clone();
|
||||
@@ -35,11 +37,20 @@ impl<T: DeserializeOwned + Default + Serialize + Clone + Send + Sync + 'static>
|
||||
|
||||
if let Some(json_data) = json_data {
|
||||
let _ = tokio::task::spawn_blocking(move || {
|
||||
if let Ok(write_txn) = db_inner.begin_write() {
|
||||
if let Ok(mut table) = write_txn.open_table(STORE_TABLE) {
|
||||
let _ = table.insert(key_inner.as_str(), json_data.as_slice());
|
||||
// Retry up to 10 times with 30ms backoff if another Store holds write transaction
|
||||
for _ in 0..10 {
|
||||
match db_inner.begin_write() {
|
||||
Ok(write_txn) => {
|
||||
if let Ok(mut table) = write_txn.open_table(STORE_TABLE) {
|
||||
let _ = table.insert(key_inner.as_str(), json_data.as_slice());
|
||||
}
|
||||
let _ = write_txn.commit();
|
||||
break;
|
||||
}
|
||||
Err(_) => {
|
||||
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||
}
|
||||
}
|
||||
let _ = write_txn.commit();
|
||||
}
|
||||
})
|
||||
.await;
|
||||
|
||||
Reference in new issue
Block a user