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

feat(workers): many small RQ worker features #18995

Merged
merged 6 commits into from Nov 25, 2022

Conversation

ankush
Copy link
Member

@ankush ankush commented Nov 24, 2022

reference for all of this: https://python-rq.org/docs/workers/


Multi-queue consumption

Why?

  • servers with insufficient RAM. Using 1 common worker vs 3 workers = ~120-180MB RAM saved.
  • Bench with low # of sites which dont truly need 3 separate workers for 3 queues because the workload is very low and wait times are tolerable.
  • Lighter development setups. After this change you can use single worker for all queues like this:
- worker_short: bench worker --queue short
- worker_long: bench worker --queue long
- worker_default: bench worker --queue default

+ worker: bench worker --queue short,default,long

If you drop --queue argument altogether then all queues are consumed. So both of these are equievalent if you dont have custom queues.

worker: bench worker --queue short,default,long
worker: bench worker

Note: RQ has inbuilt prioritization, the order of specified queues matters. So in the example above until the short queue is finished default queue won't be worked upon and so on.


burst mode

If you only periodically need higher worker count you can do so by calling bench worker --burst this can be useful in high workload scenario.

Worker exits once specified queues are cleared.


Dequeue strategies

bench worker --strategy round_robin will give equal priority to all specified queues. random does it randomly. Default strategy (no flags required) gives priority based on order you specify.

docs: https://frappeframework.com/docs/v14/user/en/api/background_jobs

@ankush ankush requested a review from a team as a code owner November 24, 2022 08:15
@ankush ankush requested review from shariquerik and removed request for a team November 24, 2022 08:15
@github-actions github-actions bot added the add-test-cases Add test case to validate fix or enhancement label Nov 24, 2022
@ankush ankush marked this pull request as draft November 24, 2022 08:16
@ankush ankush removed the add-test-cases Add test case to validate fix or enhancement label Nov 24, 2022
@codecov
Copy link

codecov bot commented Nov 24, 2022

Codecov Report

Merging #18995 (ed28626) into develop (b170311) will decrease coverage by 0.07%.
The diff coverage is 41.66%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #18995      +/-   ##
===========================================
- Coverage    63.46%   63.39%   -0.08%     
===========================================
  Files          750      750              
  Lines        67621    67733     +112     
  Branches      6027     6027              
===========================================
+ Hits         42917    42939      +22     
- Misses       21230    21320      +90     
  Partials      3474     3474              
Flag Coverage Δ
server-mariadb 67.28% <55.55%> (-0.03%) ⬇️
server-postgres 67.29% <55.55%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ankush ankush changed the title feat(workers): allow consuming multiple queues feat(workers): many small RQ worker features Nov 24, 2022
@ankush ankush force-pushed the multi_queue_workers branch 2 times, most recently from c24619c to 7ebc046 Compare November 24, 2022 11:07
@ankush ankush marked this pull request as ready for review November 24, 2022 12:18
@ankush ankush requested review from phot0n and removed request for shariquerik and surajshetty3416 November 24, 2022 12:19
@ankush ankush added docs-pending Feature was merged without docs for some reason docs-required and removed docs-pending Feature was merged without docs for some reason labels Nov 24, 2022
frappe/utils/background_jobs.py Outdated Show resolved Hide resolved
frappe/core/doctype/rq_worker/rq_worker.py Outdated Show resolved Hide resolved
frappe/commands/scheduler.py Outdated Show resolved Hide resolved
frappe/utils/background_jobs.py Show resolved Hide resolved
frappe/core/doctype/rq_worker/rq_worker.json Show resolved Hide resolved
@ankush ankush added the defer backport Backports for some PR are deferred for a week or two to test them properly before releasing label Nov 25, 2022
@ankush ankush merged commit 4661083 into frappe:develop Nov 25, 2022
1 check passed
@ankush ankush deleted the multi_queue_workers branch November 25, 2022 07:17
@ankush ankush added backport version-14-hotfix backport to version 14 and removed docs-required defer backport Backports for some PR are deferred for a week or two to test them properly before releasing labels Nov 25, 2022
ankush added a commit that referenced this pull request Nov 30, 2022
* fix: prioritize short queue when using all queues

(cherry picked from commit b7cef3a)

* feat(workers): allow consuming multiple queues

(cherry picked from commit 40b2929)

* refactor: consider multi-queue consumption

(cherry picked from commit 0ebd394)

* feat: burst mode in workers

https://python-rq.org/docs/workers/#burst-mode
(cherry picked from commit aece93f)

# Conflicts:
#	frappe/commands/scheduler.py
#	frappe/core/doctype/rq_job/test_rq_job.py

* feat: support dequeuing strategies for worker

(cherry picked from commit a8bf86e)

# Conflicts:
#	frappe/commands/scheduler.py

* refactor: simpler deque strat selection

Co-authored-by: Ritwik Puri <ritwikpuri5678@gmail.com>
(cherry picked from commit ed28626)

* chore: conflicts

Co-authored-by: Ankush Menat <ankush@frappe.io>
Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
frappe-pr-bot pushed a commit that referenced this pull request Dec 6, 2022
# [14.18.0](v14.17.1...v14.18.0) (2022-12-06)

### Bug Fixes

* attribute error on export of reports with additional columns ([#19105](#19105)) ([2b43d5b](2b43d5b))
* check for bad zip files during unzipping in file doctype ([#19058](#19058)) ([#19060](#19060)) ([96c928e](96c928e))
* **db_query:** Disallow usage of certain functions in *_by ([#18981](#18981)) ([#19135](#19135)) ([5376755](5376755))
* **db_query:** Space resilient sanitization (backport [#18996](#18996)) ([#19045](#19045)) ([ab8422f](ab8422f))
* disable signups by default (backport [#19114](#19114)) ([#19118](#19118)) ([3dd2775](3dd2775))
* do not escape undefined txt ([86267e9](86267e9))
* empty search shows `None` ([#19055](#19055)) ([#19057](#19057)) ([1cd0bc2](1cd0bc2))
* ensure correct parenttype when retrieving roles ([af55da9](af55da9))
* give more weight to sequential matches ([#19121](#19121)) ([#19122](#19122)) ([16f642f](16f642f))
* ignore empty/`None` scripts ([#19111](#19111)) ([#19113](#19113)) ([2a96757](2a96757))
* keep actions on right ([7d3e47b](7d3e47b))
* LDAP - check each email in list before creating user ([250f787](250f787))
* only check for special characters in fieldname ([#19061](#19061)) ([#19065](#19065)) ([de0facc](de0facc)), closes [#18965](#18965)
* only System Manager can access Google Drive ([05be9ee](05be9ee))
* Optimize check field type is tab break if the doctype has a workflow ([#18858](#18858)) ([d9ce6c1](d9ce6c1))
* site creation using non-root users ([#19014](#19014)) ([#19043](#19043)) ([844e744](844e744))
* socketio spawn error ([#19070](#19070)) ([#19071](#19071)) ([75a54eb](75a54eb))
* type conversion for read receipt in communication email ([e0f7dd4](e0f7dd4))
* use permtype from passed arguments in has_web_form_permission when applying document permissions ([91c99d2](91c99d2))
* use webform doctype rather than allowing user to pass any doctype ([2be3178](2be3178))
* **UX:** freeze on delete ([#19094](#19094)) ([dd4791a](dd4791a))
* **UX:** Make fetch_from read_only if fetch_is_empty is not set ([#19025](#19025)) ([#19041](#19041)) ([feed227](feed227))
* Widget control on dashboard chart breaks on smaller screens ([d6dedca](d6dedca))

### Features

* **workers:** many small RQ worker features (backport [#18995](#18995)) ([#19046](#19046)) ([37dbada](37dbada))
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport version-14-hotfix backport to version 14
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants