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

Add thread based delayed workers #3887

Merged
merged 9 commits into from
Sep 3, 2024
Merged

Add thread based delayed workers #3887

merged 9 commits into from
Sep 3, 2024

Conversation

johha
Copy link
Contributor

@johha johha commented Jul 16, 2024

Currently operators can configure the number of delayed job workers for the generic queue with two parameters:

  • number of cc-worker VMs in the cf bosh deployment
  • number of worker processes on each VM (capi parameter number_of_workers)

Most delayed jobs however are limited by I/O (e.g. database queries) and don't do a lot of processing in ruby.
To increase the throughput on a single worker VM while reducing resource consumption (threads vs processes) this change introduces the option to run multiple delayed worker threads in a single process.
The number of workers calculates like this: num_cc_workers X number_processes X num_threads

Tests comparing 8 worker processes versus 8 worker threads show that the throughput is the same while the memory consumption is ~60% lower. Allowing operators to run more workers on a single VM.

All threads have a graceful shutdown period of 30 seconds (like monit) so that long running jobs have a chance to finish.
In case a thread crashes with an error a graceful shutdown is triggered and the whole process will exit with an error. Delayed::Job already catches all errors during job execution (https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/worker.rb#L241-L244).

@johha johha force-pushed the delayed-worker-threads branch from e89734a to 61d2742 Compare July 26, 2024 09:55
johha added a commit to cloudfoundry/capi-release that referenced this pull request Jul 26, 2024
@johha johha marked this pull request as ready for review July 26, 2024 11:09
johha added a commit to cloudfoundry/capi-release that referenced this pull request Jul 26, 2024
johha added a commit to cloudfoundry/capi-release that referenced this pull request Jul 26, 2024
johha added a commit to cloudfoundry/capi-release that referenced this pull request Jul 26, 2024
johha added a commit to cloudfoundry/capi-release that referenced this pull request Jul 26, 2024
@johha johha force-pushed the delayed-worker-threads branch from 61d2742 to 96a8251 Compare August 7, 2024 06:32
@johha johha marked this pull request as draft August 8, 2024 15:42
@johha johha force-pushed the delayed-worker-threads branch 3 times, most recently from 49b63f5 to 635c570 Compare August 19, 2024 14:32
johha added a commit to cloudfoundry/capi-release that referenced this pull request Aug 19, 2024
johha added a commit to cloudfoundry/capi-release that referenced this pull request Aug 19, 2024
@johha johha marked this pull request as ready for review August 19, 2024 16:21
@johha johha requested a review from Samze August 20, 2024 09:02
@johha johha force-pushed the delayed-worker-threads branch from e5b8ea8 to 49b799b Compare August 20, 2024 09:16
johha added a commit to cloudfoundry/capi-release that referenced this pull request Aug 21, 2024
johha added a commit to cloudfoundry/capi-release that referenced this pull request Aug 21, 2024
@johha johha force-pushed the delayed-worker-threads branch from 661614c to 4fb1e59 Compare August 21, 2024 15:57
Samze
Samze previously approved these changes Aug 30, 2024
Copy link
Contributor

@Samze Samze left a comment

Choose a reason for hiding this comment

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

LGTM

lib/delayed_job/threaded_worker.rb Outdated Show resolved Hide resolved
lib/delayed_job/threaded_worker.rb Outdated Show resolved Hide resolved
spec/unit/lib/delayed_job/threaded_worker_spec.rb Outdated Show resolved Hide resolved
spec/unit/lib/delayed_job/threaded_worker_spec.rb Outdated Show resolved Hide resolved
spec/unit/lib/delayed_job/threaded_worker_spec.rb Outdated Show resolved Hide resolved
spec/unit/lib/delayed_job/threaded_worker_spec.rb Outdated Show resolved Hide resolved
spec/unit/lib/delayed_job/threaded_worker_spec.rb Outdated Show resolved Hide resolved
spec/unit/lib/delayed_job/threaded_worker_spec.rb Outdated Show resolved Hide resolved
spec/unit/lib/delayed_job/threaded_worker_spec.rb Outdated Show resolved Hide resolved
Co-authored-by: Johannes Haass <[email protected]>
Co-authored-by: Johannes Haass <[email protected]>
In the event of an unexpected error in a thread, this change ensures that all other
threads that are still running will get a graceful shutdown period of 30
seconds (like monit). After that, the remaining threads are killed and the
threaded worker process will fail with an exception.
This ensures that monit can restart the failed process.

DelayedJobs already handles all possible errors during job execution,
so the graceful shutdown is only applied to errors that occur
after a job has finished.

Co-authored-by: Johannes Haass <[email protected]>
@johha johha merged commit 8200f4c into main Sep 3, 2024
8 checks passed
@johha johha deleted the delayed-worker-threads branch September 3, 2024 12:36
ari-wg-gitbot added a commit to cloudfoundry/capi-release that referenced this pull request Sep 3, 2024
Changes in cloud_controller_ng:

- Add thread based delayed workers
    PR: cloudfoundry/cloud_controller_ng#3887
    Author: Johannes Haass <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants