Skip to content

Poor performance when enqueuing many throttled jobs because of unindexed queries #1603

@Intrepidd

Description

@Intrepidd

When the concurrency extension looks up for existing queued jobs within the throttle period, it performs the following query :

enqueued_within_period = GoodJob::Job.where(concurrency_key: key)
.where(GoodJob::Job.arel_table[:created_at].gt(throttle_period.ago))
.count

In my case, this query will run in 200-300ms for each enqueue attempt, so it adds up pretty quickly when trying to enqueue hundreds of jobs.

The index on concurrency_key has a where finished_at is NULL, so it can't be used here.

Would it make sense to have an index solely on concurrency_key ?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions