Adjust the Drydock allocator to limit each pending lease to one allocating resource
commit62360ea406890db9b1a908e2b387326a4e0214fd
authorepriestley <git@epriestley.com>
Mon, 9 May 2022 17:03:59 +0000 (9 10:03 -0700)
committerepriestley <git@epriestley.com>
Mon, 9 May 2022 17:40:08 +0000 (9 10:40 -0700)
tree45cb642d0a05094ca00d3901efe2d82fbc2a3c4d
parent13a37282bcb30fe5caa612881ed7a1d6c3f6e509
Adjust the Drydock allocator to limit each pending lease to one allocating resource

Summary:
Ref T13677. Currently, one lease may cause multiple resources to allocate simultaneously if it starts allocating one, then wakes up from a yield later on and still sees no available resources.

This is never desired -- or, at least, produces desirable behavior only entirely by accident. Normally, it causes an excess of resources to allocate.

This is not a catastrophic problem: the extra resources usually get used sooner or later or cleaned up; and the total amount of badness is limited by overall resource allocation limits.

However, this behavior is also suppressed by an artificial "25% of current pool size" growth limit throttle which I intend to remove. Removing this throttle without fixing the allocator behavior could make this "too many resources" problem worse.

Change the allocator so that a lease that has started allocating a resource won't allocate another resource until the first resource leaves the "pending" state.

This also fixes some general oddness with the allocator and attempts to simplify the structure.

Test Plan:
  - Ran 8 taskmasters.
  - Destroyed all resources and leases.
  - Leased 4 working copies.
    - Saw exactly 4 resources build and lease, all simultaneously.
  - Destroyed all resources and leases.
  - Leased 32 working copies.
    - Saw exactly 32 resources build and lease, approximately 8 at a time (limited by taskmasters).
  - Destroyed all leases (but not resources).
  - Leased 32 working copies, saw them  satisfied by existing resources.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13677

Differential Revision: https://secure.phabricator.com/D21807
src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
src/applications/drydock/worker/DrydockWorker.php