Project

General

Profile

Dispatching containers to cloud VMs » History » Version 23

Tom Clegg, 10/16/2018 08:45 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 12 Tom Clegg
h2. Deployment
12
13 21 Tom Clegg
*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 (future versions will support multiple dispatchers).
14
15
*SSH key:* The installer must generate an SSH private key, with no passphrase, for the dispatcher to use when connecting to cloud VMs. The private key is stored in the cluster configuration file. It does not need to be saved in @~/.ssh/@.
16
17
*Cloud VM image:* The installer must provide a VM image with an SSH server on port 22, reachable by the dispatcher. 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. _(Alternatively, it is possible to install these using a custom boot probe command, but pre-installing is more efficient.)_
18 22 Tom Clegg
* (Future) Configurable SSH port number.
19
* (Future) Automatically sync the crunch-run binary from the dispatcher host to each worker node.
20 12 Tom Clegg
21 23 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 installer must ensure the cloud provider itself is enforcing a suitable quota.
22
23 9 Tom Clegg
h2. Overview of operation
24 1 Tom Clegg
25 9 Tom Clegg
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.
26 1 Tom Clegg
27 6 Tom Clegg
h2. Interaction with other components
28 1 Tom Clegg
29 9 Tom Clegg
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.
30 1 Tom Clegg
31 6 Tom Clegg
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.
32 1 Tom Clegg
33 6 Tom Clegg
The SSH server on each cloud VM allows the dispatcher to authenticate with a private key and execute shell commands as root.
34 1 Tom Clegg
35 6 Tom Clegg
h2. Configuration
36 1 Tom Clegg
37 6 Tom Clegg
Arvados configuration (currently a file in /etc) supplies cloud provider credentials, allowed node types, spending limits/policies, etc.
38 1 Tom Clegg
39 6 Tom Clegg
<pre><code class="yaml">
40
    CloudVMs:
41 8 Tom Clegg
      BootProbeCommand: "docker ps -q"
42
      SyncInterval: 1m    # get list of 
43
      TimeoutIdle: 1m     # shutdown if idle longer than this
44
      TimeoutBooting: 10m # shutdown if exists longer than this without running BootProbeCommand successfully
45
      TimeoutProbe: 2m    # shutdown if (after booting) communication fails longer than this, even if ctrs are running
46
      TimeoutShutdown: 1m # shutdown again if node still exists this long after shutdown
47 6 Tom Clegg
      Driver: Amazon
48 8 Tom Clegg
      DriverParameters:   # following configs are driver dependent
49 6 Tom Clegg
        Region: us-east-1
50
        APITimeout: 20s
51
        EC2Key: abcdef
52
        EC2Secret: abcdefghijklmnopqrstuvwxyz
53
        StorageKey: abcdef
54
        StorageSecret: abcdefghijklmnopqrstuvwxyz
55
        ImageID: ami-0123456789abcdef0
56 1 Tom Clegg
        SubnetID: subnet-01234567
57
        SecurityGroups: sg-01234567
58 8 Tom Clegg
    Dispatch:
59
      StaleLockTimeout: 1m     # after restart, time to wait for workers to come up before abandoning locks from previous run
60
      PollInterval: 1m         # how often to get latest queue from arvados controller
61
      ProbeInterval: 10s       # how often to probe each instance for current status/vital signs
62
      MaxProbesPerSecond: 1000 # limit total probe rate for dispatch process (across all instances)
63
      PrivateKey: |            # SSH key able to log in as root@ worker VMs
64
        -----BEGIN RSA PRIVATE KEY-----
65
        MIIEowIBAAKCAQEAqYm4XsQHm8sBSZFwUX5VeW1OkGsfoNzcGPG2nzzYRhNhClYZ
66
        0ABHhUk82HkaC/8l6d/jpYTf42HrK42nNQ0r0Yzs7qw8yZMQioK4Yk+kFyVLF78E
67
        GRG4pGAWXFs6pUchs/lm8fo9zcda4R3XeqgI+NO+nEERXmdRJa1FhI+Za3/S/+CV
68
        mg+6O00wZz2+vKmDPptGN4MCKmQOCKsMJts7wSZGyVcTtdNv7jjfr6yPAIOIL8X7
69
        LtarBCFaK/pD7uWll/Uj7h7D8K48nIZUrvBJJjXL8Sm4LxCNoz3Z83k8J5ZzuDRD
70
        gRiQe/C085mhO6VL+2fypDLwcKt1tOL8fI81MwIDAQABAoIBACR3tEnmHsDbNOav
71
        Oxq8cwRQh9K2yDHg8BMJgz/TZa4FIx2HEbxVIw0/iLADtJ+Z/XzGJQCIiWQuvtg6
72
        exoFQESt7JUWRWkSkj9JCQJUoTY9Vl7APtBpqG7rIEQzd3TvzQcagZNRQZQO6rR7
73
        p8sBdBSZ72lK8cJ9tM3G7Kor/VNK7KgRZFNhEWnmvEa3qMd4hzDcQ4faOn7C9NZK
74
        dwJAuJVVfwOLlOORYcyEkvksLaDOK2DsB/p0AaCpfSmThRbBKN5fPXYaKgUdfp3w
75
        70Hpp27WWymb1cgjyqSH3DY+V/kvid+5QxgxCBRq865jPLn3FFT9bWEVS/0wvJRj
76
        iMIRrjECgYEA4Ffv9rBJXqVXonNQbbstd2PaprJDXMUy9/UmfHL6pkq1xdBeuM7v
77
        yf2ocXheA8AahHtIOhtgKqwv/aRhVK0ErYtiSvIk+tXG+dAtj/1ZAKbKiFyxjkZV
78
        X72BH7cTlR6As5SRRfWM/HaBGEgED391gKsI5PyMdqWWdczT5KfxAksCgYEAwXYE
79
        ewPmV1GaR5fbh2RupoPnUJPMj36gJCnwls7sGaXDQIpdlq56zfKgrLocGXGgj+8f
80
        QH7FHTJQO15YCYebtsXWwB3++iG43gVlJlecPAydsap2CCshqNWC5JU5pan0QzsP
81
        exzNzWqfUPSbTkR2SRaN+MenZo2Y/WqScOAth7kCgYBgVoLujW9EXH5QfXJpXLq+
82
        jTvE38I7oVcs0bJwOLPYGzcJtlwmwn6IYAwohgbhV2pLv+EZSs42JPEK278MLKxY
83
        lgVkp60npgunFTWroqDIvdc1TZDVxvA8h9VeODEJlSqxczgbMcIUXBM9yRctTI+5
84
        7DiKlMUA4kTFW2sWwuOlFwKBgGXvrYS0FVbFJKm8lmvMu5D5x5RpjEu/yNnFT4Pn
85
        G/iXoz4Kqi2PWh3STl804UF24cd1k94D7hDoReZCW9kJnz67F+C67XMW+bXi2d1O
86
        JIBvlVfcHb1IHMA9YG7ZQjrMRmx2Xj3ce4RVPgUGHh8ra7gvLjd72/Tpf0doNClN
87
        ti/hAoGBAMW5D3LhU05LXWmOqpeT4VDgqk4MrTBcstVe7KdVjwzHrVHCAmI927vI
88 1 Tom Clegg
        pjpphWzpC9m3x4OsTNf8m+g6H7f3IiQS0aiFNtduXYlcuT5FHS2fSATTzg5PBon9
89
        1E6BudOve+WyFyBs7hFWAqWFBdWujAl4Qk5Ek09U2ilFEPE7RTgJ
90
        -----END RSA PRIVATE KEY-----
91 9 Tom Clegg
    InstanceTypes:
92
    - Name: m4.large
93
      VCPUs: 2
94
      RAM: 7782000000
95
      Scratch: 32000000000
96
      Price: 0.1
97
    - Name: m4.large.spot
98
      Preemptible: true
99
      VCPUs: 2
100
      RAM: 7782000000
101
      Scratch: 32000000000
102
      Price: 0.1
103
    - Name: m4.xlarge
104
      VCPUs: 4
105
      RAM: 15564000000
106
      Scratch: 80000000000
107
      Price: 0.2
108
    - Name: m4.xlarge.spot
109
      Preemptible: true
110
      VCPUs: 4
111
      RAM: 15564000000
112
      Scratch: 80000000000
113
      Price: 0.2
114
    - Name: m4.2xlarge
115
      VCPUs: 8
116
      RAM: 31129000000
117
      Scratch: 160000000000
118
      Price: 0.4
119
    - Name: m4.2xlarge.spot
120
      Preemptible: true
121
      VCPUs: 8
122
      RAM: 31129000000
123
      Scratch: 160000000000
124
      Price: 0.4
125 6 Tom Clegg
</code></pre>
126 1 Tom Clegg
127 10 Tom Clegg
h2. Management API
128 1 Tom Clegg
129 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}".
130
131
Responses are JSON-encoded and resemble other Arvados APIs:
132
<pre><code class="json">
133
{
134
  "Items": [
135
    {
136
      "Name": "...",
137
      ...
138
    },
139
    ...
140
  ]
141
}
142
</code></pre>
143
144
@GET /arvados/v1/dispatch/instances@ lists cloud VMs. Each returned item includes:
145
* provider's instance ID
146
* hourly price (from configuration file)
147
* instance type (from configuration file)
148
* instance type (from provider's menu)
149
* UUID of the current / most recent container attempted (if known)
150
* time last container finished (or boot time, if nothing run yet)
151
152
@GET /arvados/v1/dispatch/containers@ lists queued/locked/running containers. Each returned item includes:
153
* container UUID
154
* container state (Queued/Locked/Running/Complete/Cancelled)
155
* desired instance type
156
* time appeared in queue
157
* time started (if started)
158
159
@POST /arvados/v1/dispatch/instances/:instance_id/drain@ puts an instance in "drain" state.
160
* if the instance is currently running a container, it is allowed to continue
161
* no further containers will be scheduled on the instance
162
* (TBD) the instance will not be shut down automatically
163
164
@POST /arvados/v1/dispatch/instances/:instance_id/shutdown@ puts an instance in "shutdown" state.
165
* if the instance is currently running a container, the instance is shut down when the container finishes
166
* otherwise, the instance is shut down immediately
167
168
h2. Metrics
169
170 13 Tom Clegg
Metrics are available via HTTP on a configurable address/port (conventionally :9005). Request headers must include "Authorization: Bearer {management token}".
171 10 Tom Clegg
172
Metrics include:
173 13 Tom Clegg
* [future] (summary) time elapsed between VM creation and first successful SSH connection to that VM
174
* [future] (summary) time elapsed between first successful SSH connection on a VM and ready to run a container on that VM
175 10 Tom Clegg
* (gauge) total hourly price of all existing VMs
176
* (gauge) total VCPUs and memory allocated to containers
177 1 Tom Clegg
* (gauge) number of containers running
178 10 Tom Clegg
* (gauge) number of containers allocated to VMs but not started yet (because VMs are pending/booting)
179
* (gauge) number of containers not allocated to VMs (because provider quota is reached)
180 13 Tom Clegg
181 14 Tom Clegg
h2. Logs
182
183 20 Tom Clegg
For purposes of troubleshooting, a JSON-formatted log entry is printed on stderr when...
184 16 Tom Clegg
185 20 Tom Clegg
|                                                              |...including timestamp and...|
186 16 Tom Clegg
|a new instance is created/ordered                             |instance type name|
187
|an instance appears on the provider's list of instances       |instance ID|
188
|an instance's boot probe succeeds                             |instance ID|
189
|an instance is shut down after boot timeout                   |instance ID, stdout/stderr/error from last boot probe attempt|
190
|an instance shutdown is requested                             |instance ID|
191
|an instance disappears from the provider's list of instances  |instance ID and previous state (booting/idle/shutdown)|
192
|a cloud provider API or driver error occurs                   |provider/driver's error message|
193
|a new container appears in the Arvados queue                  |container UUID, desired instance type name|
194
|a container is locked by the dispatcher                       |container UUID|
195
|a crunch-run process is started on an instance                |container UUID, instance ID, crunch-run PID|
196
|a crunch-run process fails to start on an instance            |container UUID, instance ID, stdout/stderr/exitcode|
197
|a crunch-run process ends                                     |container UUID, instance ID|
198
|an active container's state changes to Complete or Cancelled  |container UUID, new state|
199
|an active container is requeued after being locked            |container UUID|  
200
|an Arvados API error occurs                                   |error message|
201
202 14 Tom Clegg
203
(Example log entries should be shown here)
204
205
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.
206 10 Tom Clegg
207
h2. Internal details
208
209
h3. Scheduling policy
210
211 6 Tom Clegg
The container priority field determines the order in which resources are allocated.
212
* If container C1 has priority P1,
213
* ...and C2 has higher priority P2,
214
* ...and there is no pending/booting/idle VM suitable for running C2,
215
* ...then C1 will not be started.
216
217
However, containers that run on different VM types don't necessarily start in priority order.
218 1 Tom Clegg
* If container C1 has priority P1,
219
* ...and C2 has higher priority P2,
220 5 Peter Amstutz
* ...and there is no idle VM suitable for running C2,
221 6 Tom Clegg
* ...and there is a pending/booting VM that will be suitable for running C2 when it comes up,
222
* ...and there is an idle VM suitable for running C1,
223 1 Tom Clegg
* ...then C1 will start before C2.
224 6 Tom Clegg
225 10 Tom Clegg
h3. Special cases / synchronizing state
226 1 Tom Clegg
227 6 Tom Clegg
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.
228
229 10 Tom Clegg
Some containers might have state=Locked at startup. 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).
230 6 Tom Clegg
231 1 Tom Clegg
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).
232 4 Peter Amstutz
233 6 Tom Clegg
When a crunch-run process ends without finalizing its container's state, the dispatcher notices this and sets state to Cancelled.
234
235 10 Tom Clegg
h3. SSH keys
236 5 Peter Amstutz
237 10 Tom Clegg
The operator must install a public key in /root/.ssh/authorized_keys on each worker node. Dispatcher has the corresponding private key.
238 5 Peter Amstutz
239 6 Tom Clegg
(Future) Dispatcher generates its own keys and installs its public key on new VMs using cloud provider bootstrapping/metadata features.
240 4 Peter Amstutz
241
h3. Probes
242 5 Peter Amstutz
243
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.
244
245
Probe:
246
* Check whether the SSH connection is alive; reopen if needed.
247
* Run the configured "ready?" command (e.g., "grep /encrypted-tmp /etc/mtab"); if this fails, conclude the node is still booting.
248
* Run "crunch-run --list" to get a list of crunch-run supervisors (pid + container UUID)
249
250 6 Tom Clegg
h3. Detecting dead/lame nodes
251 5 Peter Amstutz
252 10 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.
253 5 Peter Amstutz
254 6 Tom Clegg
h3. Multiple dispatchers
255 5 Peter Amstutz
256 6 Tom Clegg
Not supported in initial version.