merb-core 1.0.8.1 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -359,7 +359,7 @@ end
359
359
  class Merb::BootLoader::Dependencies < Merb::BootLoader
360
360
 
361
361
  # ==== Returns
362
- # Array[Gem::Dependency]:: The dependencies regiestered in init.rb.
362
+ # Array[Gem::Dependency]:: The dependencies registered in init.rb.
363
363
  #
364
364
  # :api: plugin
365
365
  cattr_accessor :dependencies
@@ -515,9 +515,11 @@ class Merb::BootLoader::Dependencies < Merb::BootLoader
515
515
  #
516
516
  # :api: private
517
517
  def self.load_initfile
518
+ return nil if Merb.const_defined?("INIT_RB_LOADED")
518
519
  if File.exists?(initfile)
519
520
  STDOUT.puts "Loading init file from #{initfile}" unless Merb.testing?
520
521
  load(initfile)
522
+ Merb.const_set("INIT_RB_LOADED", true)
521
523
  elsif !Merb.testing?
522
524
  Merb.fatal! "You are not in a Merb application, or you are in " \
523
525
  "a flat application and have not specified the init file. If you " \
@@ -153,6 +153,8 @@ module Kernel
153
153
  end
154
154
 
155
155
  if block = dep.require_block
156
+ # reset the require block so it doesn't get called a second time
157
+ dep.require_block = nil
156
158
  block.call
157
159
  end
158
160
 
@@ -1,3 +1,46 @@
1
+ module Merb
2
+ module System
3
+ class PortablePoller
4
+ def initialize(pid)
5
+ @pid = pid
6
+ end
7
+ # Memory usage in kilobytes (resident set size)
8
+ def memory
9
+ ps_int('rss')
10
+ end
11
+
12
+ # Percentage memory usage
13
+ def percent_memory
14
+ ps_float('%mem')
15
+ end
16
+
17
+ # Percentage CPU usage
18
+ def percent_cpu
19
+ ps_float('%cpu')
20
+ end
21
+
22
+ private
23
+
24
+ def ps_int(keyword)
25
+ `ps -o #{keyword}= -p #{@pid}`.to_i
26
+ end
27
+
28
+ def ps_float(keyword)
29
+ `ps -o #{keyword}= -p #{@pid}`.to_f
30
+ end
31
+
32
+ def ps_string(keyword)
33
+ `ps -o #{keyword}= -p #{@pid}`.strip
34
+ end
35
+
36
+ def time_string_to_seconds(text)
37
+ _, minutes, seconds, useconds = *text.match(/(\d+):(\d{2}).(\d{2})/)
38
+ (minutes.to_i * 60) + seconds.to_i
39
+ end
40
+ end
41
+ end
42
+ end
43
+
1
44
  module Merb
2
45
  module Rack
3
46
  class AbstractAdapter
@@ -106,10 +149,27 @@ module Merb
106
149
  Thread.new do
107
150
  catch(:new_worker) do
108
151
  loop do
109
- pid = @pids[port + i]
152
+ pid, status = @pids[port + i], nil
153
+ poller = Merb::System::PortablePoller.new(pid)
110
154
  begin
111
- # Watch for the pid to exit.
112
- _, status = Process.wait2(pid)
155
+ loop do
156
+ # Watch for the pid to exit.
157
+ _, status = Process.wait2(pid, Process::WNOHANG)
158
+ break if status
159
+
160
+ if Merb::Config[:max_memory] && poller.memory > Merb::Config[:max_memory]
161
+ Process.kill("INT", pid)
162
+ if (Process.kill(0, pid) rescue false)
163
+ sleep Merb::Config[:hang_time] || 5
164
+ Process.kill(9, pid)
165
+ Process.wait2(pid) if (Process.kill(0, pid) rescue false)
166
+ end
167
+
168
+ status = Struct.new(:exitstatus).new(nil)
169
+ break
170
+ end
171
+ sleep 0.25
172
+ end
113
173
 
114
174
  # If the pid doesn't exist, we want to silently exit instead of
115
175
  # raising here.
@@ -1,4 +1,5 @@
1
1
  module Merb
2
- VERSION = '1.0.8.1' unless defined?(Merb::VERSION)
3
- DM_VERSION = '0.9.9' unless defined?(Merb::DM_VERSION)
2
+ VERSION = '1.0.9' unless defined?(Merb::VERSION)
3
+ DM_VERSION = '0.9.10' unless defined?(Merb::DM_VERSION)
4
+ DO_VERSION = '0.9.11' unless defined?(Merb::DO_VERSION)
4
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8.1
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-19 00:00:00 -07:00
12
+ date: 2009-02-12 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency