Project

General

Profile

Dispatching containers to cloud VMs » History » Version 11

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