Skip to content

perf: replace Mutex with RwLock for concurrent read requests #661

Description

@ajianaz

Summary

HTTP server serializes ALL requests via Mutex<Uteke> (main.rs:571-578). Read-only requests (recall, search, list, stats) blocked while writes process.

With 17K+ memories, a single /recall can take 50-100ms. During this time no other requests can be processed.

Proposed Fix

Replace Mutex<Uteke> with RwLock<Uteke>:

  • Read endpoints (recall, search, list, stats, health, namespaces, graph, room/, doc/, context) = read()
  • Write endpoints (remember, forget, room/create, room/delete, doc/create, doc/move, doc/delete) = write()

Acceptance Criteria

Functional

  • Replace Mutex<Uteke> with RwLock<Uteke>
  • Read endpoints use read() — concurrent access
  • Write endpoints use write() — exclusive access

Verification (CMO can run without reading code)

  • Start server → curl GET /health returns 200 (basic sanity)
  • 10 simultaneous curl POST /recall requests → all return 200 within 500ms each (no serialization)
  • During a POST /recall, another POST /recall completes without waiting (concurrent reads)
  • During a POST /remember (write), a POST /recall (read) can still complete (read doesn't block on write)
  • During a POST /remember, a second POST /remember waits until first completes (writes are exclusive)
  • No crashes or panics under 50 concurrent mixed read/write requests
  • cargo test passes (no data race warnings from #[warn(dead_code)])

Tests

  • Unit: verify RwLock compiles and passes existing tests
  • Integration: concurrent recall benchmark (10 goroutines/threads)

Priority

Medium — performance bottleneck under load.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions