garbageman 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/garbageman.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "garbageman"
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Doug Youch"]
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/garbageman.rb",
30
30
  "lib/garbageman/collector.rb",
31
31
  "lib/garbageman/config.rb",
32
+ "lib/garbageman/ext/fiber_pool.rb",
32
33
  "lib/garbageman/ext/thin.rb",
33
34
  "lib/garbageman/rack/middleware.rb",
34
35
  "test/helper.rb",
@@ -31,6 +31,13 @@ module GarbageMan
31
31
  end
32
32
 
33
33
  def collect
34
+ # if we are starting to queue requests turn on gc, we could be in trouble
35
+ if queuing?
36
+ debug "queuing request, enabling gc"
37
+ GC.enable
38
+ return
39
+ end
40
+
34
41
  return unless can_collect?
35
42
 
36
43
  write_gc_yaml server_index, 'starting'
@@ -105,6 +112,14 @@ module GarbageMan
105
112
  fiber_poll && fiber_poll.busy_fibers.size > 0
106
113
  end
107
114
 
115
+ def queuing?
116
+ fiber_poll && fiber_poll.queue.size > 0
117
+ end
118
+
119
+ def not_queuing?
120
+ ! queuing?
121
+ end
122
+
108
123
  # no traffic and we've been selected by health check
109
124
  def can_collect?
110
125
  @will_collect && ! busy? && Thin::Backends::Base.num_connections == 0
@@ -121,21 +136,21 @@ module GarbageMan
121
136
  end
122
137
 
123
138
  def can_disable?
124
- Config.thin_config.has_key?('socket') && not_alone?
139
+ Config.thin_config.has_key?('socket') && not_queuing? && min_running_servers?
125
140
  end
126
141
 
127
- # make sure I'm not the only server running
128
- def not_alone?
142
+ def num_running_servers
143
+ count = 0
129
144
  Config.thin_config['servers'].times do |i|
130
145
  next if i == server_index
131
- file = socket_file i
132
- if File.exists?(file)
133
- return true
134
- end
146
+ count += 1 if File.exists?(socket_file(i))
135
147
  end
148
+ count
149
+ end
136
150
 
137
- debug "no other servers found"
138
- false
151
+ # make sure there are 3 or more servers running before disabling gc
152
+ def min_running_servers?
153
+ num_servers >= Config.min_servers_to_disable_gc && num_running_servers >= Config.min_servers_to_disable_gc
139
154
  end
140
155
 
141
156
  def socket_file(index)
@@ -19,5 +19,6 @@ module GarbageMan
19
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
+ def self.min_servers_to_disable_gc; 3; end
22
23
  end
23
24
  end
@@ -0,0 +1,3 @@
1
+ class FiberPool
2
+ attr_reader :queue
3
+ end
@@ -13,7 +13,8 @@ module GarbageMan
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
- GarbageMan::Collector.instance.logger.error("still receiving traffic even though I'm waiting to GC") if GarbageMan::Collector.instance.will_collect
16
+ # this is not 100% preventable with nginx, nginx will still send requests while waiting for the health check response
17
+ GarbageMan::Collector.instance.logger.debug("still receiving traffic even though I'm waiting to GC") if GarbageMan::Collector.instance.will_collect
17
18
  @app.call(env)
18
19
  end
19
20
  end
data/lib/garbageman.rb CHANGED
@@ -23,5 +23,6 @@ end
23
23
 
24
24
  require 'garbageman/config'
25
25
  require 'garbageman/ext/thin'
26
+ require 'garbageman/ext/fiber_pool'
26
27
  require 'garbageman/rack/middleware'
27
28
  require 'garbageman/collector'
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.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -80,6 +80,7 @@ files:
80
80
  - lib/garbageman.rb
81
81
  - lib/garbageman/collector.rb
82
82
  - lib/garbageman/config.rb
83
+ - lib/garbageman/ext/fiber_pool.rb
83
84
  - lib/garbageman/ext/thin.rb
84
85
  - lib/garbageman/rack/middleware.rb
85
86
  - test/helper.rb
@@ -99,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
100
  version: '0'
100
101
  segments:
101
102
  - 0
102
- hash: -932921230500805269
103
+ hash: -3173816017839592880
103
104
  required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  none: false
105
106
  requirements: