| Metadata | Value |
|---|---|
| Status | Active |
| Version | 1.1.0 |
| Last Updated | 2026-09-10 |
| Author | Sangeetha Grantha Team |
| Document Type | Design reference |
[!NOTE] Design/reference material: this page may include proposals or earlier implementation assumptions. Use current operations guides for implemented behavior and current operating steps.
A review of the application logs (sangita_logs.txt) reveals a high frequency of database queries originating from the background worker service (BulkImportWorkerService).
FOR UPDATE on frequent polls can lead to lock contention, although SKIP LOCKED (if used/implied) mitigates blocking.The following queries appear repeatedly (every ~750ms per worker):
SELECT ... FROM import_task_run
WHERE status IN ('pending', 'retryable')
AND job_type = 'entity_resolution'
AND batch_status = 'running'
LIMIT 1 FOR UPDATE
SELECT ... FROM import_task_run
WHERE status IN ('pending', 'retryable')
AND job_type = 'scrape'
LIMIT 1 FOR UPDATE
SELECT ... FROM import_task_run
WHERE job_type = 'manifest_ingest'
LIMIT 1 FOR UPDATE
To address this, we will implement a multi-layered optimization strategy, tracked under TRACK-006.
Impact: Drastically reduces idle queries. Logic:
pollInterval = 750ms.750ms -> 1.5s -> 3s -> ... -> Max (e.g., 15s).750ms.Impact: Increases throughput during active loads. Logic:
LIMIT 1, workers should claim LIMIT N (e.g., 5) tasks in a single transaction.Impact: Makes the “Check for work” query faster.
Recommendation:
Ensure the following composite index exists on import_task_run:
CREATE INDEX CONCURRENTLY idx_import_task_run_polling
ON import_task_run (job_id, status, created_at);
-- Note: job_type is on import_job, not task_run, requiring a JOIN.
-- Optimizing the JOIN or denormalizing job_type to task_run might be considered if JOIN performance degrades.
Impact: Reduces background noise. Logic:
| Phase | Action | Est. Effort |
|---|---|---|
| Phase 1 | Implement AdaptivePolling in BulkImportWorkerService. |
Low |
| Phase 2 | Update BulkImportRepository.claimNextPendingTask to support batch size (e.g., limit: Int = 1). |
Medium |
| Phase 3 | Execute database migration for indices (if analysis confirms missing index). | Low |
After implementation, we will monitor sangita_logs.txt to verify: