garbageman 0.1.19 → 0.1.20

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 CHANGED
@@ -1 +1 @@
1
- 0.1.19
1
+ 0.1.20
data/garbageman.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "garbageman"
8
- s.version = "0.1.19"
8
+ s.version = "0.1.20"
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"]
12
- s.date = "2013-06-25"
12
+ s.date = "2013-09-24"
13
13
  s.description = "Disable GC while processing requests. By using nginx upstream health checks to garbage collect when no one is there."
14
14
  s.email = "doug@sessionm.com"
15
15
  s.extra_rdoc_files = [
@@ -1,4 +1,5 @@
1
1
  require 'singleton'
2
+ require 'fileutils'
2
3
 
3
4
  module GarbageMan
4
5
  class Collector
@@ -13,6 +14,16 @@ module GarbageMan
13
14
 
14
15
  include Status
15
16
 
17
+ module Messages
18
+ CAN_NOT_DISABLE_GC = "can not disable gc"
19
+ QUEUING_REQUESTS = "queuing request, enabling gc"
20
+ WAITED_TOO_LONG = "waited too long to gc"
21
+ DISABLE_GC = "disabling gc"
22
+ CANT_TURN_OFF = "enabling gc, can not turn off"
23
+ end
24
+
25
+ include Messages
26
+
16
27
  attr_accessor :request_count, :will_collect, :will_select_next_server, :show_gc_times
17
28
  attr_reader :fiber_poll, :last_gc_finished_at
18
29
 
@@ -28,7 +39,7 @@ module GarbageMan
28
39
 
29
40
  def healthy?
30
41
  unless can_disable?
31
- debug "can not disable gc"
42
+ debug CAN_NOT_DISABLE_GC
32
43
  GC.enable
33
44
  return true
34
45
  end
@@ -54,15 +65,11 @@ module GarbageMan
54
65
  def collect
55
66
  # if we are starting to queue requests turn on gc, we could be in trouble
56
67
  if queuing?
57
- debug "queuing request, enabling gc"
68
+ debug QUEUING_REQUESTS
58
69
  GC.enable
59
- return
60
- end
61
-
62
- if waited_too_long_to_gc?
63
- debug "waited too long to gc"
70
+ elsif waited_too_long_to_gc?
71
+ debug WAITED_TOO_LONG
64
72
  GC.enable
65
- return
66
73
  end
67
74
 
68
75
  return unless can_collect?
@@ -80,10 +87,10 @@ module GarbageMan
80
87
  reset
81
88
 
82
89
  if can_disable?
83
- debug "disabling gc"
90
+ debug DISABLE_GC
84
91
  GC.disable
85
92
  else
86
- debug "enabling gc, can not turn off"
93
+ debug CANT_TURN_OFF
87
94
  GC.enable
88
95
  end
89
96
  end
@@ -130,9 +137,12 @@ module GarbageMan
130
137
  Config.thin_config['servers']
131
138
  end
132
139
 
140
+ WRITE_MOVE_OPTIONS = {:force => true}
133
141
  def write_gc_yaml(index, status)
134
142
  config = {'gc' => {'server' => index, 'status' => status}}
135
- File.open(Config.gc_yaml_file, 'w+') { |f| f.write config.to_yaml }
143
+ File.open(Config.gc_yaml_tmp_file, 'w+') { |f| f.write config.to_yaml }
144
+ # atomic write
145
+ FileUtils.mv Config.gc_yaml_tmp_file, Config.gc_yaml_file, WRITE_MOVE_OPTIONS
136
146
  end
137
147
 
138
148
  def reset
@@ -211,7 +221,6 @@ module GarbageMan
211
221
 
212
222
  def waited_too_long_to_gc?
213
223
  return false unless @last_gc_finished_at
214
- return false if @will_collect
215
224
  (Time.now - @last_gc_finished_at) >= Config.max_time_without_gc
216
225
  end
217
226
  end
@@ -7,6 +7,10 @@ module GarbageMan
7
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
+ @@gc_yaml_tmp_file = nil
11
+ def self.gc_yaml_tmp_file; @@gc_yaml_tmp_file ||= "./data/.tmp.gc.yml"; end
12
+ def self.gc_yaml_tmp_file=(file); @@gc_yaml_tmp_file = file; end
13
+
10
14
  def self.gc_config
11
15
  begin
12
16
  File.exists?(self.gc_yaml_file) ? YAML.load_file(self.gc_yaml_file) : nil
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.19
4
+ version: 0.1.20
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-25 00:00:00.000000000 Z
12
+ date: 2013-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: 2888262783155275332
105
+ hash: -76733894484378456
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements: