Project

General

Profile

Dispatching containers to cloud VMs » History » Version 51

Tom Clegg, 02/05/2019 09:53 PM

1 1 Tom Clegg
h1. Dispatching containers to cloud VMs
2
3 6 Tom Clegg
(Draft)
4 1 Tom Clegg
5 11 Tom Clegg
{{>toc}}
6
7 7 Tom Clegg
h2. Component name / purpose
8 1 Tom Clegg
9 7 Tom Clegg
crunch-dispatch-cloud runs Arvados user containers on generic public cloud infrastructure by automatically creating and destroying VMs of various sizes according to demand, preparing the VMs' runtime environments, and running containers on them.
10 1 Tom Clegg
11 49 Tom Clegg
h2. Overview of operation
12
13
The dispatcher waits for containers to appear in the queue, and runs them on appropriately sized cloud VMs. When there are no idle cloud VMs with the desired size, the dispatcher brings up more VMs using the cloud provider's API. The dispatcher also shuts down idle VMs that exceed the configured idle timer -- and sooner if the provider starts refusing to create new VMs.
14
15
h2. Interaction with other components
16
17
Controller (backed by RailsAPI and PostgreSQL) supplies the container queue: which containers the system should be trying to execute (or cancel) at any given time.
18
19
The cloud provider's API supplies a list of VMs that exist (or are being created) at a given time and their network addresses, accepts orders to create new VMs, updates instance tags, and (optionally, depending on the driver) obtains the VMs' SSH server public keys.
20
21
The SSH server on each cloud VM allows the dispatcher to authenticate with a private key and execute shell commands as root.
22
23
h2. Instance tags
24
25
The dispatcher relies on the cloud provider's tagging feature to persist state across server restarts.
26
* {"InstanceType": "foo"} indicates that the instance was created with the specs from the instance type named "foo" in the cluster configuration file.
27 50 Tom Clegg
* {"IdleBehavior": "hold"} indicates that the management API has been used to put the instance in "hold" state.
28 49 Tom Clegg
29
Provider-specific drivers (Amazon, Google, Azure) determine exactly how these tags are encoded in the cloud API, and can use tags to persist their own internal state as well. For example, a driver might save tags named "Arvados-DispatchCloud-InstanceType" rather than just "InstanceType".
30
31 23 Tom Clegg
h2. Deployment
32 24 Tom Clegg
33
*Where to install:* The crunch-dispatch-cloud process can run anywhere, as long as it has network access to the Arvados controller, the cloud provider's API, and the worker VMs. Each Arvados cluster should run only one crunch-dispatch-cloud process.
34 9 Tom Clegg
* Future versions will support multiple dispatchers.
35 1 Tom Clegg
36 9 Tom Clegg
*Dispatcher's SSH key:* The operator must generate an SSH key pair for the dispatcher to use when connecting to cloud VMs. The private key is stored (without a passphrase) in the cluster configuration file. It does not need to be saved in @~/.ssh/@.
37 1 Tom Clegg
38 6 Tom Clegg
*Cloud VM image:* The operator must provide a VM image with an SSH server on a port reachable by the dispatcher (default 22, configurable per cluster). The dispatcher's SSH public key must be listed in @/root/.ssh/authorized_keys@. The image should also include suitable versions of docker and crunch-run. The @/var/lock@ directory must be available for lockfiles with names matching "@crunch-run-*.*@".
39 1 Tom Clegg
* It is possible to install docker and crunch-run using a custom boot probe command, but pre-installing is more efficient.
40 9 Tom Clegg
* Future versions will automatically sync the crunch-run binary from the dispatcher host to each worker node.
41 1 Tom Clegg
42 6 Tom Clegg
*Cloud provider account:* The dispatcher uses cloud provider credentials to create and delete VMs and other cloud resources. An Arvados user can create an arbitrary number of long-running containers, and the dispatcher will try to run all of them. Currently the dispatcher does not enforce any resource limits of its own, so the operator must ensure the cloud provider itself is enforcing a suitable quota.
43 1 Tom Clegg
44 6 Tom Clegg
*Migrating from nodemanager/SLURM:* When VM images, SSH keys, and configuration files are ready, disable nodemanager and crunch-dispatch-slurm. Install crunch-dispatch-cloud deb/rpm package. Confirm success with @systemctl status crunch-dispatch-cloud@ and @journalctl -fu crunch-dispatch-cloud@.
45 1 Tom Clegg
46 6 Tom Clegg
h2. Configuration
47 1 Tom Clegg
48 42 Tom Clegg
Arvados [[Cluster configuration]] (currently a file in /etc) supplies cloud provider credentials, allowed node types, spending limits/policies, etc.
49 1 Tom Clegg
50 6 Tom Clegg
<pre><code class="yaml">
51
    CloudVMs:
52 1 Tom Clegg
      BootProbeCommand: "docker ps -q"
53 42 Tom Clegg
      SSHPort: 22
54 27 Tom Clegg
      SyncInterval: 1m    # how often to get list of active instances from cloud provider
55 8 Tom Clegg
      TimeoutIdle: 1m     # shutdown if idle longer than this
56
      TimeoutBooting: 10m # shutdown if exists longer than this without running BootProbeCommand successfully
57
      TimeoutProbe: 2m    # shutdown if (after booting) communication fails longer than this, even if ctrs are running
58
      TimeoutShutdown: 1m # shutdown again if node still exists this long after shutdown
59 6 Tom Clegg
      Driver: Amazon
60 8 Tom Clegg
      DriverParameters:   # following configs are driver dependent
61 6 Tom Clegg
        Region: us-east-1
62
        APITimeout: 20s
63 39 Tom Clegg
        AWSAccessKeyID: abcdef
64
        AWSSecretAccessKey: abcdefghijklmnopqrstuvwxyz
65 6 Tom Clegg
        ImageID: ami-0123456789abcdef0
66 1 Tom Clegg
        SubnetID: subnet-01234567
67
        SecurityGroups: sg-01234567
68 8 Tom Clegg
    Dispatch:
69
      StaleLockTimeout: 1m     # after restart, time to wait for workers to come up before abandoning locks from previous run
70
      PollInterval: 1m         # how often to get latest queue from arvados controller
71
      ProbeInterval: 10s       # how often to probe each instance for current status/vital signs
72
      MaxProbesPerSecond: 1000 # limit total probe rate for dispatch process (across all instances)
73
      PrivateKey: |            # SSH key able to log in as root@ worker VMs
74
        -----BEGIN RSA PRIVATE KEY-----
75
        MIIEowIBAAKCAQEAqYm4XsQHm8sBSZFwUX5VeW1OkGsfoNzcGPG2nzzYRhNhClYZ
76
        0ABHhUk82HkaC/8l6d/jpYTf42HrK42nNQ0r0Yzs7qw8yZMQioK4Yk+kFyVLF78E
77
        GRG4pGAWXFs6pUchs/lm8fo9zcda4R3XeqgI+NO+nEERXmdRJa1FhI+Za3/S/+CV
78
        mg+6O00wZz2+vKmDPptGN4MCKmQOCKsMJts7wSZGyVcTtdNv7jjfr6yPAIOIL8X7
79
        LtarBCFaK/pD7uWll/Uj7h7D8K48nIZUrvBJJjXL8Sm4LxCNoz3Z83k8J5ZzuDRD
80
        gRiQe/C085mhO6VL+2fypDLwcKt1tOL8fI81MwIDAQABAoIBACR3tEnmHsDbNOav
81
        Oxq8cwRQh9K2yDHg8BMJgz/TZa4FIx2HEbxVIw0/iLADtJ+Z/XzGJQCIiWQuvtg6
82
        exoFQESt7JUWRWkSkj9JCQJUoTY9Vl7APtBpqG7rIEQzd3TvzQcagZNRQZQO6rR7
83
        p8sBdBSZ72lK8cJ9tM3G7Kor/VNK7KgRZFNhEWnmvEa3qMd4hzDcQ4faOn7C9NZK
84
        dwJAuJVVfwOLlOORYcyEkvksLaDOK2DsB/p0AaCpfSmThRbBKN5fPXYaKgUdfp3w
85
        70Hpp27WWymb1cgjyqSH3DY+V/kvid+5QxgxCBRq865jPLn3FFT9bWEVS/0wvJRj
86
        iMIRrjECgYEA4Ffv9rBJXqVXonNQbbstd2PaprJDXMUy9/UmfHL6pkq1xdBeuM7v
87
        yf2ocXheA8AahHtIOhtgKqwv/aRhVK0ErYtiSvIk+tXG+dAtj/1ZAKbKiFyxjkZV
88
        X72BH7cTlR6As5SRRfWM/HaBGEgED391gKsI5PyMdqWWdczT5KfxAksCgYEAwXYE
89
        ewPmV1GaR5fbh2RupoPnUJPMj36gJCnwls7sGaXDQIpdlq56zfKgrLocGXGgj+8f
90
        QH7FHTJQO15YCYebtsXWwB3++iG43gVlJlecPAydsap2CCshqNWC5JU5pan0QzsP
91
        exzNzWqfUPSbTkR2SRaN+MenZo2Y/WqScOAth7kCgYBgVoLujW9EXH5QfXJpXLq+
92
        jTvE38I7oVcs0bJwOLPYGzcJtlwmwn6IYAwohgbhV2pLv+EZSs42JPEK278MLKxY
93
        lgVkp60npgunFTWroqDIvdc1TZDVxvA8h9VeODEJlSqxczgbMcIUXBM9yRctTI+5
94
        7DiKlMUA4kTFW2sWwuOlFwKBgGXvrYS0FVbFJKm8lmvMu5D5x5RpjEu/yNnFT4Pn
95
        G/iXoz4Kqi2PWh3STl804UF24cd1k94D7hDoReZCW9kJnz67F+C67XMW+bXi2d1O
96
        JIBvlVfcHb1IHMA9YG7ZQjrMRmx2Xj3ce4RVPgUGHh8ra7gvLjd72/Tpf0doNClN
97
        ti/hAoGBAMW5D3LhU05LXWmOqpeT4VDgqk4MrTBcstVe7KdVjwzHrVHCAmI927vI
98 1 Tom Clegg
        pjpphWzpC9m3x4OsTNf8m+g6H7f3IiQS0aiFNtduXYlcuT5FHS2fSATTzg5PBon9
99
        1E6BudOve+WyFyBs7hFWAqWFBdWujAl4Qk5Ek09U2ilFEPE7RTgJ
100
        -----END RSA PRIVATE KEY-----
101 9 Tom Clegg
    InstanceTypes:
102
    - Name: m4.large
103
      VCPUs: 2
104
      RAM: 7782000000
105
      Scratch: 32000000000
106
      Price: 0.1
107
    - Name: m4.large.spot
108
      Preemptible: true
109
      VCPUs: 2
110
      RAM: 7782000000
111
      Scratch: 32000000000
112
      Price: 0.1
113
    - Name: m4.xlarge
114
      VCPUs: 4
115
      RAM: 15564000000
116
      Scratch: 80000000000
117
      Price: 0.2
118
    - Name: m4.xlarge.spot
119
      Preemptible: true
120
      VCPUs: 4
121
      RAM: 15564000000
122
      Scratch: 80000000000
123
      Price: 0.2
124
    - Name: m4.2xlarge
125
      VCPUs: 8
126
      RAM: 31129000000
127
      Scratch: 160000000000
128
      Price: 0.4
129
    - Name: m4.2xlarge.spot
130
      Preemptible: true
131
      VCPUs: 8
132
      RAM: 31129000000
133
      Scratch: 160000000000
134
      Price: 0.4
135 6 Tom Clegg
</code></pre>
136 1 Tom Clegg
137 10 Tom Clegg
h2. Management API
138 1 Tom Clegg
139 10 Tom Clegg
APIs for monitoring/diagnostics/control are available via HTTP on a configurable address/port. Request headers must include "Authorization: Bearer {management token}".
140
141
Responses are JSON-encoded and resemble other Arvados APIs:
142
<pre><code class="json">
143
{
144 43 Tom Clegg
  "items": [
145 10 Tom Clegg
    {
146 43 Tom Clegg
      "name": "...",
147 10 Tom Clegg
      ...
148
    },
149
    ...
150
  ]
151
}
152
</code></pre>
153
154
@GET /arvados/v1/dispatch/instances@ lists cloud VMs. Each returned item includes:
155
* provider's instance ID
156
* hourly price (from configuration file)
157
* instance type (from configuration file)
158
* instance type (from provider's menu)
159
* UUID of the current / most recent container attempted (if known)
160
* time last container finished (or boot time, if nothing run yet)
161
162
@GET /arvados/v1/dispatch/containers@ lists queued/locked/running containers. Each returned item includes:
163
* container UUID
164
* container state (Queued/Locked/Running/Complete/Cancelled)
165
* desired instance type
166
* time appeared in queue
167
* time started (if started)
168
169 34 Tom Clegg
@POST /arvados/v1/dispatch/instances/:instance_id/hold@ puts an instance in "hold" state.
170
* if the instance is currently running a container, it is allowed to continue
171
* no further containers will be scheduled on the instance
172
* the instance will not be shut down automatically
173
174 10 Tom Clegg
@POST /arvados/v1/dispatch/instances/:instance_id/drain@ puts an instance in "drain" state.
175 1 Tom Clegg
* if the instance is currently running a container, it is allowed to continue
176
* no further containers will be scheduled on the instance
177 34 Tom Clegg
* the instance will be shut down automatically when all containers finish
178 1 Tom Clegg
179 48 Tom Clegg
&dagger;@POST /arvados/v1/dispatch/instances/:instance_id/kill@ shuts down an instance immediately.
180 34 Tom Clegg
* the instance is terminated immediately via cloud API
181
* SIGTERM is sent to the container if one is running, but no effort is made to give it time to end gracefully before terminating the instance
182
183 48 Tom Clegg
&dagger;@POST /arvados/v1/dispatch/loglevel/:level@ sets the logging threshold to "debug" or "info".
184 47 Tom Clegg
* @.../loglevel/debug@ enables debug logs
185
* @.../loglevel/info@ disables debug logs
186
187 10 Tom Clegg
h2. Metrics
188 13 Tom Clegg
189 10 Tom Clegg
Metrics are available via HTTP on a configurable address/port (conventionally :9005). Request headers must include "Authorization: Bearer {management token}".
190
191 13 Tom Clegg
Metrics include:
192 1 Tom Clegg
* (gauge) number of existing VMs
193 35 Tom Clegg
* (gauge) total hourly price of all existing VMs
194 46 Tom Clegg
* (gauge) total VCPUs and memory in all existing VMs
195 1 Tom Clegg
* (gauge) total VCPUs and memory allocated to containers
196
* (gauge) number of containers running
197 46 Tom Clegg
* &dagger;(gauge) number of containers allocated to VMs but not started yet (because VMs are pending/booting)
198
* &dagger;(gauge) number of containers not allocated to VMs (because provider quota is reached)
199
* &dagger;(gauge) total hourly price of VMs, partitioned by allocation state (running, booting/idle, adminhold)
200
* &dagger;(summary) time elapsed between VM creation and first successful SSH connection to that VM
201
* &dagger;(summary) time elapsed between first successful SSH connection on a VM and ready to run a container on that VM
202
* &dagger;(summary) time elapsed between first shutdown attempt on a VM and its disappearance from the provider listing
203
204
&dagger; not yet implemented
205
206 14 Tom Clegg
h2. Logs
207 20 Tom Clegg
208 16 Tom Clegg
For purposes of troubleshooting, a JSON-formatted log entry is printed on stderr when...
209 20 Tom Clegg
210 44 Tom Clegg
|                                                              |... if loglevel &ge; ...|...including timestamp and...|
211
|a new instance is created/ordered                             |info                    |instance type name|
212
|an instance appears on the provider's list of instances       |info                    |instance ID|
213
|an instance's boot probe succeeds                             |info                    |instance ID|
214
|an instance is shut down after boot timeout                   |warn                    |instance ID, &dagger;stdout/stderr/error from last boot probe attempt|
215
|an instance shutdown is requested                             |info                    |instance ID|
216
|an instance disappears from the provider's list of instances  |info                    |instance ID and previous state (booting/idle/shutdown)|
217
|a cloud provider API or driver error occurs                   |error                   |provider/driver's error message|
218
|a new container appears in the Arvados queue                  |&dagger;info            |container UUID, desired instance type name|
219 45 Tom Clegg
|a container is locked by the dispatcher                       |debug                   |container UUID|
220 44 Tom Clegg
|a crunch-run process is started on an instance                |info                    |container UUID, instance ID, crunch-run PID|
221
|a crunch-run process fails to start on an instance            |info                    |container UUID, instance ID, stdout/stderr/exitcode|
222
|a crunch-run process ends                                     |info                    |container UUID, instance ID|
223
|an active container's state changes to Complete or Cancelled  |info                    |container UUID, new state|
224
|an active container is requeued after being locked            |info                    |container UUID|  
225
|an Arvados API error occurs                                   |warn                    |error message|
226 16 Tom Clegg
227 44 Tom Clegg
&dagger; not yet implemented
228 1 Tom Clegg
229 51 Tom Clegg
Example log entries from test suite (note test suite uses text formatting, production logging uses JSON formatting):
230
<pre>
231
INFO[0000] creating new instance                         ContainerUUID=zzzzz-dz642-000000000000160 InstanceType=type8
232
INFO[0000] instance appeared in cloud                    IdleBehavior=run Instance=stub-providertype8-6ec34c367674cb74 InstanceType=type8 State=booting
233
INFO[0000] boot probe succeeded                          Command=true Instance=stub-providertype8-6ec34c367674cb74 InstanceType=type8 stderr= stdout=
234
INFO[0000] instance booted; will try probeRunning        Instance=stub-providertype8-6ec34c367674cb74 InstanceType=type8 ProbeStart="2019-02-05 15:49:49.183431341 -0500 EST m=+0.126074285"
235
INFO[0000] probes succeeded, instance is in service      Instance=stub-providertype8-6ec34c367674cb74 InstanceType=type8 ProbeStart="2019-02-05 15:49:49.183431341 -0500 EST m=+0.126074285" RunningContainers=0 State=idle
236
INFO[0000] crunch-run process started                    ContainerUUID=zzzzz-dz642-000000000000160 Instance=stub-providertype8-6ec34c367674cb74 InstanceType=type8 Priority=20
237
INFO[0000] container finished                            ContainerUUID=zzzzz-dz642-000000000000160 State=Complete
238
...
239
INFO[0002] shutdown idle worker                          Age=151.615512ms IdleBehavior=run Instance=stub-providertype8-6ec34c367674cb74 InstanceType=type8 State=idle
240
INFO[0002] instance disappeared in cloud                 Instance=stub-providertype8-6ec34c367674cb74 WorkerState=shutdown
241
</pre>
242 14 Tom Clegg
243 10 Tom Clegg
If the dispatcher starts with a non-empty ARVADOS_DEBUG environment variable, it also prints more detailed logs about other internal state changes, using level=debug.
244
245
h2. Internal details
246
247 38 Tom Clegg
h3. Worker lifecycle
248
249
<pre>
250 41 Tom Clegg
251
  ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
252
  │                                                                                                                                                    │
253
  │                  create() returns ID                                                                                                               │         want=drain
254
  │    ┌───────────────────────────────────────────────────────────────────────────┐                                      ┌────────────────────────────┼─────────────────────────────────────────┐
255
  │    │                                                                           ∨                                      │                            │                                         ∨
256
  │  ┌─────────────┐  appears in cloud list   ┌─────────┐  create() returns ID   ┌─────────┐  boot+run probes succeed   ┌──────┐  container starts   ┌─────────┐  container ends, want=drain   ┌──────────┐  instance disappears from cloud   ┌──────┐
257
  │  │ Nonexistent │ ───────────────────────> │ Unknown │ ─────────────────────> │ Booting │ ─────────────────────────> │      │ ──────────────────> │ Running │ ────────────────────────────> │          │ ────────────────────────────────> │ Gone │
258
  │  └─────────────┘                          └─────────┘                        └─────────┘                            │      │                     └─────────┘                               │          │                                   └──────┘
259
  │                                             │                                                                       │      │                                 idle timeout                  │          │
260
  │                                             │                                                                       │ Idle │ ────────────────────────────────────────────────────────────> │ Shutdown │
261
  │                                             │                                                                       │      │                                                               │          │
262
  │                                             │                                                                       │      │                                 probe timeout                 │          │
263
  │                                             │                                                                       │      │ ────────────────────────────────────────────────────────────> │          │
264
  │                                             │                                                                       └──────┘                                                               └──────────┘
265
  │                                             │                                                                         ∧      boot timeout                                                    ∧
266
  │                                             └─────────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┘
267
  │                                                                                                                       │
268
  │   container ends                                                                                                      │
269
  └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘</pre>
270 38 Tom Clegg
271 10 Tom Clegg
h3. Scheduling policy
272 6 Tom Clegg
273
The container priority field determines the order in which resources are allocated.
274
* If container C1 has priority P1,
275
* ...and C2 has higher priority P2,
276
* ...and there is no pending/booting/idle VM suitable for running C2,
277
* ...then C1 will not be started.
278
279 1 Tom Clegg
However, containers that run on different VM types don't necessarily start in priority order.
280
* If container C1 has priority P1,
281 5 Peter Amstutz
* ...and C2 has higher priority P2,
282 6 Tom Clegg
* ...and there is no idle VM suitable for running C2,
283
* ...and there is a pending/booting VM that will be suitable for running C2 when it comes up,
284 1 Tom Clegg
* ...and there is an idle VM suitable for running C1,
285 6 Tom Clegg
* ...then C1 will start before C2.
286 10 Tom Clegg
287 1 Tom Clegg
h3. Special cases / synchronizing state
288 6 Tom Clegg
289
When first starting up, dispatcher inspects API server’s container queue and the cloud provider’s list of dispatcher-tagged cloud nodes, and restores internal state accordingly.
290 10 Tom Clegg
291 36 Tom Clegg
At startup, some containers might have state=Locked. The dispatcher can't be sure these have no corresponding crunch-run process anywhere until it establishes communication with all running instances. To avoid breaking priority order by guessing wrong, the dispatcher avoids scheduling any new containers until all such "stale-locked" containers are matched up with crunch-run processes on existing VMs (typically preparing a docker image) or all of the existing VMs have been probed successfully (meaning the locked containers aren't running anywhere and need to be rescheduled).
292
293 37 Tom Clegg
At startup, some instances might still be running containers that were started by a prior invocation, even though the (new) boot probe command fails. Such instances are left alive at least until the containers finish. After that, the usual rules apply: if boot probe succeeds before boot timeout, start scheduling containers; otherwise, shut down. This allows the operator to configure a new image along with a new boot probe command that only works on the new image, without disrupting users' work.
294 1 Tom Clegg
295 4 Peter Amstutz
When a user cancels a container request with state=Locked or Running, the container priority changes to 0. On its next poll, the dispatcher notices this and kills any corresponding crunch-run processes (or, if there is no such process, just unlocks the container).
296 6 Tom Clegg
297
When a crunch-run process ends without finalizing its container's state, the dispatcher notices this and sets state to Cancelled.
298 4 Peter Amstutz
299 5 Peter Amstutz
h3. Probes
300
301
Sometimes (on the happy path) the dispatcher knows the state of each worker, whether it's idle, and which container it's running. In general, it's necessary to probe the worker node itself.
302
303
Probe:
304
* Check whether the SSH connection is alive; reopen if needed.
305
* Run the configured "ready?" command (e.g., "grep /encrypted-tmp /etc/mtab"); if this fails, conclude the node is still booting.
306
* Run "crunch-run --list" to get a list of crunch-run supervisors (pid + container UUID)
307 6 Tom Clegg
308 5 Peter Amstutz
h3. Detecting dead/lame nodes
309 10 Tom Clegg
310 28 Tom Clegg
If a node has been up for N seconds without a successful probe, despite at least M attempts, it is shut down, even if it was running a container last time it was contacted successfully.
311
312
h1. Future plans / features
313
314
Per-instance-type VM images: It can be useful to run differently configured/tuned kernels/systems on different instance types, use different ops/monitoring systems on preemptible instances, etc. In addition to a system-wide default, each instance type could optionally specify an image.
315
316 1 Tom Clegg
Selectable VM images: When upgrading a production system, it can be useful to run a few trial containers on a new VM image before making it the default.