good_job-async_executor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +338 -0
- data/Rakefile +11 -0
- data/lib/good_job/async_executor/claim_release.rb +100 -0
- data/lib/good_job/async_executor/configuration_extension.rb +38 -0
- data/lib/good_job/async_executor/connection_cleanup.rb +192 -0
- data/lib/good_job/async_executor/errors.rb +11 -0
- data/lib/good_job/async_executor/executor.rb +404 -0
- data/lib/good_job/async_executor/hard_stop.rb +68 -0
- data/lib/good_job/async_executor/log_subscriber_extension.rb +21 -0
- data/lib/good_job/async_executor/multi_scheduler_extension.rb +92 -0
- data/lib/good_job/async_executor/queue_segment.rb +61 -0
- data/lib/good_job/async_executor/queue_shape.rb +71 -0
- data/lib/good_job/async_executor/reactor/draining.rb +173 -0
- data/lib/good_job/async_executor/reactor.rb +319 -0
- data/lib/good_job/async_executor/reload_gate.rb +168 -0
- data/lib/good_job/async_executor/scheduler_extension.rb +164 -0
- data/lib/good_job/async_executor/version.rb +8 -0
- data/lib/good_job/async_executor/worker_pool.rb +86 -0
- data/lib/good_job/async_executor.rb +30 -0
- metadata +118 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'good_job/async_executor/queue_segment'
|
|
5
|
+
|
|
6
|
+
module GoodJob
|
|
7
|
+
module AsyncExecutor
|
|
8
|
+
# One scheduler GoodJob builds from the queue string: the queues it runs and how it runs them (`shape`).
|
|
9
|
+
#
|
|
10
|
+
# `queues` is the segment's comma-separated queue list, each name stripped and without the `+` that orders them.
|
|
11
|
+
# GoodJob's other tokens are kept as written: `*` (every queue) and a leading `-` (every queue but these, on the
|
|
12
|
+
# first name only, eg. `["-mice", "elephants"]`). A segment with no queue list (`:5`) still gets a scheduler from
|
|
13
|
+
# GoodJob, so it is a pool with no queues and counts towards the totals.
|
|
14
|
+
WorkerPool = Data.define(:queues, :shape) do
|
|
15
|
+
class << self
|
|
16
|
+
#: (QueueSegment) -> WorkerPool
|
|
17
|
+
def from_segment(segment)
|
|
18
|
+
queues = segment.queue_name.to_s.split(',').map { |queue| queue.strip.delete_prefix('+') }
|
|
19
|
+
new(queues:, shape: segment.shape)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#: () -> bool
|
|
24
|
+
def threads?
|
|
25
|
+
!shape.fibers?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#: () -> bool
|
|
29
|
+
def fibers?
|
|
30
|
+
shape.fibers?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# The most jobs this pool runs at once: its threads, or all its fibers.
|
|
34
|
+
#
|
|
35
|
+
#: () -> Integer
|
|
36
|
+
def concurrency
|
|
37
|
+
shape.max_concurrency
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class << self
|
|
42
|
+
# The worker pools this process runs, one per `;` segment, read exactly as `MultiScheduler.from_configuration`
|
|
43
|
+
# reads them (the same parser), without building anything or touching the database. Safe in an ERB
|
|
44
|
+
# `database.yml`. Raises ArgumentError for an invalid count, as booting would.
|
|
45
|
+
#
|
|
46
|
+
# Pipe-delimited subprocess pools (`a:5|b:10f`) are flattened, as GoodJob flattens them for one process, so these
|
|
47
|
+
# are every pool's schedulers. For one subprocess's pools, pass its configuration
|
|
48
|
+
# (`configuration.subprocess_configs[index]`).
|
|
49
|
+
#
|
|
50
|
+
#: (?GoodJob::Configuration) -> Array[WorkerPool]
|
|
51
|
+
def worker_pools(configuration = GoodJob.configuration)
|
|
52
|
+
QueueSegment.all(configuration).map { |segment| WorkerPool.from_segment(segment) }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Job-running threads in thread pools. Reactor threads are not counted (see `worker_reactor_threads_count`).
|
|
56
|
+
#
|
|
57
|
+
#: (?GoodJob::Configuration) -> Integer
|
|
58
|
+
def worker_threads_count(configuration = GoodJob.configuration)
|
|
59
|
+
worker_pools(configuration).select(&:threads?).sum(&:concurrency)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Fibers across every fiber pool.
|
|
63
|
+
#
|
|
64
|
+
#: (?GoodJob::Configuration) -> Integer
|
|
65
|
+
def worker_fibers_count(configuration = GoodJob.configuration)
|
|
66
|
+
worker_pools(configuration).select(&:fibers?).sum(&:concurrency)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Reactor threads across every fiber pool (`500f` has 1, `5x100f` has 5): with `worker_threads_count`, the
|
|
70
|
+
# threads the worker pools start.
|
|
71
|
+
#
|
|
72
|
+
#: (?GoodJob::Configuration) -> Integer
|
|
73
|
+
def worker_reactor_threads_count(configuration = GoodJob.configuration)
|
|
74
|
+
worker_pools(configuration).select(&:fibers?).sum { |pool| pool.shape.reactors }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# The most jobs in flight at once, threads plus fibers, and so the most ActiveRecord connection leases running
|
|
78
|
+
# jobs can hold at once. Size the ActiveRecord pool with this, not with a thread count.
|
|
79
|
+
#
|
|
80
|
+
#: (?GoodJob::Configuration) -> Integer
|
|
81
|
+
def worker_concurrency(configuration = GoodJob.configuration)
|
|
82
|
+
worker_pools(configuration).sum(&:concurrency)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'good_job'
|
|
5
|
+
require 'good_job/async_executor/version'
|
|
6
|
+
require 'good_job/async_executor/errors'
|
|
7
|
+
require 'good_job/async_executor/hard_stop'
|
|
8
|
+
require 'good_job/async_executor/queue_shape'
|
|
9
|
+
require 'good_job/async_executor/queue_segment'
|
|
10
|
+
require 'good_job/async_executor/worker_pool'
|
|
11
|
+
require 'good_job/async_executor/reactor'
|
|
12
|
+
require 'good_job/async_executor/reload_gate'
|
|
13
|
+
require 'good_job/async_executor/claim_release'
|
|
14
|
+
require 'good_job/async_executor/executor'
|
|
15
|
+
require 'good_job/async_executor/connection_cleanup'
|
|
16
|
+
require 'good_job/async_executor/configuration_extension'
|
|
17
|
+
require 'good_job/async_executor/log_subscriber_extension'
|
|
18
|
+
require 'good_job/async_executor/multi_scheduler_extension'
|
|
19
|
+
require 'good_job/async_executor/scheduler_extension'
|
|
20
|
+
|
|
21
|
+
module GoodJob
|
|
22
|
+
# Runs chosen GoodJob queue groups as fibers on reactor threads.
|
|
23
|
+
module AsyncExecutor
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
GoodJob::Configuration.prepend(GoodJob::AsyncExecutor::ConfigurationExtension)
|
|
28
|
+
GoodJob::MultiScheduler.singleton_class.prepend(GoodJob::AsyncExecutor::MultiSchedulerExtension)
|
|
29
|
+
GoodJob::Scheduler.prepend(GoodJob::AsyncExecutor::SchedulerExtension)
|
|
30
|
+
GoodJob::LogSubscriber.prepend(GoodJob::AsyncExecutor::LogSubscriberExtension)
|
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: good_job-async_executor
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Minty Fresh
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: activesupport
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '8.1'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '8.2'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '8.1'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '8.2'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: async
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '2'
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '2'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: good_job
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '4.23'
|
|
53
|
+
- - "<"
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '5'
|
|
56
|
+
type: :runtime
|
|
57
|
+
prerelease: false
|
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '4.23'
|
|
63
|
+
- - "<"
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '5'
|
|
66
|
+
description: Lets GoodJob run selected queue groups as many fibers on a few reactor
|
|
67
|
+
threads, so IO-bound jobs can run at high concurrency.
|
|
68
|
+
email:
|
|
69
|
+
- 7896757+mintyfresh@users.noreply.github.com
|
|
70
|
+
executables: []
|
|
71
|
+
extensions: []
|
|
72
|
+
extra_rdoc_files: []
|
|
73
|
+
files:
|
|
74
|
+
- MIT-LICENSE
|
|
75
|
+
- README.md
|
|
76
|
+
- Rakefile
|
|
77
|
+
- lib/good_job/async_executor.rb
|
|
78
|
+
- lib/good_job/async_executor/claim_release.rb
|
|
79
|
+
- lib/good_job/async_executor/configuration_extension.rb
|
|
80
|
+
- lib/good_job/async_executor/connection_cleanup.rb
|
|
81
|
+
- lib/good_job/async_executor/errors.rb
|
|
82
|
+
- lib/good_job/async_executor/executor.rb
|
|
83
|
+
- lib/good_job/async_executor/hard_stop.rb
|
|
84
|
+
- lib/good_job/async_executor/log_subscriber_extension.rb
|
|
85
|
+
- lib/good_job/async_executor/multi_scheduler_extension.rb
|
|
86
|
+
- lib/good_job/async_executor/queue_segment.rb
|
|
87
|
+
- lib/good_job/async_executor/queue_shape.rb
|
|
88
|
+
- lib/good_job/async_executor/reactor.rb
|
|
89
|
+
- lib/good_job/async_executor/reactor/draining.rb
|
|
90
|
+
- lib/good_job/async_executor/reload_gate.rb
|
|
91
|
+
- lib/good_job/async_executor/scheduler_extension.rb
|
|
92
|
+
- lib/good_job/async_executor/version.rb
|
|
93
|
+
- lib/good_job/async_executor/worker_pool.rb
|
|
94
|
+
homepage: https://github.com/mintyfresh/good_job-async_executor
|
|
95
|
+
licenses:
|
|
96
|
+
- MIT
|
|
97
|
+
metadata:
|
|
98
|
+
homepage_uri: https://github.com/mintyfresh/good_job-async_executor
|
|
99
|
+
source_code_uri: https://github.com/mintyfresh/good_job-async_executor
|
|
100
|
+
rubygems_mfa_required: 'true'
|
|
101
|
+
rdoc_options: []
|
|
102
|
+
require_paths:
|
|
103
|
+
- lib
|
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - ">="
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '3.3'
|
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
requirements: []
|
|
115
|
+
rubygems_version: 4.0.20
|
|
116
|
+
specification_version: 4
|
|
117
|
+
summary: Runs chosen GoodJob queue groups as fibers on reactor threads
|
|
118
|
+
test_files: []
|