Skip to content

Optimize Latency for AI-Powered Features(by Reducing Sidekiq Dependency)

Description

AI-powered features are experiencing latency issues and service disruptions during Sidekiq outages. This issue aims to explore and implement solutions to reduce latency and improve reliability for these features.

Problem Statement

  1. AI-powered features, are experiencing high latency due to Sidekiq processing.
  2. During Sidekiq outages, these features become unusable, impacting user experience.
  3. Current architecture adds unnecessary round-trip delays, affecting response times.

Proposed Solutions:

1. Workhorse Offloading:

  • Pros:
    • Reduces load on Rails/Puma workers
    • Minimizes time spent in Rails
    • Similar to existing code suggestion implementation
  • Cons:
    • Rails loses visibility of AI gateway responses
    • Requires maintaining connection logic in both Rails and Workhorse
    • Limited by current websocket support for some AI features

2. Direct Communication with AI Gateway:

  • Pros:
    • Eliminates Sidekiq dependency
    • Potentially reduces overall latency
  • Cons:
    • Requires significant architectural changes
    • May need to move logic out of Rails into AI gateway

3. ActionController::Live with WebSockets:

  • Pros:
    • Enables real-time updates
    • Could reduce load on Sidekiq workers
  • Cons:
    • May spawn uncontrolled threads in Rails
    • Could complicate capacity planning

4. Fibers for Lightweight Concurrency:

  • Pros:
    • Improves job processing efficiency within Ruby threads
    • Better resource utilization for I/O-bound tasks
  • Cons:
    • May require significant refactoring of existing code

Possible Next Steps

  1. Conduct detailed latency analysis to identify bottlenecks
  2. Set specific latency targets for AI-powered features
  3. Create proof-of-concept implementations for proposed solutions
  4. Consult with infrastructure team on feasibility and impact of each approach
  5. Evaluate performance gains and integration complexity for each solution

Links

  1. Code Suggestions Implementation
  2. Merge Request for Workhorse Implementation
  3. Related Issue: Completion Worker Delay
  4. Code Suggestion Performance Dashboard
    • Epic: &12224
    • Context: Detailed performance analysis for code suggestions, including latency breakdowns.
  5. Sidekiq Incident Report
  6. Flamegraph Profiling Guide
  7. Latency Monitoring Dashboard
  8. ActionController::Live Documentation
  9. Vertex AI Claude Integration
Edited by David O'Regan