OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

Refactor EventStream to use single-file storage

Open tofarr opened this issue 1 year ago • 0 comments

Event Stream Storage Refactoring

Changes

  • Modified EventStream to store all events in a single JSON file per session instead of one file per event
  • Added performance tests to verify the implementation
  • Improved storage efficiency for small events (< 200 bytes)
  • Added metrics for read/write operations

Performance Metrics

The performance tests show:

  • Fast write operations (~0.35ms per event)
  • Efficient read operations
  • Reduced storage overhead by using a single file

Testing

  • Added comprehensive performance tests in tests/load/test_event_stream_perf.py
  • Tests verify event creation, storage, retrieval, and content integrity
  • Includes metrics for common operations

Benefits

  • Reduced filesystem overhead
  • Better storage efficiency for small events
  • Simpler file management
  • Potentially better performance for bulk operations

Trade-offs

  • Entire events list needs to be loaded into memory
  • Potential file contention with multiple writers
  • File size grows over time as more events are added

To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=ghcr.io/all-hands-ai/runtime:d96477a-nikolaik   --name openhands-app-d96477a   ghcr.io/all-hands-ai/runtime:d96477a

tofarr avatar Nov 01 '24 22:11 tofarr