Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor job queue #2275

Merged
merged 2 commits into from
Mar 26, 2021
Merged

Refactor job queue #2275

merged 2 commits into from
Mar 26, 2021

Conversation

dapplion
Copy link
Contributor

@dapplion dapplion commented Mar 26, 2021

Motivation

To develop #2265 we need a queue that is able to choose between FIFO and LIFO. Our current JobQueue does not support that since it-pushable hardcodes a FIFO module inside it.

Description

I've taken this opportunity to refactor the queue with backed-in metrics that will be used on all of it's consumers

  • Use a simple enum to track queue state instead on an async iterable.
  • Keep jobs in an array in the JobQueue instance to consume them differently in FIFO or LIFO mode
  • Yield to the macro queue after every job with a sleep(0)
  • Incorporate three metrics into the JobQueue (only if requested)
    • ${prefix}_length: Count of total queue length
    • ${prefix}_dropped_jobs_total: Count of total dropped jobs
    • ${prefix}_job_time_seconds: Time (async) to process queue job

The metrics use a new API from prom-client: the .collect() function available in v13. It allows to de-duplicated state from the prometheus client if that state is already tracked by the application. This is used in the queue length metric, and only computed on demand.

@github-actions github-actions bot added the scope-networking All issues related to networking, gossip, and libp2p. label Mar 26, 2021
@codeclimate
Copy link

codeclimate bot commented Mar 26, 2021

Code Climate has analyzed commit 883c0e6 and detected 0 issues on this pull request.

View more on Code Climate.

@dapplion dapplion force-pushed the dapplion/refactor-job-queue branch from 20fb63b to af74b31 Compare March 26, 2021 11:33
mpetrunic
mpetrunic previously approved these changes Mar 26, 2021
Copy link
Member

@mpetrunic mpetrunic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@wemeetagain wemeetagain merged commit ce48eaf into master Mar 26, 2021
@wemeetagain wemeetagain deleted the dapplion/refactor-job-queue branch March 26, 2021 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope-networking All issues related to networking, gossip, and libp2p.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants