Removing Azure workers takes 10-30 minutes and still accepts jobs during this time
When executing taskcluster api workerManager removeWorker on an Azure worker, it appears to only be removed after 10-30 minutes and during this time it still takes jobs.
On AWS per what I was told, this only takes around 5 minutes.
Also during out meeting we mentioned updating the jobs, these are the jobs right now when running --help with the above command:
Remove a Worker
Method: delete
Path: /workers/<workerPoolId>/<workerGroup>/<workerId>
Stability: stable
JSON Input: no
Remove an existing worker. The precise behavior of this method depends
on the provider implementing the given worker. Some providers
do not support removing workers at all, and will return a 400 error.
Others may begin removing the worker, but it may remain available via
the API (perhaps even in state RUNNING) afterward.
The removeWorker method: https://github.com/taskcluster/taskcluster/blob/95026102bfc716e10c18fa83d2e0144639c542e7/services/worker-manager/src/providers/azure/index.js#L1273-L1281 just records the removal in the DB (by putting the worker in state STOPPING). Then https://github.com/taskcluster/taskcluster/blob/95026102bfc716e10c18fa83d2e0144639c542e7/services/worker-manager/src/providers/azure/index.js#L1031-L1034 starts to deprovision resourcs from the worker on the next run of the worker scanner. Depending on how loaded the worker manager is, it may take a while to get around to that point. If I recall, Azure is very slow to respond to API requests, so this may explain the 10-30 minutes. The deprovisionResource method then begins by trying to delete the VM: https://github.com/taskcluster/taskcluster/blob/95026102bfc716e10c18fa83d2e0144639c542e7/services/worker-manager/src/providers/azure/index.js#L1284-L1306 The deprovisioning process pretty much calls delete: https://github.com/taskcluster/taskcluster/blob/95026102bfc716e10c18fa83d2e0144639c542e7/services/worker-manager/src/providers/azure/index.js#L1239-L1242 which then takes a while to actually occur.
For a bit of context as thoughts are developed about how to handle this better -- there have been several attempts at this general problem of handling workers efficiently. It's not easy!
- Users expect TC to
- respond to changes in instance state quickly
- respond to API requests quickly
- respond to changes in demand quickly (spin up new hosts)
- prioritize "high-impact" changes, such as creating a worker in a pool that currently has zero workers, rather than creating one more worker in a pool with 5000 running workers
- not "leak" resources (including disks, nics, and IPs in Azure)
- All clouds have pretty draconian API limits, and for example polling for instance status tends to hit those limits
- All of this is
- distributed -- there's lots of room for races between, say, deleting a VM in one process while another process is trying to create it
- asynchronous -- cloud API operations take a long time, either in a tens-of-seconds HTTP request or (with Azure for instance) by creating an operation and then polling for its completion
- fault-tolerant -- cloud APIs fail constantly (especially AWS -- EC2's 500 rate is really high) and it's rarely clear if a failure is a permanent problem or should just be retried
The main attempts to solve this were
- aws-provisioner (AWS only) - https://github.com/taskcluster/aws-provisioner (which originally did not use ec2-manager)
- ec2-manager (AWS only) - https://github.com/taskcluster/ec2-manager
- worker-manager
thank you @djmitche for detailed explanation. This seems to be a very tricky issue
Apart from the fact that it takes some time to stop and deprovision resources, we could change queue behaviour - it is checking at the moment if worker is quarantined or not.
We can also check if worker state is Running at the time we hand out task to it.
Alternatively we tried in the past to quarantine workers upon removal #6267 but later reverted it in #6275 as we were aiming to reduce claim-expired errors which didn't give desired results