concurrent-ruby 1.2.3 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/concurrent-ruby/concurrent/concurrent_ruby.jar +0 -0
- data/lib/concurrent-ruby/concurrent/executor/java_executor_service.rb +2 -6
- data/lib/concurrent-ruby/concurrent/utility/processor_counter.rb +65 -0
- data/lib/concurrent-ruby/concurrent/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7841a791b1b148d8e8efea668fc70f3acc98c247f8d49fea58a4c672b45a62e6
|
4
|
+
data.tar.gz: 380ca8252b5b9251f30cd925d8b08f2afae56db19a210a8726b44c7304e5cd84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e479a5475e8d6dd7b3589a76300ccc73162cbceb8a15b721462394ff92f02054ba06e8ec5ee3ab08aa391a846d00492c708c893416b4c0c159c53d9b065f755f
|
7
|
+
data.tar.gz: 52daa298a6820a10756bfbf472aff566f5b5508f4e014352aa7a8d2516873b1e69b6392cde1379c0feaeba7c054c6c6c919613c3e09ac4d2328939cde3f01444
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## Current
|
2
2
|
|
3
|
+
## Release v1.3.1 (29 May 2024)
|
4
|
+
|
5
|
+
* Release 1.3.0 was broken when pushed to RubyGems. 1.3.1 is a packaging fix.
|
6
|
+
|
7
|
+
## Release v1.3.0 (28 May 2024)
|
8
|
+
|
9
|
+
* (#1042) Align Java Executor Service behavior for `shuttingdown?`, `shutdown?`
|
10
|
+
* (#1038) Add `Concurrent.usable_processor_count` that is cgroups aware.
|
11
|
+
|
3
12
|
## Release v1.2.3 (16 Jan 2024)
|
4
13
|
|
5
14
|
* See [the GitHub release](https://github.com/ruby-concurrency/concurrent-ruby/releases/tag/v1.2.3) for details.
|
Binary file
|
@@ -57,15 +57,11 @@ if Concurrent.on_jruby?
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def ns_shuttingdown?
|
60
|
-
|
61
|
-
@executor.isTerminating
|
62
|
-
else
|
63
|
-
false
|
64
|
-
end
|
60
|
+
@executor.isShutdown && !@executor.isTerminated
|
65
61
|
end
|
66
62
|
|
67
63
|
def ns_shutdown?
|
68
|
-
@executor.
|
64
|
+
@executor.isTerminated
|
69
65
|
end
|
70
66
|
|
71
67
|
class Job
|
@@ -11,6 +11,7 @@ module Concurrent
|
|
11
11
|
def initialize
|
12
12
|
@processor_count = Delay.new { compute_processor_count }
|
13
13
|
@physical_processor_count = Delay.new { compute_physical_processor_count }
|
14
|
+
@cpu_quota = Delay.new { compute_cpu_quota }
|
14
15
|
end
|
15
16
|
|
16
17
|
def processor_count
|
@@ -21,6 +22,25 @@ module Concurrent
|
|
21
22
|
@physical_processor_count.value
|
22
23
|
end
|
23
24
|
|
25
|
+
def available_processor_count
|
26
|
+
cpu_count = processor_count.to_f
|
27
|
+
quota = cpu_quota
|
28
|
+
|
29
|
+
return cpu_count if quota.nil?
|
30
|
+
|
31
|
+
# cgroup cpus quotas have no limits, so they can be set to higher than the
|
32
|
+
# real count of cores.
|
33
|
+
if quota > cpu_count
|
34
|
+
cpu_count
|
35
|
+
else
|
36
|
+
quota
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def cpu_quota
|
41
|
+
@cpu_quota.value
|
42
|
+
end
|
43
|
+
|
24
44
|
private
|
25
45
|
|
26
46
|
def compute_processor_count
|
@@ -60,6 +80,24 @@ module Concurrent
|
|
60
80
|
rescue
|
61
81
|
return 1
|
62
82
|
end
|
83
|
+
|
84
|
+
def compute_cpu_quota
|
85
|
+
if RbConfig::CONFIG["target_os"].include?("linux")
|
86
|
+
if File.exist?("/sys/fs/cgroup/cpu.max")
|
87
|
+
# cgroups v2: https://docs.kernel.org/admin-guide/cgroup-v2.html#cpu-interface-files
|
88
|
+
cpu_max = File.read("/sys/fs/cgroup/cpu.max")
|
89
|
+
return nil if cpu_max.start_with?("max ") # no limit
|
90
|
+
max, period = cpu_max.split.map(&:to_f)
|
91
|
+
max / period
|
92
|
+
elsif File.exist?("/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us")
|
93
|
+
# cgroups v1: https://kernel.googlesource.com/pub/scm/linux/kernel/git/glommer/memcg/+/cpu_stat/Documentation/cgroups/cpu.txt
|
94
|
+
max = File.read("/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us").to_i
|
95
|
+
return nil if max == 0
|
96
|
+
period = File.read("/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_period_us").to_f
|
97
|
+
max / period
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
63
101
|
end
|
64
102
|
end
|
65
103
|
|
@@ -107,4 +145,31 @@ module Concurrent
|
|
107
145
|
def self.physical_processor_count
|
108
146
|
processor_counter.physical_processor_count
|
109
147
|
end
|
148
|
+
|
149
|
+
# Number of processors cores available for process scheduling.
|
150
|
+
# Returns `nil` if there is no #cpu_quota, or a `Float` if the
|
151
|
+
# process is inside a cgroup with a dedicated CPU quota (typically Docker).
|
152
|
+
#
|
153
|
+
# For performance reasons the calculated value will be memoized on the first
|
154
|
+
# call.
|
155
|
+
#
|
156
|
+
# @return [nil, Float] number of available processors
|
157
|
+
def self.available_processor_count
|
158
|
+
processor_counter.available_processor_count
|
159
|
+
end
|
160
|
+
|
161
|
+
# The maximum number of processors cores available for process scheduling.
|
162
|
+
# Returns `nil` if there is no enforced limit, or a `Float` if the
|
163
|
+
# process is inside a cgroup with a dedicated CPU quota (typically Docker).
|
164
|
+
#
|
165
|
+
# Note that nothing prevents setting a CPU quota higher than the actual number of
|
166
|
+
# cores on the system.
|
167
|
+
#
|
168
|
+
# For performance reasons the calculated value will be memoized on the first
|
169
|
+
# call.
|
170
|
+
#
|
171
|
+
# @return [nil, Float] Maximum number of available processors as set by a cgroup CPU quota, or nil if none set
|
172
|
+
def self.cpu_quota
|
173
|
+
processor_counter.cpu_quota
|
174
|
+
end
|
110
175
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: concurrent-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerry D'Antonio
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-
|
13
|
+
date: 2024-05-29 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: |
|
16
16
|
Modern concurrency tools including agents, futures, promises, thread pools, actors, supervisors, and more.
|