griffin-interceptors 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eaf4ab1433928865a32bd22d19c1283f826ea526
|
4
|
+
data.tar.gz: 43d9b6c7f9a636fa79ae6e4adf8800c0c5326952
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57917963336f2b3ba83d84da9c3c59d2c2ac3b3352317375307facadd00b55edc8d415c72c3015bfc4d70295fc1bb06211d4f0c17b382666dc3bd323514f0e6f
|
7
|
+
data.tar.gz: 6f198f8b51e9a9afd723cc6d285307685e226941af9ed51f67a465a9e193c4853a1c21fbd3bf834db08f7bd8a1682cc96cae0e21cc74643728c8e6cf4fd5ae6e
|
@@ -20,7 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_dependency '
|
23
|
+
spec.add_dependency 'get_process_mem', '~> 0.2.3'
|
24
|
+
spec.add_dependency 'griffin', '>= 0.2.3'
|
24
25
|
|
25
26
|
spec.add_development_dependency 'bundler'
|
26
27
|
spec.add_development_dependency 'rake'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'get_process_mem'
|
4
|
+
|
5
|
+
module Griffin
|
6
|
+
module Interceptors
|
7
|
+
module Server
|
8
|
+
class WorkerKillerInterceptor < GRPC::ServerInterceptor
|
9
|
+
def initialize(memory_limit_min: 1024**3, memory_limit_max: 2 * (1024**3), check_cycle: 16)
|
10
|
+
@worker_memory_limit_max = memory_limit_max
|
11
|
+
@worker_memory_limit_min = memory_limit_min
|
12
|
+
@worker_check_cycle = check_cycle
|
13
|
+
@worker_memory_limit = @worker_memory_limit_min + rand(@worker_memory_limit_max - @worker_memory_limit_min + 1)
|
14
|
+
@worker_check_count = 0
|
15
|
+
@sent_signals = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def request_response(*)
|
19
|
+
yield.tap do
|
20
|
+
break if @sent_signals
|
21
|
+
|
22
|
+
@worker_process_start ||= Time.now
|
23
|
+
@worker_check_count += 1
|
24
|
+
|
25
|
+
if (@worker_check_count % @worker_check_cycle) == 0
|
26
|
+
rss = GetProcessMem.new.bytes
|
27
|
+
if rss > @worker_memory_limit
|
28
|
+
Griffin.logger.warn("Worker (pid: #{Process.pid}) exceeds memory limit (#{rss.to_i} bytes > #{@worker_memory_limit} bytes)")
|
29
|
+
send_restart_signal(@worker_process_start)
|
30
|
+
end
|
31
|
+
|
32
|
+
@worker_check_count = 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
alias_method :server_streamer, :request_response
|
38
|
+
alias_method :client_streamer, :request_response
|
39
|
+
alias_method :bidi_streamer, :request_response
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def send_restart_signal(start_time)
|
44
|
+
# No need to get a lock, sending signals duplicately is acceptable
|
45
|
+
@sent_signals = true
|
46
|
+
pid = Process.pid
|
47
|
+
alive_sec = (Time.now - start_time).round
|
48
|
+
|
49
|
+
Griffin.logger.info("Send signal(USR1) pid: #{pid}, alive_sec: #{alive_sec}")
|
50
|
+
Process.kill :USR1, pid
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: griffin-interceptors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuta Iwama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: get_process_mem
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.3
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: griffin
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
33
|
+
version: 0.2.3
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
40
|
+
version: 0.2.3
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,6 +126,7 @@ files:
|
|
112
126
|
- lib/griffin/interceptors/server/rails_exception_interceptor.rb
|
113
127
|
- lib/griffin/interceptors/server/raven_interceptor.rb
|
114
128
|
- lib/griffin/interceptors/server/timeout_interceptor.rb
|
129
|
+
- lib/griffin/interceptors/server/worker_killer_interceptor.rb
|
115
130
|
- lib/griffin/interceptors/server/x_request_id_interceptor.rb
|
116
131
|
- lib/griffin/interceptors/version.rb
|
117
132
|
homepage: https://github.com/cookpad/griffin-interceptors
|