contained_mr 0.3.4 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa36265b30cbc358e74b368ebdf5cf9a90c6ebaa
4
- data.tar.gz: f10177d6247c5be5e24c7c47cc72e1511f1805d3
3
+ metadata.gz: e185d4610f9518f8f95924cd6569f8f62bdd309d
4
+ data.tar.gz: 9dc30131aa6475f07b3e5042e43877dbab91d0a3
5
5
  SHA512:
6
- metadata.gz: be014222e385e4b87ac25e5d4e979bd1931b1d6f3ffc304543a11fab3857fb82030eca49d68818c8d3ffe33366518d7b178e77af96c546459afd2e3200afe4d5
7
- data.tar.gz: 9a31100c13d897147cd0ca6bef0dc53fd5109d701b0dc4c6c3a5bd469a246d7385e5fe71d33a9e93124c679bc82ef97424048a430159e8f41c79c7ad2063990d
6
+ metadata.gz: 597919494dce5409863b1ecd5d8ea9b75870f6705d945e74822995501184b6a0138fdd730a6c04e2a0bbe1bb7c85bcb3028f5a1c6291ec2bd0284bc01d06dfc3
7
+ data.tar.gz: c0936fd70b787f76aa222186ee6e915b9d400f0abb036af0c09a038c33a6049e4cf11d4435ab3c0dea6291a5fae6feb13a0b7eb6c647e4fa24e4a006f49add3d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
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.3.4 ruby lib
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.3.4"
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-13"
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
- if job_section[:swap] == 0
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, # megabytes
126
- swap: mapper['swap'] || 0, # megabytes
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, # megabytes
138
- swap: reducer['swap'] || 0, # megabytes
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
@@ -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' => -1,
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
@@ -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 test_memory_cpu_limits
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 test_memory_cpu_limits_without_host_config
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 test_memory_cpu_limits_without_host_config_memory
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 test_memory_cpu_limits_without_host_config_memory_swap
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 test_memory_cpu_limits_without_host_config_cpu_shares
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 test_memory_cpu_limits_without_host_config_cpu_period
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 test_memory_limits_without_swap
158
- @container_options['HostConfig']['MemorySwap'] = -1
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
@@ -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
@@ -4,6 +4,7 @@
4
4
  "vcpus": 1.5,
5
5
  "ram": 256.5,
6
6
  "swap": 64,
7
+ "logs": 4.5,
7
8
  "ulimits": { "cpu": 3 }
8
9
  },
9
10
  "reducer": {
@@ -11,6 +12,7 @@
11
12
  "vcpus": 0.5,
12
13
  "ram": 768.5,
13
14
  "swap": 0,
15
+ "logs": 6.5,
14
16
  "ulimits": { "cpu": 2 }
15
17
  }
16
18
  }
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.3.4
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-13 00:00:00.000000000 Z
11
+ date: 2015-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api