-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
executable file
·87 lines (78 loc) · 1.89 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env rake
MAXFILES = ENV['MAXFILES'] || 65535
def as_root(*args)
unless Process.euid == 0
cmd = ['sudo', __FILE__, *args]
puts cmd.join(' ')
exec *cmd
end
end
desc "setup limits.conf"
task :limits do
desired = <<-PLAIN
* soft nofile 1024
* hard nofile 65535
PLAIN
path = '/etc/security/limits.conf'
limits = File.read(path)
soft = limits[/soft\s+nofile\s+(\d+)/m, 1]
hard = limits[/hard\s+nofile\s+(\d+)/m, 1]
unless soft || hard
as_root('limits')
open('/etc/secuirty/limits.conf', 'a') do |f|
f.puts
f.puts desired
end
else
unless hard && hard.to_i >= MAXFILES
puts "Please setup the following entries in #{path}:\n#{desired}"
else
puts "hard: #{hard}"
puts "soft: #{soft}"
end
end
end
desc "setup file-max"
task :file_max do
path = '/proc/sys/fs/file-max'
limit = File.read(path).to_i
unless limit >= MAXFILES
as_root('file_max')
open('/proc/sys/fs/file-max', 'w') { |f| f.write(MAXFILES.to_s) }
end
end
desc "set kernel maxfiles to #{MAXFILES}"
task :sysctl do
maxfiles = `sysctl kern.maxfiles`[/:\s*(\d+)/, 1].to_i
maxfilesproc = `sysctl kern.maxfilesperproc`[/:\s*(\d+)/, 1].to_i
unless maxfiles >= MAXFILES && maxfilesproc >= MAXFILES
as_root('sysctl')
sh "sysctl -w kern.maxfiles=#{MAXFILES}"
sh "sysctl -w kern.maxfilesperproc=#{MAXFILES}"
end
end
desc "set ulimit to #{MAXFILES}"
task :ulimit do
case RUBY_PLATFORM
when /linux/
sh "ulimit -n unlimited"
else
# Assume broken ulimit implementation.
sh "ulimit -n #{MAXFILES}"
end
sh "ulimit -n"
end
desc "start test"
task :run do
ruby '-rubygems', 'conns.rb', MAXFILES.to_s
end
desc "show time waits"
task :time_waits do
grep = if RUBY_PLATFORM =~ /mswin|mingw/
'find "TIME_WAIT"'
else
'grep TIME_WAIT'
end
system "netstat -an | #{grep}"
end
task :default => :run