contained_mr 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/contained_mr.gemspec +3 -3
- data/lib/contained_mr/job_logic.rb +15 -9
- data/lib/contained_mr/mock/runner.rb +12 -1
- data/test/test_job_logic.rb +17 -1
- data/test/test_mock_runner.rb +53 -8
- data/test/test_runner_logic.rb +8 -0
- data/testdata/job.hello +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e185d4610f9518f8f95924cd6569f8f62bdd309d
|
4
|
+
data.tar.gz: 9dc30131aa6475f07b3e5042e43877dbab91d0a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 597919494dce5409863b1ecd5d8ea9b75870f6705d945e74822995501184b6a0138fdd730a6c04e2a0bbe1bb7c85bcb3028f5a1c6291ec2bd0284bc01d06dfc3
|
7
|
+
data.tar.gz: c0936fd70b787f76aa222186ee6e915b9d400f0abb036af0c09a038c33a6049e4cf11d4435ab3c0dea6291a5fae6feb13a0b7eb6c647e4fa24e4a006f49add3d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/contained_mr.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: contained_mr 0.
|
5
|
+
# stub: contained_mr 0.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "contained_mr"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Victor Costan"]
|
14
|
-
s.date = "2015-10-
|
14
|
+
s.date = "2015-10-17"
|
15
15
|
s.description = "Plumbing for running mappers and reducers inside Docker containers"
|
16
16
|
s.email = "victor@costan.us"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -96,11 +96,7 @@ module ContainedMr::JobLogic
|
|
96
96
|
# @return {Hash<String, Object>} a container's HostConfig params
|
97
97
|
def container_host_config(job_section)
|
98
98
|
ram_bytes = (job_section[:ram] * 1048576).to_i
|
99
|
-
|
100
|
-
swap_bytes = -1
|
101
|
-
else
|
102
|
-
swap_bytes = (job_section[:swap] * 1048576).to_i + ram_bytes
|
103
|
-
end
|
99
|
+
swap_bytes = (job_section[:swap] * 1048576).to_i + ram_bytes
|
104
100
|
|
105
101
|
# NOTE: The value below is 1 second, in microsecodns. This is the maximum
|
106
102
|
# value, and it minimizes scheduling overheads, at the expense of
|
@@ -109,8 +105,16 @@ module ContainedMr::JobLogic
|
|
109
105
|
|
110
106
|
{
|
111
107
|
'Memory' => ram_bytes, 'MemorySwap' => swap_bytes,
|
108
|
+
'MemorySwappiness' => 0,
|
112
109
|
'CpuPeriod' => cpu_period,
|
113
110
|
'CpuQuota' => (job_section[:vcpus] * cpu_period).to_i,
|
111
|
+
'LogConfig' => {
|
112
|
+
'Type' => 'json-file',
|
113
|
+
'Config' => {
|
114
|
+
'max-size' => (job_section[:logs] * 1048576).to_i.to_s,
|
115
|
+
'max-file' => '1',
|
116
|
+
},
|
117
|
+
},
|
114
118
|
}
|
115
119
|
end
|
116
120
|
private :container_host_config
|
@@ -122,8 +126,9 @@ module ContainedMr::JobLogic
|
|
122
126
|
@mapper_options = {
|
123
127
|
wait_time: mapper['wait_time'] || 60,
|
124
128
|
vcpus: mapper['vcpus'] || 1, # logical processors
|
125
|
-
ram: mapper['ram'] || 512,
|
126
|
-
swap: mapper['swap'] || 0,
|
129
|
+
ram: mapper['ram'] || 512, # megabytes
|
130
|
+
swap: mapper['swap'] || 0, # megabytes
|
131
|
+
logs: mapper['logs'] || 64, # megabytes
|
127
132
|
ulimits: {
|
128
133
|
cpu: mapper_ulimits['cpu'] || 60, # seconds
|
129
134
|
}
|
@@ -134,8 +139,9 @@ module ContainedMr::JobLogic
|
|
134
139
|
@reducer_options = {
|
135
140
|
wait_time: reducer['wait_time'] || 60,
|
136
141
|
vcpus: reducer['vcpus'] || 1, # logical processors
|
137
|
-
ram: reducer['ram'] || 512,
|
138
|
-
swap: reducer['swap'] || 0,
|
142
|
+
ram: reducer['ram'] || 512, # megabytes
|
143
|
+
swap: reducer['swap'] || 0, # megabytes
|
144
|
+
logs: reducer['logs'] || 64, # megabytes
|
139
145
|
ulimits: {
|
140
146
|
cpu: reducer_ulimits['cpu'] || 60,
|
141
147
|
}
|
@@ -101,7 +101,6 @@ class ContainedMr::Mock::Runner
|
|
101
101
|
return nil unless memory = host_config['Memory']
|
102
102
|
return nil unless memory_swap = host_config['MemorySwap']
|
103
103
|
|
104
|
-
return 0 if memory_swap == -1
|
105
104
|
(memory_swap - memory) / (1024 * 1024).to_f
|
106
105
|
end
|
107
106
|
|
@@ -116,4 +115,16 @@ class ContainedMr::Mock::Runner
|
|
116
115
|
|
117
116
|
quota / period.to_f
|
118
117
|
end
|
118
|
+
|
119
|
+
# Convenience method for looking up the log size limit in container options.
|
120
|
+
#
|
121
|
+
# @return {Number} the container's log limit, in megabytes
|
122
|
+
def _logs
|
123
|
+
return nil unless host_config = @_container_options['HostConfig']
|
124
|
+
return nil unless log_config = host_config['LogConfig']
|
125
|
+
return nil unless config = log_config['Config']
|
126
|
+
return nil unless max_size = config['max-size']
|
127
|
+
|
128
|
+
max_size.to_i / (1024 * 1024).to_f
|
129
|
+
end
|
119
130
|
end
|
data/test/test_job_logic.rb
CHANGED
@@ -40,8 +40,16 @@ class TestJobLogic < MiniTest::Test
|
|
40
40
|
'HostConfig' => {
|
41
41
|
'Memory' => 256.5 * 1024 * 1024,
|
42
42
|
'MemorySwap' => (256.5 + 64) * 1024 * 1024,
|
43
|
+
'MemorySwappiness' => 0,
|
43
44
|
'CpuQuota' => 1500000,
|
44
45
|
'CpuPeriod' => 1000000,
|
46
|
+
'LogConfig' => {
|
47
|
+
'Type' => 'json-file',
|
48
|
+
'Config' => {
|
49
|
+
'max-size' => '4718592',
|
50
|
+
'max-file' => '1',
|
51
|
+
},
|
52
|
+
},
|
45
53
|
},
|
46
54
|
}
|
47
55
|
assert_equal golden, @job.mapper_container_options(2)
|
@@ -62,9 +70,17 @@ class TestJobLogic < MiniTest::Test
|
|
62
70
|
'NetworkDisabled' => true, 'ExposedPorts' => {},
|
63
71
|
'HostConfig' => {
|
64
72
|
'Memory' => 768.5 * 1024 * 1024,
|
65
|
-
'MemorySwap' =>
|
73
|
+
'MemorySwap' => 768.5 * 1024 * 1024,
|
74
|
+
'MemorySwappiness' => 0,
|
66
75
|
'CpuQuota' => 500000,
|
67
76
|
'CpuPeriod' => 1000000,
|
77
|
+
'LogConfig' => {
|
78
|
+
'Type' => 'json-file',
|
79
|
+
'Config' => {
|
80
|
+
'max-size' => '6815744',
|
81
|
+
'max-file' => '1',
|
82
|
+
},
|
83
|
+
},
|
68
84
|
},
|
69
85
|
}
|
70
86
|
assert_equal golden, @job.reducer_container_options
|
data/test/test_mock_runner.rb
CHANGED
@@ -17,8 +17,16 @@ class TestMockRunner < MiniTest::Test
|
|
17
17
|
'HostConfig' => {
|
18
18
|
'Memory' => 256.5 * 1024 * 1024,
|
19
19
|
'MemorySwap' => (256.5 + 64) * 1024 * 1024,
|
20
|
+
'MemorySwappiness' => 0,
|
20
21
|
'CpuQuota' => 1500000,
|
21
22
|
'CpuPeriod' => 1000000,
|
23
|
+
'LogConfig' => {
|
24
|
+
'Type' => 'json-file',
|
25
|
+
'Config' => {
|
26
|
+
'max-size' => '4718592',
|
27
|
+
'max-file' => '1',
|
28
|
+
},
|
29
|
+
},
|
22
30
|
},
|
23
31
|
}
|
24
32
|
@runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
@@ -103,63 +111,100 @@ class TestMockRunner < MiniTest::Test
|
|
103
111
|
assert_equal nil, runner._ulimit('rss')
|
104
112
|
end
|
105
113
|
|
106
|
-
def
|
114
|
+
def test_resources
|
107
115
|
assert_equal 256.5, @runner._ram_limit
|
108
116
|
assert_equal 64, @runner._swap_limit
|
109
117
|
assert_equal 1.5, @runner._vcpus
|
118
|
+
assert_equal 4.5, @runner._logs
|
110
119
|
end
|
111
120
|
|
112
|
-
def
|
121
|
+
def test_resources_without_host_config
|
113
122
|
@container_options.delete 'HostConfig'
|
114
123
|
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
115
124
|
'/usr/mrd/map-output'
|
116
125
|
assert_equal nil, runner._ram_limit
|
117
126
|
assert_equal nil, runner._swap_limit
|
118
127
|
assert_equal nil, runner._vcpus
|
128
|
+
assert_equal nil, runner._logs
|
119
129
|
end
|
120
130
|
|
121
|
-
def
|
131
|
+
def test_resources_without_host_config_memory
|
122
132
|
@container_options['HostConfig'].delete 'Memory'
|
123
133
|
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
124
134
|
'/usr/mrd/map-output'
|
125
135
|
assert_equal nil, runner._ram_limit
|
126
136
|
assert_equal nil, runner._swap_limit
|
127
137
|
assert_equal 1.5, runner._vcpus
|
138
|
+
assert_equal 4.5, runner._logs
|
128
139
|
end
|
129
140
|
|
130
|
-
def
|
141
|
+
def test_resources_without_host_config_memory_swap
|
131
142
|
@container_options['HostConfig'].delete 'MemorySwap'
|
132
143
|
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
133
144
|
'/usr/mrd/map-output'
|
134
145
|
assert_equal 256.5, runner._ram_limit
|
135
146
|
assert_equal nil, runner._swap_limit
|
136
147
|
assert_equal 1.5, runner._vcpus
|
148
|
+
assert_equal 4.5, runner._logs
|
137
149
|
end
|
138
150
|
|
139
|
-
def
|
151
|
+
def test_resources_without_host_config_cpu_shares
|
140
152
|
@container_options['HostConfig'].delete 'CpuQuota'
|
141
153
|
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
142
154
|
'/usr/mrd/map-output'
|
143
155
|
assert_equal 256.5, runner._ram_limit
|
144
156
|
assert_equal 64, runner._swap_limit
|
145
157
|
assert_equal nil, runner._vcpus
|
158
|
+
assert_equal 4.5, runner._logs
|
146
159
|
end
|
147
160
|
|
148
|
-
def
|
161
|
+
def test_resources_without_host_config_cpu_period
|
149
162
|
@container_options['HostConfig'].delete 'CpuPeriod'
|
150
163
|
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
151
164
|
'/usr/mrd/map-output'
|
152
165
|
assert_equal 256.5, runner._ram_limit
|
153
166
|
assert_equal 64, runner._swap_limit
|
154
167
|
assert_equal nil, runner._vcpus
|
168
|
+
assert_equal 4.5, runner._logs
|
155
169
|
end
|
156
170
|
|
157
|
-
def
|
158
|
-
@container_options['HostConfig']
|
171
|
+
def test_resources_without_host_config_log_config
|
172
|
+
@container_options['HostConfig'].delete 'LogConfig'
|
173
|
+
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
174
|
+
'/usr/mrd/map-output'
|
175
|
+
assert_equal 256.5, runner._ram_limit
|
176
|
+
assert_equal 64, runner._swap_limit
|
177
|
+
assert_equal 1.5, runner._vcpus
|
178
|
+
assert_equal nil, runner._logs
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_resources_without_host_config_log_config_config
|
182
|
+
@container_options['HostConfig']['LogConfig'].delete 'Config'
|
183
|
+
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
184
|
+
'/usr/mrd/map-output'
|
185
|
+
assert_equal 256.5, runner._ram_limit
|
186
|
+
assert_equal 64, runner._swap_limit
|
187
|
+
assert_equal 1.5, runner._vcpus
|
188
|
+
assert_equal nil, runner._logs
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_resources_without_host_config_log_config_config_max_size
|
192
|
+
@container_options['HostConfig']['LogConfig']['Config'].delete 'max-size'
|
193
|
+
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
194
|
+
'/usr/mrd/map-output'
|
195
|
+
assert_equal 256.5, runner._ram_limit
|
196
|
+
assert_equal 64, runner._swap_limit
|
197
|
+
assert_equal 1.5, runner._vcpus
|
198
|
+
assert_equal nil, runner._logs
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_resources_with_zero_swap
|
202
|
+
@container_options['HostConfig']['MemorySwap'] = 256.5 * 1024 * 1024
|
159
203
|
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
160
204
|
'/usr/mrd/map-output'
|
161
205
|
assert_equal 256.5, runner._ram_limit
|
162
206
|
assert_equal 0, runner._swap_limit
|
163
207
|
assert_equal 1.5, runner._vcpus
|
208
|
+
assert_equal 4.5, runner._logs
|
164
209
|
end
|
165
210
|
end
|
data/test/test_runner_logic.rb
CHANGED
@@ -16,8 +16,16 @@ class TestRunnerLogic < MiniTest::Test
|
|
16
16
|
'HostConfig' => {
|
17
17
|
'Memory' => 256.5 * 1024 * 1024,
|
18
18
|
'MemorySwap' => (256.5 + 64) * 1024 * 1024,
|
19
|
+
'MemorySwappiness' => 0,
|
19
20
|
'CpuQuota' => 1500000,
|
20
21
|
'CpuPeriod' => 1000000,
|
22
|
+
'LogConfig' => {
|
23
|
+
'Type' => 'json-file',
|
24
|
+
'Config' => {
|
25
|
+
'max-size' => '4718592',
|
26
|
+
'max-file' => '1',
|
27
|
+
},
|
28
|
+
},
|
21
29
|
},
|
22
30
|
}
|
23
31
|
@runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
data/testdata/job.hello
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contained_mr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Costan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|