Skip to content

Commit a2711ef

Browse files
committed
Switch from proc-wait3 to rusage gem.
proc-wait3 monkey patches `$?` which was causing problems for poltergeist. rusage is lighter weight and provides the bit of proc-wait3 we care about.
1 parent e483351 commit a2711ef

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

Gemfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ GEM
6060
http_parser.rb (~> 0.5.3)
6161
multi_json (~> 1.0)
6262
powerpack (0.0.8)
63-
proc-wait3 (1.6.0)
6463
rack (1.5.2)
6564
rack-protection (1.5.0)
6665
rack
@@ -84,6 +83,7 @@ GEM
8483
powerpack (~> 0.0.6)
8584
rainbow (>= 1.1.4)
8685
rubyzip (0.9.9)
86+
rusage (0.2.0)
8787
selenium-webdriver (2.35.1)
8888
childprocess (>= 0.2.5)
8989
multi_json (~> 1.0)
@@ -124,12 +124,12 @@ DEPENDENCIES
124124
launchy (~> 2.1.0)
125125
metriks (~> 0.9)
126126
poltergeist (~> 1.0.0)
127-
proc-wait3 (~> 1.6)
128127
qless!
129128
rake (~> 10.0)
130129
rspec (~> 2.12)
131130
rspec-fire (~> 1.1)
132131
rubocop (~> 0.13.1)
132+
rusage (~> 0.2.0)
133133
sentry-raven (~> 0.4)
134134
simplecov (~> 0.7.1)
135135
sinatra (~> 1.3.2)

benchmarks/current_memory_usage.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
n.times { Integer(`ps -o rss= -p #{Process.pid}`) * 1024 }
88
end
99

10-
x.report("proc-wait3") do
11-
require 'proc/wait3'
12-
n.times { Process.getrusage }
10+
x.report("rusage") do
11+
require 'rusage'
12+
n.times { Process.rusage }
1313
end
1414
end
1515

1616
=begin
1717
On my computer:
1818
1919
Rehearsal ------------------------------------------------
20-
shelling out 0.100000 0.670000 3.750000 ( 4.141153)
21-
proc-wait3 0.000000 0.000000 0.000000 ( 0.002601)
22-
--------------------------------------- total: 3.750000sec
20+
shelling out 0.090000 0.550000 3.650000 ( 4.051986)
21+
rusage 0.010000 0.000000 0.010000 ( 0.002501)
22+
--------------------------------------- total: 3.660000sec
2323
2424
user system total real
25-
shelling out 0.090000 0.730000 3.760000 ( 4.150078)
26-
proc-wait3 0.000000 0.000000 0.000000 ( 0.003116)
25+
shelling out 0.100000 0.550000 3.660000 ( 4.031830)
26+
rusage 0.010000 0.000000 0.010000 ( 0.001669)
2727
=end
2828

lib/qless/middleware/memory_usage_monitor.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ def format_large_number(num)
2828
end
2929

3030
begin
31-
require 'proc/wait3'
31+
require 'rusage'
3232
def self.current_usage
33-
Process.getrusage.maxrss
33+
Process.rusage.maxrss
3434
end
3535
rescue LoadError
36-
warn "Could not load `proc-wait3` gem. Falling back to shelling out to get process memory usage, " +
36+
warn "Could not load `rusage` gem. Falling back to shelling out to get process memory usage, " +
3737
"which is several orders of magnitude slower."
3838

3939
def self.current_usage

qless.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ language-specific extension will also remain up to date.
5050
s.add_development_dependency 'sentry-raven' , '~> 0.4'
5151
s.add_development_dependency 'metriks' , '~> 0.9'
5252
s.add_development_dependency 'rubocop' , '~> 0.13.1'
53-
s.add_development_dependency 'proc-wait3' , '~> 1.6'
53+
s.add_development_dependency 'rusage' , '~> 0.2.0'
5454
end

spec/integration/middleware/memory_usage_monitor_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,19 @@ def self.puts(msg)
9292
end
9393
end
9494

95-
context "when the proc-wait3 gem is available" do
95+
context "when the rusage gem is available" do
9696
before do
9797
load "qless/middleware/memory_usage_monitor.rb"
9898

99-
unless Process.respond_to?(:getrusage)
100-
pending "Could not load the proc-wait3 gem"
99+
unless Process.respond_to?(:rusage)
100+
pending "Could not load the rusage gem"
101101
end
102102
end
103103

104104
include_examples "memory usage monitor"
105105
end
106106

107-
context "when the proc-wait3 gem is not available" do
107+
context "when the rusage gem is not available" do
108108
before do
109109
MemoryUsageMonitor.stub(:warn)
110110
MemoryUsageMonitor.stub(:require).and_raise(LoadError)

0 commit comments

Comments
 (0)