blue_green_process 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +3 -3
- data/README.md +97 -13
- data/lib/blue_green_process/config.rb +18 -2
- data/lib/blue_green_process/master_process.rb +55 -20
- data/lib/blue_green_process/performance.rb +11 -0
- data/lib/blue_green_process/shared_variable.rb +59 -0
- data/lib/blue_green_process/version.rb +1 -1
- data/lib/blue_green_process/worker_process.rb +20 -7
- data/lib/blue_green_process.rb +26 -13
- metadata +10 -7
- data/blue_green_process.gemspec +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89de1bb6ab2d7f30cf4063f1f04411da882e1061550603ee8ca866839a62f9d0
|
4
|
+
data.tar.gz: dc64126db9c11c6e03dfa80be32aed24e0a7142f463efd04915729f335233c68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00874bdfeba757a3e8cc5bba6cebdf8a8bfa63d2ab8ff4779f26a9ce5bd8a5afd9ac933e4833b8a0042ce55cefda62d69f70077396d8f6df9bb64961d2e12f70'
|
7
|
+
data.tar.gz: c5de3504ad7ec738260fcf4969ea9cb1cba38539f582ad122c159f543e05666ac1cc3dc7d8f1111134a5d8ad8ae4392006db8d7c4893f4d1214ae9bcea98361f
|
data/.rubocop.yml
CHANGED
@@ -25,3 +25,18 @@ Metrics/AbcSize:
|
|
25
25
|
|
26
26
|
Metrics/MethodLength:
|
27
27
|
Enabled: false
|
28
|
+
|
29
|
+
Metrics/CyclomaticComplexity:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Security/Eval:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Lint/MissingSuper:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Metrics/ClassLength:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Lint/AmbiguousBlockAssociation:
|
42
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
## [0.1.3] - 2022-9-5
|
2
|
+
* 単一プロセスでの実行を延長するとGC.startを実行しなくなりました
|
3
|
+
* 長時間にわたって延長する時は呼び出し側でGC.startを実行してください
|
4
|
+
|
5
|
+
## [0.1.2] - 2022-9-5
|
6
|
+
- プロセス間での値の共有で値の共有ができるようになりました
|
7
|
+
- 単一プロセスでの実行を延長できるようになりました
|
8
|
+
- プロセスをforkした時に実行するコールバックをblockで設定できるようになりました
|
9
|
+
- プロセスの切り替え時にかかった時間を取得できるようになりました
|
10
|
+
- BlueGreenProcess.performance.process_switching_time_before_work
|
11
|
+
|
12
|
+
## [0.1] - 2022-06-17
|
13
|
+
|
14
|
+
- Initial release
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
blue_green_process (0.1.
|
4
|
+
blue_green_process (0.1.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -57,8 +57,8 @@ PLATFORMS
|
|
57
57
|
DEPENDENCIES
|
58
58
|
blue_green_process!
|
59
59
|
pry
|
60
|
-
rake
|
61
|
-
rspec
|
60
|
+
rake
|
61
|
+
rspec
|
62
62
|
rubocop (~> 1.21)
|
63
63
|
|
64
64
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
BlueGreenProcess.configure do |config|
|
19
|
-
config.after_fork = ->{ puts 'forked!'
|
19
|
+
config.after_fork = ->{ puts 'forked!' }
|
20
20
|
end
|
21
21
|
|
22
22
|
process = BlueGreenProcess.new(
|
@@ -31,14 +31,98 @@ end
|
|
31
31
|
sleep(1)
|
32
32
|
|
33
33
|
process.shutdown
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
Process.waitall
|
35
|
+
```
|
36
|
+
|
37
|
+
### プロセス間での値の共有
|
38
|
+
* Hashが入っている'BlueGreenProcess::SharedVariable.data' の値はmaster process, work processで共有します.
|
39
|
+
* 共有するHashのキーは `config.shared_variables` で許可する必要があります
|
40
|
+
* プロセスを入れ替えるタイミングで値の復元とダンプを行います
|
41
|
+
* JSONでシリアライズしているので共有できるオブジェクトはプリミティブ型に限定されます
|
42
|
+
* GCの時間を軽減するために整数型だけを共有するとパフォーマンスに良さそう
|
43
|
+
* `config.shared_variables` に最初から入っている `extend_run_on_this_process` は消すことができません
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
BlueGreenProcess.configure do |config|
|
47
|
+
config.shared_variables = [:count]
|
48
|
+
end
|
49
|
+
|
50
|
+
worker_class = Class.new(BlueGreenProcess::BaseWorker) do
|
51
|
+
def initialize(*); end
|
52
|
+
|
53
|
+
def work(label)
|
54
|
+
BlueGreenProcess::SharedVariable.data['count'] += 1
|
55
|
+
puts "#{label}'s data['count'] is #{BlueGreenProcess::SharedVariable.data['count']}"
|
40
56
|
end
|
41
57
|
end
|
58
|
+
|
59
|
+
BlueGreenProcess::SharedVariable.data['count'] = 0
|
60
|
+
process = BlueGreenProcess.new(worker_instance: worker_class.new, max_work: 3)
|
61
|
+
process.work # blue
|
62
|
+
process.work # green
|
63
|
+
process.work # blue
|
64
|
+
BlueGreenProcess::SharedVariable.data['count']
|
65
|
+
```
|
66
|
+
|
67
|
+
outputs
|
68
|
+
|
69
|
+
```
|
70
|
+
blue's data['count'] is 1
|
71
|
+
blue's data['count'] is 2
|
72
|
+
blue's data['count'] is 3
|
73
|
+
green's data['count'] is 4
|
74
|
+
green's data['count'] is 5
|
75
|
+
green's data['count'] is 6
|
76
|
+
blue's data['count'] is 7
|
77
|
+
blue's data['count'] is 8
|
78
|
+
blue's data['count'] is 9
|
79
|
+
9
|
80
|
+
```
|
81
|
+
|
82
|
+
### 単一プロセスでの実行を延長する
|
83
|
+
* workerクラスの中で、`BlueGreenProcess::SharedVariable.extend_run_on_this_process`にtrueをセットするともう一度同じプロセスで処理を行います
|
84
|
+
* 次の実行でtrueを明示しない限りはプロセスを切り替えます
|
85
|
+
* 単一プロセスでの実行を延長するとGC.startを実行しなくなります
|
86
|
+
* 長時間にわたって延長する時は呼び出し側でGC.startを実行してください
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
BlueGreenProcess.configure do |config|
|
90
|
+
config.shared_variables = [:count]
|
91
|
+
end
|
92
|
+
|
93
|
+
worker_class = Class.new(BlueGreenProcess::BaseWorker) do
|
94
|
+
def initialize(*); end
|
95
|
+
|
96
|
+
def work(label)
|
97
|
+
BlueGreenProcess::SharedVariable.data['count'] += 1
|
98
|
+
BlueGreenProcess::SharedVariable.extend_run_on_this_process = true
|
99
|
+
puts "#{label}'s data['count'] is #{BlueGreenProcess::SharedVariable.data['count']}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
BlueGreenProcess::SharedVariable.data['count'] = 0
|
104
|
+
process = BlueGreenProcess.new(worker_instance: worker_class.new, max_work: 3)
|
105
|
+
process.work # blue
|
106
|
+
process.work # blue
|
107
|
+
process.work # blue
|
108
|
+
process.work # blue
|
109
|
+
```
|
110
|
+
|
111
|
+
### Metrics
|
112
|
+
パフォーマンスの解析に使えます
|
113
|
+
|
114
|
+
##### BlueGreenProcess.performance.process_switching_time_before_work
|
115
|
+
* プロセスを最後に入れ替えた時にかかった時間を返す
|
116
|
+
|
117
|
+
### Callbacks
|
118
|
+
#### after_fork
|
119
|
+
|
120
|
+
プロセスをforkした時に実行する
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
BlueGreenProcess.configure do |config|
|
124
|
+
config.after_fork = ->{ puts 'forked!' }
|
125
|
+
end
|
42
126
|
```
|
43
127
|
|
44
128
|
## Development
|
@@ -56,14 +140,14 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
56
140
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
57
141
|
|
58
142
|
## NOTE
|
59
|
-
*
|
60
|
-
*
|
143
|
+
* 処理は直列で行う
|
144
|
+
* processが行う処理内容は引数を含めて固定
|
145
|
+
* A processがinactiveになった時に行うGC.startに時間がかかると、次にA processがbe_activeになったらレスポンスが遅れる. 構造上の仕様.
|
146
|
+
* これが起きる場合はオブジェクトの生成を減らすとか、blue, greenではなくプロセスのプールを作ってプロセスがGCに時間を費やせるようにする
|
147
|
+
* workerプロセスでエラーが起きたらmasterプロセスにそのエラーが伝わり、workerプロセスは終了します
|
61
148
|
|
62
149
|
## TODO
|
150
|
+
* shutdownしないでプロセスを停止したときにSIGINTを受け取りたい
|
63
151
|
* runしている間にsignalをもらったらすぐにdieを送りたい
|
64
|
-
* プロセスを入れ替えるときに変数を受け渡しをする
|
65
|
-
* queueしてからのdequeueするまでの時間を測定したい
|
66
|
-
* webサーバでよくあるqueued timeみたいな扱い
|
67
|
-
* これが伸びると致命的なのでチューニングできるようにしたいため
|
68
152
|
* inactiveからactiveへの切り替えになる時間を測定したい
|
69
153
|
* GCが長引いてactiveプロセスが処理開始に時間がかかるので
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "logger"
|
4
|
+
|
3
5
|
module BlueGreenProcess
|
4
6
|
class Config
|
7
|
+
attr_writer :logger
|
8
|
+
|
5
9
|
def after_fork=(block)
|
6
10
|
@after_fork_block = block
|
7
11
|
end
|
@@ -10,8 +14,20 @@ module BlueGreenProcess
|
|
10
14
|
@after_fork_block || -> {}
|
11
15
|
end
|
12
16
|
|
13
|
-
def
|
14
|
-
@
|
17
|
+
def logger
|
18
|
+
@logger ||= Logger.new("/dev/null")
|
19
|
+
end
|
20
|
+
|
21
|
+
def shared_variables
|
22
|
+
@shared_variables ||= []
|
23
|
+
@shared_variables.push(:extend_run_on_this_process)
|
24
|
+
@shared_variables.uniq
|
25
|
+
end
|
26
|
+
|
27
|
+
def shared_variables=(value)
|
28
|
+
@shared_variables = value.map(&:to_s)
|
29
|
+
@shared_variables.push("extend_run_on_this_process")
|
30
|
+
@shared_variables.uniq
|
15
31
|
end
|
16
32
|
end
|
17
33
|
end
|
@@ -1,6 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module BlueGreenProcess
|
4
|
+
class ErrorWrapper < StandardError
|
5
|
+
attr_accessor :error_class, :message
|
6
|
+
|
7
|
+
def initialize(error_class, error_message)
|
8
|
+
self.error_class = error_class
|
9
|
+
self.message = error_message
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
class MasterProcess
|
5
14
|
def initialize(worker_instance:, max_work:)
|
6
15
|
blue = fork_process(label: :blue, worker_instance: worker_instance)
|
@@ -15,12 +24,17 @@ module BlueGreenProcess
|
|
15
24
|
@max_work = max_work
|
16
25
|
end
|
17
26
|
|
27
|
+
def pids
|
28
|
+
@processes.map(&:pid)
|
29
|
+
end
|
30
|
+
|
18
31
|
def fork_process(label:, worker_instance:)
|
19
32
|
child_read, parent_write = IO.pipe
|
20
33
|
parent_read, child_write = IO.pipe
|
21
34
|
|
22
35
|
pid = fork do
|
23
36
|
BlueGreenProcess.config.after_fork.call
|
37
|
+
::GC.disable
|
24
38
|
|
25
39
|
parent_write.close
|
26
40
|
parent_read.close
|
@@ -28,29 +42,35 @@ module BlueGreenProcess
|
|
28
42
|
|
29
43
|
loop do
|
30
44
|
data = child_read.gets&.strip
|
31
|
-
|
45
|
+
json = JSON.parse(data)
|
46
|
+
command = json["c"]
|
47
|
+
case command
|
32
48
|
when BlueGreenProcess::PROCESS_COMMAND_DIE, nil, ""
|
33
|
-
BlueGreenProcess.
|
49
|
+
BlueGreenProcess.logger.debug "[BLUE_GREEN_PROCESS] #{label} will die(#{$PROCESS_ID})"
|
34
50
|
exit 0
|
35
51
|
when BlueGreenProcess::PROCESS_COMMAND_BE_ACTIVE
|
36
52
|
process_status = BlueGreenProcess::PROCESS_STATUS_ACTIVE
|
37
|
-
BlueGreenProcess.
|
38
|
-
|
39
|
-
::
|
53
|
+
BlueGreenProcess::SharedVariable.instance.restore(json["data"])
|
54
|
+
BlueGreenProcess.logger.debug "[BLUE_GREEN_PROCESS] #{label} has become active(#{$PROCESS_ID})"
|
55
|
+
child_write.puts({ c: BlueGreenProcess::RESPONSE_OK }.to_json)
|
40
56
|
when BlueGreenProcess::PROCESS_COMMAND_BE_INACTIVE
|
41
57
|
process_status = BlueGreenProcess::PROCESS_STATUS_INACTIVE
|
42
|
-
BlueGreenProcess.
|
43
|
-
child_write.puts BlueGreenProcess::
|
44
|
-
|
45
|
-
::GC.start
|
58
|
+
BlueGreenProcess.logger.debug "[BLUE_GREEN_PROCESS] #{label} has become inactive(#{$PROCESS_ID})"
|
59
|
+
child_write.puts({ c: BlueGreenProcess::RESPONSE_OK,
|
60
|
+
data: BlueGreenProcess::SharedVariable.data }.to_json)
|
61
|
+
::GC.start unless BlueGreenProcess::SharedVariable.extend_run_on_this_process
|
46
62
|
when BlueGreenProcess::PROCESS_COMMAND_WORK
|
47
63
|
if process_status == BlueGreenProcess::PROCESS_STATUS_INACTIVE
|
48
64
|
warn "Should not be able to run in this status"
|
49
65
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
66
|
+
|
67
|
+
begin
|
68
|
+
worker_instance.work(*label)
|
69
|
+
child_write.puts({ c: BlueGreenProcess::RESPONSE_OK }.to_json)
|
70
|
+
rescue StandardError => e
|
71
|
+
child_write.puts({ c: BlueGreenProcess::RESPONSE_ERROR, err_class: e.class.name,
|
72
|
+
err_message: e.message }.to_json)
|
73
|
+
end
|
54
74
|
else
|
55
75
|
child_write.puts "NG"
|
56
76
|
puts "unknown. from #{label}(#{$PROCESS_ID})"
|
@@ -73,23 +93,38 @@ module BlueGreenProcess
|
|
73
93
|
process.work
|
74
94
|
end
|
75
95
|
end
|
76
|
-
|
77
|
-
|
96
|
+
rescue BlueGreenProcess::ErrorWrapper => e
|
97
|
+
shutdown
|
98
|
+
BlueGreenProcess.logger.error "[BLUE_GREEN_PROCESS] #{e.error_class}: #{e.message}"
|
99
|
+
raise eval(e.error_class), e.message
|
78
100
|
end
|
79
101
|
|
80
102
|
def shutdown
|
81
|
-
@processes.each
|
82
|
-
|
83
|
-
end
|
103
|
+
@processes.each(&:shutdown)
|
104
|
+
Process.waitall
|
84
105
|
end
|
85
106
|
|
86
107
|
private
|
87
108
|
|
88
109
|
def active_process
|
89
|
-
active_process =
|
110
|
+
active_process = nil
|
90
111
|
@stage[!@stage_state].be_inactive
|
112
|
+
process_switching_time = Benchmark.realtime do
|
113
|
+
active_process = @stage[@stage_state].be_active
|
114
|
+
end
|
115
|
+
BlueGreenProcess.performance.process_switching_time_before_work = process_switching_time
|
116
|
+
|
91
117
|
yield(active_process)
|
92
|
-
|
118
|
+
|
119
|
+
active_process.be_inactive
|
120
|
+
if BlueGreenProcess::SharedVariable.extend_run_on_this_process
|
121
|
+
BlueGreenProcess::SharedVariable.extend_run_on_this_process = false
|
122
|
+
active_process.be_active
|
123
|
+
else
|
124
|
+
@stage_state = !@stage_state
|
125
|
+
end
|
126
|
+
|
127
|
+
true
|
93
128
|
end
|
94
129
|
end
|
95
130
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "singleton"
|
4
|
+
|
5
|
+
module BlueGreenProcess
|
6
|
+
class SharedVariable
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_writer :data
|
10
|
+
|
11
|
+
def self.data
|
12
|
+
instance.data
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.data=(value)
|
16
|
+
instance.data = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.extend_run_on_this_process
|
20
|
+
instance.extend_run_on_this_process
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.extend_run_on_this_process=(value)
|
24
|
+
instance.extend_run_on_this_process = (value)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Hash]
|
28
|
+
def data
|
29
|
+
@data ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Boolean]
|
33
|
+
def extend_run_on_this_process
|
34
|
+
@data["extend_run_on_this_process"] ||= false
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Boolean]
|
38
|
+
def extend_run_on_this_process=(value)
|
39
|
+
@data["extend_run_on_this_process"] = value
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Hash]
|
43
|
+
def restore(json)
|
44
|
+
return if json.nil?
|
45
|
+
|
46
|
+
self.data = json.slice(*BlueGreenProcess.config.shared_variables)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [Hash]
|
50
|
+
def dump
|
51
|
+
data.slice(*BlueGreenProcess.config.shared_variables)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [NilClass]
|
55
|
+
def reset
|
56
|
+
@data = nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -15,7 +15,8 @@ module BlueGreenProcess
|
|
15
15
|
def be_active
|
16
16
|
return self if status == BlueGreenProcess::PROCESS_STATUS_ACTIVE
|
17
17
|
|
18
|
-
write_and_await_until_read(BlueGreenProcess::PROCESS_COMMAND_BE_ACTIVE
|
18
|
+
write_and_await_until_read(BlueGreenProcess::PROCESS_COMMAND_BE_ACTIVE,
|
19
|
+
{ data: BlueGreenProcess::SharedVariable.data })
|
19
20
|
self.status = BlueGreenProcess::PROCESS_STATUS_ACTIVE
|
20
21
|
self
|
21
22
|
end
|
@@ -34,24 +35,36 @@ module BlueGreenProcess
|
|
34
35
|
write_and_await_until_read(BlueGreenProcess::PROCESS_COMMAND_WORK)
|
35
36
|
end
|
36
37
|
|
38
|
+
def shutdown
|
39
|
+
write(BlueGreenProcess::PROCESS_COMMAND_DIE)
|
40
|
+
end
|
41
|
+
|
37
42
|
private
|
38
43
|
|
39
|
-
def write_and_await_until_read(command)
|
40
|
-
write(command)
|
44
|
+
def write_and_await_until_read(command, args = {})
|
45
|
+
write(command, args)
|
41
46
|
wait_response
|
42
47
|
end
|
43
48
|
|
44
49
|
def wait_response
|
45
|
-
response = read
|
46
|
-
|
50
|
+
response = JSON.parse(read)
|
51
|
+
BlueGreenProcess::SharedVariable.instance.restore(response["data"])
|
52
|
+
case response["c"]
|
53
|
+
when BlueGreenProcess::RESPONSE_OK
|
54
|
+
[BlueGreenProcess::SharedVariable.data, response]
|
55
|
+
when BlueGreenProcess::RESPONSE_ERROR
|
56
|
+
raise BlueGreenProcess::ErrorWrapper.new(response["err_class"], response["err_message"])
|
57
|
+
else
|
58
|
+
raise "invalid response."
|
59
|
+
end
|
47
60
|
end
|
48
61
|
|
49
62
|
def read
|
50
63
|
rpipe.gets.strip
|
51
64
|
end
|
52
65
|
|
53
|
-
def write(token)
|
54
|
-
wpipe.puts token
|
66
|
+
def write(token, args = {})
|
67
|
+
wpipe.puts({ c: token }.merge!(args).to_json)
|
55
68
|
end
|
56
69
|
|
57
70
|
def enforce_to_be_active
|
data/lib/blue_green_process.rb
CHANGED
@@ -2,10 +2,15 @@
|
|
2
2
|
|
3
3
|
require "English"
|
4
4
|
require_relative "blue_green_process/version"
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
require_relative "blue_green_process/master_process"
|
6
|
+
require_relative "blue_green_process/worker_process"
|
7
|
+
require_relative "blue_green_process/base_worker"
|
8
|
+
require_relative "blue_green_process/config"
|
9
|
+
require_relative "blue_green_process/performance"
|
10
|
+
require_relative "blue_green_process/shared_variable"
|
11
|
+
require "benchmark"
|
12
|
+
require "json"
|
13
|
+
require "singleton"
|
9
14
|
|
10
15
|
module BlueGreenProcess
|
11
16
|
PROCESS_STATUS_ACTIVE = :active
|
@@ -13,21 +18,16 @@ module BlueGreenProcess
|
|
13
18
|
|
14
19
|
PROCESS_COMMAND_DIE = "die"
|
15
20
|
PROCESS_COMMAND_BE_ACTIVE = "be_active"
|
16
|
-
PROCESS_COMMAND_BE_INACTIVE = "
|
17
|
-
PROCESS_COMMAND_WORK = "
|
21
|
+
PROCESS_COMMAND_BE_INACTIVE = "be_inactive"
|
22
|
+
PROCESS_COMMAND_WORK = "work"
|
18
23
|
|
19
|
-
|
24
|
+
RESPONSE_OK = "OK"
|
25
|
+
RESPONSE_ERROR = "ERR"
|
20
26
|
|
21
27
|
def self.new(worker_instance:, max_work:)
|
22
28
|
BlueGreenProcess::MasterProcess.new(worker_instance: worker_instance, max_work: max_work)
|
23
29
|
end
|
24
30
|
|
25
|
-
def self.debug_log(message)
|
26
|
-
return unless ENV["VERBOSE"]
|
27
|
-
|
28
|
-
puts message
|
29
|
-
end
|
30
|
-
|
31
31
|
def self.configure
|
32
32
|
@config = Config.new
|
33
33
|
yield(@config)
|
@@ -37,4 +37,17 @@ module BlueGreenProcess
|
|
37
37
|
def self.config
|
38
38
|
@config ||= Config.new
|
39
39
|
end
|
40
|
+
|
41
|
+
def self.logger
|
42
|
+
config.logger
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.performance
|
46
|
+
@performance ||= Performance.new
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.reset
|
50
|
+
@config = Config.new
|
51
|
+
@performance = Performance.new
|
52
|
+
end
|
40
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blue_green_process
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jiikko
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library that solves GC bottlenecks with multi-process.
|
14
14
|
email:
|
@@ -19,16 +19,19 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- ".rspec"
|
21
21
|
- ".rubocop.yml"
|
22
|
+
- ".ruby-version"
|
23
|
+
- CHANGELOG.md
|
22
24
|
- Gemfile
|
23
25
|
- Gemfile.lock
|
24
26
|
- LICENSE.txt
|
25
27
|
- README.md
|
26
28
|
- Rakefile
|
27
|
-
- blue_green_process.gemspec
|
28
29
|
- lib/blue_green_process.rb
|
29
30
|
- lib/blue_green_process/base_worker.rb
|
30
31
|
- lib/blue_green_process/config.rb
|
31
32
|
- lib/blue_green_process/master_process.rb
|
33
|
+
- lib/blue_green_process/performance.rb
|
34
|
+
- lib/blue_green_process/shared_variable.rb
|
32
35
|
- lib/blue_green_process/version.rb
|
33
36
|
- lib/blue_green_process/worker_process.rb
|
34
37
|
- sig/blue_green_process.rbs
|
@@ -38,7 +41,7 @@ licenses:
|
|
38
41
|
metadata:
|
39
42
|
homepage_uri: https://github.com/splaplapla/blue_green_process
|
40
43
|
source_code_uri: https://github.com/splaplapla/blue_green_process
|
41
|
-
post_install_message:
|
44
|
+
post_install_message:
|
42
45
|
rdoc_options: []
|
43
46
|
require_paths:
|
44
47
|
- lib
|
@@ -53,8 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
56
|
- !ruby/object:Gem::Version
|
54
57
|
version: '0'
|
55
58
|
requirements: []
|
56
|
-
rubygems_version: 3.3.
|
57
|
-
signing_key:
|
59
|
+
rubygems_version: 3.0.3.1
|
60
|
+
signing_key:
|
58
61
|
specification_version: 4
|
59
62
|
summary: A library that solves GC bottlenecks with multi-process.
|
60
63
|
test_files: []
|
data/blue_green_process.gemspec
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/blue_green_process/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "blue_green_process"
|
7
|
-
spec.version = BlueGreenProcess::VERSION
|
8
|
-
spec.authors = ["jiikko"]
|
9
|
-
spec.email = ["n905i.1214@gmail.com"]
|
10
|
-
|
11
|
-
spec.summary = "A library that solves GC bottlenecks with multi-process."
|
12
|
-
spec.description = spec.summary
|
13
|
-
spec.homepage = "https://github.com/splaplapla/blue_green_process"
|
14
|
-
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 2.5"
|
16
|
-
|
17
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
-
spec.metadata["source_code_uri"] = "https://github.com/splaplapla/blue_green_process"
|
19
|
-
|
20
|
-
# Specify which files should be added to the gem when it is released.
|
21
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
-
spec.files = Dir.chdir(__dir__) do
|
23
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
-
end
|
26
|
-
end
|
27
|
-
spec.bindir = "exe"
|
28
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
-
spec.require_paths = ["lib"]
|
30
|
-
|
31
|
-
# Uncomment to register a new dependency of your gem
|
32
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
33
|
-
|
34
|
-
# For more information and examples about making a new gem, check out our
|
35
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
-
end
|