garbageman 0.1.0 → 0.1.1
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.
- data/VERSION +1 -1
- data/garbageman.gemspec +61 -0
- data/lib/garbageman/collector.rb +12 -4
- data/lib/garbageman/config.rb +2 -2
- data/lib/garbageman/ext/thin.rb +7 -5
- data/lib/garbageman/rack/middleware.rb +2 -2
- data/lib/garbageman.rb +5 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/garbageman.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "garbageman"
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Doug Youch"]
|
12
|
+
s.date = "2013-06-10"
|
13
|
+
s.description = "Disable GC while processing requests. By using nginx upstream health checks to garbage collect when no one is there."
|
14
|
+
s.email = "doug@sessionm.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rvmrc",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"garbageman.gemspec",
|
29
|
+
"lib/garbageman.rb",
|
30
|
+
"lib/garbageman/collector.rb",
|
31
|
+
"lib/garbageman/config.rb",
|
32
|
+
"lib/garbageman/ext/thin.rb",
|
33
|
+
"lib/garbageman/rack/middleware.rb",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_garbageman.rb"
|
36
|
+
]
|
37
|
+
s.homepage = "http://github.com/dyouch5@yahoo.com/garbageman"
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = "1.8.23"
|
41
|
+
s.summary = "Process requests without garbage collection"
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
53
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/lib/garbageman/collector.rb
CHANGED
@@ -66,7 +66,7 @@ module GarbageMan
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def num_servers
|
69
|
-
|
69
|
+
Config.thin_config['servers']
|
70
70
|
end
|
71
71
|
|
72
72
|
def write_gc_yaml(index, status)
|
@@ -77,7 +77,7 @@ module GarbageMan
|
|
77
77
|
def select_next_server
|
78
78
|
Config.thin_config['servers'].times do |i|
|
79
79
|
next_server_index = (server_index + i + 1) % num_servers
|
80
|
-
file =
|
80
|
+
file = socket_file next_server_index
|
81
81
|
next unless File.exists?(file)
|
82
82
|
debug "selected #{next_server_index}"
|
83
83
|
write_gc_yaml next_server_index, 'selected'
|
@@ -91,9 +91,13 @@ module GarbageMan
|
|
91
91
|
@will_collect = false
|
92
92
|
end
|
93
93
|
|
94
|
+
def busy?
|
95
|
+
fiber_poll && fiber_poll.busy_fibers.size > 0
|
96
|
+
end
|
97
|
+
|
94
98
|
# no traffic and we've been selected by health check
|
95
99
|
def can_collect?
|
96
|
-
@will_collect &&
|
100
|
+
@will_collect && ! busy? && Thin::Backends::Base.num_connections == 0
|
97
101
|
end
|
98
102
|
|
99
103
|
# if the request count is high enough and it is our turn
|
@@ -114,7 +118,7 @@ module GarbageMan
|
|
114
118
|
def not_alone?
|
115
119
|
Config.thin_config['servers'].times do |i|
|
116
120
|
next if i == server_index
|
117
|
-
file =
|
121
|
+
file = socket_file i
|
118
122
|
if File.exists?(file)
|
119
123
|
return true
|
120
124
|
end
|
@@ -124,6 +128,10 @@ module GarbageMan
|
|
124
128
|
false
|
125
129
|
end
|
126
130
|
|
131
|
+
def socket_file(index)
|
132
|
+
Config.thin_config['socket'].sub '.sock', ".#{index}.sock"
|
133
|
+
end
|
134
|
+
|
127
135
|
def logger; GarbageMan.logger; end
|
128
136
|
|
129
137
|
def debug(msg)
|
data/lib/garbageman/config.rb
CHANGED
@@ -4,7 +4,7 @@ module GarbageMan
|
|
4
4
|
def self.gc_health_check_request_path; @@gc_health_check_request_path; end
|
5
5
|
|
6
6
|
@@gc_yaml_file = nil
|
7
|
-
def self.gc_yaml_file; @@gc_yaml_file ||= "
|
7
|
+
def self.gc_yaml_file; @@gc_yaml_file ||= "./data/gc.yml"; end
|
8
8
|
def self.gc_yaml_file=(file); @@gc_yaml_file = file; end
|
9
9
|
|
10
10
|
def self.gc_config
|
@@ -16,7 +16,7 @@ module GarbageMan
|
|
16
16
|
end
|
17
17
|
|
18
18
|
@@thin_config = nil
|
19
|
-
def self.thin_config; @@thin_config ||= YAML.load_file("
|
19
|
+
def self.thin_config; @@thin_config ||= YAML.load_file("./config/thin.yml"); end
|
20
20
|
|
21
21
|
def self.num_request_before_collecting; 10; end
|
22
22
|
end
|
data/lib/garbageman/ext/thin.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
module Thin
|
2
2
|
module Backends
|
3
3
|
class Base
|
4
|
-
cattr_reader :num_connections
|
5
4
|
@@num_connections = 0
|
6
|
-
|
5
|
+
def self.num_connections; @@num_connections; end
|
7
6
|
@@server_index = nil
|
7
|
+
def self.server_index; @@server_index; end
|
8
|
+
def self.server_index=(index); @@server_index = index; end
|
8
9
|
|
9
10
|
def connection_finished_with_count(connection)
|
10
11
|
connection_finished_without_count(connection).tap { @@num_connections -= 1 }
|
11
12
|
end
|
12
|
-
|
13
|
+
alias connection_finished_without_count connection_finished
|
14
|
+
alias connection_finished connection_finished_with_count
|
13
15
|
|
14
16
|
protected
|
15
17
|
|
16
18
|
def initialize_connection_with_count(connection)
|
17
19
|
initialize_connection_without_count(connection).tap { @@num_connections += 1 }
|
18
20
|
end
|
19
|
-
alias initialize_connection_without_count
|
20
|
-
alias
|
21
|
+
alias initialize_connection_without_count initialize_connection
|
22
|
+
alias initialize_connection initialize_connection_with_count
|
21
23
|
end
|
22
24
|
|
23
25
|
class TcpServer
|
@@ -8,12 +8,12 @@ module GarbageMan
|
|
8
8
|
@@ok_response = [200, {'Content-Length' => '0'}, '']
|
9
9
|
@@gc_response = [589, {'Content-Length' => '0'}, '']
|
10
10
|
def call(env)
|
11
|
-
|
11
|
+
GarbageMan::Collector.instance.request_count += 1
|
12
12
|
|
13
13
|
if env['REQUEST_PATH'] == GarbageMan::Config.gc_health_check_request_path
|
14
14
|
GarbageMan::Collector.instance.healthy? ? @@ok_response : @@gc_response
|
15
15
|
else
|
16
|
-
|
16
|
+
GarbageMan::Collector.instance.logger.error("still receiving traffic even though I'm waiting to GC") if GarbageMan::Collector.instance.will_collect
|
17
17
|
@app.call(env)
|
18
18
|
end
|
19
19
|
end
|
data/lib/garbageman.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garbageman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- README.rdoc
|
77
77
|
- Rakefile
|
78
78
|
- VERSION
|
79
|
+
- garbageman.gemspec
|
79
80
|
- lib/garbageman.rb
|
80
81
|
- lib/garbageman/collector.rb
|
81
82
|
- lib/garbageman/config.rb
|
@@ -98,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
99
|
version: '0'
|
99
100
|
segments:
|
100
101
|
- 0
|
101
|
-
hash: -
|
102
|
+
hash: -664374349812690077
|
102
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
104
|
none: false
|
104
105
|
requirements:
|