refactor(cache): redesign cache system with structured keys and improved performance
- Add repo_path parameter to cached_response and cached_vec_response functions - Implement structured cache key format with namespace, repo_path, and request proto - Replace global cache with Moka in-memory cache using weight-based eviction - Set 256MB memory cap with 10-minute TTL and 2-minute TTI policy - Add metrics collection for cache operations and evictions - Implement efficient repo-scoped invalidation using key structure - Add detailed documentation comments explaining cache architecture - Remove outdated dependencies and update dependency versions - Add error handling for encoding failures in cache operations - Optimize Vec responses with length-delimited encoding and pre-allocation
This commit is contained in:
+7
-1
@@ -12,6 +12,8 @@ use crate::pb::UploadPackResponse;
|
||||
|
||||
/// Maximum time allowed for a git upload-pack process before it is killed.
|
||||
const UPLOAD_PACK_TIMEOUT: Duration = Duration::from_secs(600); // 10 minutes
|
||||
const MAX_UPLOAD_PACKET_BYTES: usize = 16 * 1024 * 1024;
|
||||
const MAX_UPLOAD_STDERR_BYTES: u64 = 64 * 1024;
|
||||
|
||||
impl GitBare {
|
||||
/// Upload pack data using git-upload-pack with true concurrent streaming.
|
||||
@@ -87,6 +89,9 @@ impl GitBare {
|
||||
}
|
||||
match result {
|
||||
Ok(req) => {
|
||||
if req.packet.len() > MAX_UPLOAD_PACKET_BYTES {
|
||||
break;
|
||||
}
|
||||
if stdin.write_all(&req.packet).await.is_err() {
|
||||
break;
|
||||
}
|
||||
@@ -137,7 +142,8 @@ impl GitBare {
|
||||
let stderr_task = {
|
||||
let tx = tx.clone();
|
||||
async move {
|
||||
if let Some(mut stderr) = stderr.take() {
|
||||
if let Some(stderr) = stderr.take() {
|
||||
let mut stderr = stderr.take(MAX_UPLOAD_STDERR_BYTES);
|
||||
let mut s = String::new();
|
||||
if stderr.read_to_string(&mut s).await.is_ok() && !s.is_empty() {
|
||||
let _ = tx
|
||||
|
||||
Reference in New Issue
Block a user