Container dispatch » History » Version 24
Tom Clegg, 06/15/2016 02:10 PM
1 | 16 | Tom Clegg | h1. Container dispatch |
---|---|---|---|
2 | 2 | Peter Amstutz | |
3 | 15 | Tom Clegg | {{toc}} |
4 | 9 | Peter Amstutz | |
5 | 15 | Tom Clegg | h2. Summary |
6 | 1 | Peter Amstutz | |
7 | 15 | Tom Clegg | A dispatcher uses available compute resources to execute queued containers. |
8 | 1 | Peter Amstutz | |
9 | 15 | Tom Clegg | Dispatch is meant to be a small simple component rather than a pluggable framework: e.g., "slurm dispatch" can be a small standalone program, rather than a plugin for a big generic dispatch program. |
10 | 12 | Peter Amstutz | |
11 | 15 | Tom Clegg | h2. Pseudocode |
12 | 1 | Peter Amstutz | |
13 | 15 | Tom Clegg | * Notice there is a queued container |
14 | * Decide whether the required resources are available to run the container |
||
15 | * Lock the container (this avoids races with other dispatch processes) |
||
16 | * Translate the container's runtime constraints and priority to instructions for the lower-level scheduler, if any |
||
17 | * Invoke the "crunch2 run" executor |
||
18 | * When the priority changes on a container taken by this dispatch process, update the lower-level scheduler accordingly (cancel if priority is zero) |
||
19 | * If the lower-level scheduler indicates the container is finished or abandoned, but the Container record is locked by this dispatcher and has state=Running, fail the container |
||
20 | 1 | Peter Amstutz | |
21 | 15 | Tom Clegg | h2. Examples |
22 | 1 | Peter Amstutz | |
23 | 15 | Tom Clegg | slurm batch mode |
24 | * Use "sinfo" to determine whether it is possible to run the container |
||
25 | * Submit a batch job to the queue: "echo crunch-run --job {uuid} | sbatch -N1" |
||
26 | * When container priority changes, use scontrol and scancel to propagate changes to slurm |
||
27 | * Use strigger to run a cleanup script when a container exits |
||
28 | 2 | Peter Amstutz | |
29 | 15 | Tom Clegg | standalone worker |
30 | * Inspect /proc/meminfo, /proc/cpuinfo, "docker ps", etc. to determine local capacity |
||
31 | * Invoke crunch-run as a child process (or perhaps a detached daemon process) |
||
32 | * Signal crunch-run to stop if container priority changes to zero |
||
33 | 2 | Peter Amstutz | |
34 | 23 | Tom Clegg | h2. Locking |
35 | |||
36 | At a given moment, there should be (at most) one process responsible for running a given container, and that process should be the only one updating the database record. |
||
37 | |||
38 | Certain common scenarios threaten to disrupt this: |
||
39 | # Two dispatch processes are running. They both notice a queued container, and they both decide to run it. |
||
40 | 24 | Tom Clegg | # A dispatch process decides to run a container, and starts a crunch-run process (e.g., via slurm) but the dispatch service restarts while crunch-run is still running. |
41 | # A sysadmin or daemon-supervisor mishap results in two concurrent dispatch processes using the same token. This _should_ be preventable but it's still desirable to behave correctly if it happens. |
||
42 | 1 | Peter Amstutz | |
43 | 24 | Tom Clegg | The first scenario ("multiple dispatch, different tokens") is addressed by the locked_by_uuid field. |
44 | 23 | Tom Clegg | |
45 | 24 | Tom Clegg | In the second scenario ("amnesiac dispatch"): |
46 | 23 | Tom Clegg | * As long as the original crunch-run is running (or queued in slurm), the new dispatch process should leave it alone. |
47 | * If the new dispatch process knows somehow (e.g., squeue) that the original crunch-run process has stopped without moving the container record out of Running state, it should clean up the container record accordingly. |
||
48 | 1 | Peter Amstutz | * If the new dispatch process makes a mistake here, and tries to clean up the container record while crunch-run is still alive, _one of them must lose:_ If the cleanup transaction is successful, all of crunch-run's subsequent transactions must fail. |
49 | ** If state=Running then cleanup will change state to Cancelled, which itself ensures subsequent transactions will fail. |
||
50 | ** If state=Locked then cleanup will change state to Queued, and the new dispatch process might use the same dispatch token to take it off the queue and change state to Locked. An additional locking mechanism is needed here. |
||
51 | 24 | Tom Clegg | |
52 | In the third scenario ("multiple dispatch, same token"): |
||
53 | * If both processes acquire the lock by doing an "update" transaction with state=Locked, using the same token, then after a race both will think they succeeded: the loser's update will look like a no-op. |
||
54 | * Solution 1: Use an explicit "lock" API. |
||
55 | * Solution 2: Use an If-Match HTTP header when updating with intent to acquire a lock. |
||
56 | |||
57 | 23 | Tom Clegg | |
58 | 15 | Tom Clegg | h2. Arvados API support |
59 | 2 | Peter Amstutz | |
60 | 15 | Tom Clegg | Each dispatch process has an Arvados API token that allows it to see queued containers. |
61 | * No two dispatch processes can run at the same time with the same token. One way to achieve this is to make a user record for each dispatch service. |
||
62 | 2 | Peter Amstutz | |
63 | 15 | Tom Clegg | Container APIs relevant to a dispatch program: |
64 | * List Queued containers (might be a subset of Queued containers) |
||
65 | * List containers with state=Locked or state=Running associated with current token |
||
66 | 18 | Tom Clegg | ** arvados.v1.containers.current (equivalent to @filters=[["dispatch_auth_uuid","=",current_client_auth.uuid]]@) |
67 | 15 | Tom Clegg | * Receive event when container is created or modified and state is Queued (it might become runnable) |
68 | * Change state Queued->Locked |
||
69 | * Change state Locked->Queued |
||
70 | * Change state Locked->Running |
||
71 | * Change state Running->Complete |
||
72 | * Receive event when priority changes |
||
73 | 1 | Peter Amstutz | * Receive event when state changes to Complete |
74 | 18 | Tom Clegg | * Retrieve an API token to pass into the container and its arv-mount process (via crunch-run) |
75 | ** Token is automatically created/assigned when container state changes to Locked |
||
76 | ** Token is automatically expired/destroyed when container state changes away from Running |
||
77 | 19 | Tom Clegg | ** arvados.v1.containers.container_auth(uuid=container.uuid) → returns an api_client_authorization record |
78 | 15 | Tom Clegg | * Create events/logs |
79 | 22 | Tom Clegg | ** Decided to run this container |
80 | ** Decided not to run this container (e.g., no node with those resources) |
||
81 | 15 | Tom Clegg | ** Lock failed |
82 | ** Dispatched to crunch-run |
||
83 | ** Cleaned up crashed crunch-run (lower-level scheduler indicates the job finished, but crunch-run didn't leave the container in a final state) |
||
84 | ** Cleaned up abandoned container (container belongs to this process, but dispatch and lower-level scheduler don't know about it) |
||
85 | 6 | Peter Amstutz | |
86 | 15 | Tom Clegg | h2. Non-responsibilities |
87 | 6 | Peter Amstutz | |
88 | 15 | Tom Clegg | Dispatch doesn't retry failed containers. If something needs to be reattempted, a new container will appear in the queue. |
89 | 7 | Peter Amstutz | |
90 | 15 | Tom Clegg | Dispatch doesn't fail a container that it can't run. It doesn't know whether other dispatchers will be able to run it. |
91 | 8 | Peter Amstutz | |
92 | 15 | Tom Clegg | h2. Additional notes |
93 | 8 | Peter Amstutz | |
94 | 17 | Tom Clegg | (see also #6429 and #6518 and #8028) |
95 | 8 | Peter Amstutz | |
96 | 15 | Tom Clegg | Using websockets to listen for container events (new containers added, priority changes) will benefit from some Go SDK support. |
97 | 20 | Peter Amstutz | |
98 | h2. Cloud Container Services |
||
99 | |||
100 | Cloud providers now offer container execution services. However, rather than being just an API to run containers (similar to Crunch) these take the form of preconfigured clusters set up with a container orchestration system. |
||
101 | |||
102 | AWS offers Elastic Container Service. It appears that the leader runs on AWS infrastructure (?) and you spin up worker VMs which run the ECS Agent: https://github.com/aws/amazon-ecs-agent |
||
103 | |||
104 | 21 | Peter Amstutz | Google Container Engine provides a preconfigured Kubernetes cluster. https://cloud.google.com/container-engine/docs/clusters/operations |
105 | 20 | Peter Amstutz | |
106 | 21 | Peter Amstutz | Azure provides a preconfigured Mesos or Docker Swarm cluster. https://azure.microsoft.com/en-us/services/container-service/?WT.mc_id=azurebg_email_Trans_1083_Tier2_Release_MOSP |