gruf-queue 0.1.4 → 0.1.5
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 +4 -4
- data/CHANGELOG.md +29 -0
- data/README.md +3 -2
- data/lib/gruf/queue/pool_enhancements.rb +43 -15
- data/lib/gruf/queue/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c95bbcdd543d4648972f17a59e97f8c3113964fd0f3a38da423a17f6a98913e
|
4
|
+
data.tar.gz: 7079457c7e33fc6a272f8974998a5db14d743e234197625bd5b71c28332273d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55862eaad56dfe99040d110c419581b58bd12a418d2729ef73788332ab9ddaac6b39638f19de2a104550c696bd0a92e61dbc531bfbae664d4725b681322f3b7f
|
7
|
+
data.tar.gz: 64de88a3ec9c97d34bf32c76fae59cd4b3b9340b5a13a0435ed6e1b6ab9e3dde7ba34f0f0d18e297c065c32e6108ec6581abe826d3f6c2c0a80f917aa1ed2f60
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.1.5]
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- **BREAKING**: Complete rewrite of pool enhancement architecture
|
12
|
+
- Eliminated AlwaysReadyQueue and all worker queue management complexity
|
13
|
+
- Simplified to direct job scheduling with `@jobs << [blk, args]`
|
14
|
+
- Custom `schedule`, `start`, and `loop_execute_jobs` methods
|
15
|
+
- Workers now simply loop and pop jobs from single @jobs queue
|
16
|
+
|
17
|
+
### Added
|
18
|
+
- Custom job execution loop with proper error handling
|
19
|
+
- Thread-safe job scheduling with stop_mutex synchronization
|
20
|
+
- Graceful shutdown support integrated into job processing loop
|
21
|
+
|
22
|
+
### Removed
|
23
|
+
- AlwaysReadyQueue class and all null object pattern code
|
24
|
+
- Complex worker state tracking and ready_workers queue management
|
25
|
+
- Unnecessary abstractions and indirection layers
|
26
|
+
|
27
|
+
### Fixed
|
28
|
+
- Eliminated all worker queue complexity and potential race conditions
|
29
|
+
- Much more predictable and maintainable job processing
|
30
|
+
- Simplified shutdown process with clear control flow
|
31
|
+
|
32
|
+
### Improved
|
33
|
+
- Dramatically simplified codebase with single job queue approach
|
34
|
+
- Better performance through reduced complexity
|
35
|
+
- Easier to understand and debug job processing flow
|
36
|
+
|
8
37
|
## [0.1.4]
|
9
38
|
|
10
39
|
### Changed
|
data/README.md
CHANGED
@@ -8,8 +8,9 @@ Simple GRPC::Pool enhancement that replaces worker-based capacity checking with
|
|
8
8
|
|
9
9
|
## What it does
|
10
10
|
|
11
|
-
-
|
12
|
-
-
|
11
|
+
- Simplifies `GRPC::Pool` by removing complex worker queue management
|
12
|
+
- Direct job scheduling to `@jobs` queue with idle thread processing
|
13
|
+
- Uses `jobs_waiting < threshold` for capacity management
|
13
14
|
- Configurable threshold via `GRUF_MAX_WAITING_REQUESTS` (default: 60)
|
14
15
|
- Supports graceful shutdown
|
15
16
|
|
@@ -2,30 +2,58 @@
|
|
2
2
|
|
3
3
|
module Gruf
|
4
4
|
module Queue
|
5
|
-
# Null object implementation for worker queue management.
|
6
|
-
# Provides clean interface without complex worker state tracking.
|
7
|
-
class AlwaysReadyQueue
|
8
|
-
def empty? = false
|
9
|
-
|
10
|
-
def <<(*) = self
|
11
|
-
|
12
|
-
def push(*) = self
|
13
|
-
|
14
|
-
def pop = ::Queue.new
|
15
|
-
|
16
|
-
def size = 1
|
17
|
-
end
|
18
|
-
|
19
5
|
# Enhanced GRPC::Pool with job count based capacity management
|
20
6
|
module PoolEnhancements
|
21
7
|
DEFAULT_MAX_WAITING_REQUESTS = 60
|
22
8
|
|
23
9
|
def initialize(...)
|
24
10
|
super
|
25
|
-
@ready_workers = AlwaysReadyQueue.new
|
26
11
|
@max_waiting_requests = ENV.fetch('GRUF_MAX_WAITING_REQUESTS', DEFAULT_MAX_WAITING_REQUESTS).to_i
|
27
12
|
end
|
28
13
|
|
14
|
+
def schedule(*args, &blk)
|
15
|
+
return if blk.nil?
|
16
|
+
|
17
|
+
@stop_mutex.synchronize do
|
18
|
+
if @stopped
|
19
|
+
GRPC.logger.warn('did not schedule job, already stopped')
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
@jobs << [blk, args]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def start
|
28
|
+
@stop_mutex.synchronize do
|
29
|
+
raise 'already stopped' if @stopped
|
30
|
+
end
|
31
|
+
until @workers.size == @size.to_i
|
32
|
+
next_thread = Thread.new do
|
33
|
+
catch(:exit) do # allows { throw :exit } to kill a thread
|
34
|
+
loop_execute_jobs
|
35
|
+
end
|
36
|
+
remove_current_thread
|
37
|
+
end
|
38
|
+
@workers << next_thread
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def loop_execute_jobs
|
43
|
+
loop do
|
44
|
+
begin
|
45
|
+
blk, args = @jobs.pop
|
46
|
+
blk.call(*args)
|
47
|
+
rescue StandardError, GRPC::Core::CallError => e
|
48
|
+
GRPC.logger.warn('Error in worker thread')
|
49
|
+
GRPC.logger.warn(e)
|
50
|
+
end
|
51
|
+
@stop_mutex.synchronize do
|
52
|
+
return if @stopped
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
29
57
|
def ready_for_work?
|
30
58
|
return false if @stopped
|
31
59
|
|
data/lib/gruf/queue/version.rb
CHANGED