Skip to content

cml-runner: Add an option to reuse only idle runners #575

Closed
iterative/cml.dev
#263

Description

@courentin

Today, the --reuse option of cml-runner does not care if the runner is in use or not.
While it is convenient when multiple jobs can be run on the same runner, some job needs a dedicated runner to work (jobs that take the runner resources).

However, we could benefit from runner reusability for this kind of job by introducing a --reuse-idle option to the runner. This option would reuse a runner only if it is idle (option naming to be challenged).

Activity

  1. courentin commented on Jun 4, 2021

    @courentin
    ContributorAuthor

    Implementation notes:

    Github

    Github returns an is_busy boolean that is false when the runner is idle (see the doc).
    We can pass is_idle in opts and filter runners depending on this value, here:

    cml/src/drivers/github.js

    Lines 233 to 245 in 75866d1

    async runnersByLabels(opts = {}) {
    const { labels } = opts;
    const runners = await this.getRunners(opts);
    return runners
    .filter((runner) =>
    labels
    .split(',')
    .every((label) =>
    runner.labels.map(({ name }) => name).includes(label)
    )
    )
    .map((runner) => ({ id: runner.id, name: runner.name }));
    }

    Gitlab

    I wasn't able to test it on gitlab but they seem to have an active field (see the doc).

    However I was not able to see the signification of this active, can someone with a gitlab repo and runner setup help me to make sure this field checks runner idle-ness, maybe @DavidGOrtega ?

  2. added
    cml-runner
    enhancement
    on Jun 4, 2021
  3. 0x2b3bfa0 commented on Jun 4, 2021

    @0x2b3bfa0
    Member

    Thank you very much, @courentin! This could be a nice way for cml-runner to expedite runs triggered with --reuse runners.

    What would happen if the runner accepts another task between the idleness check and the task creation?

  4. courentin commented on Jun 4, 2021

    @courentin
    ContributorAuthor

    I haven't thought about it, it will have the same behaviour than --reuse in this case.
    Not sure if we can avoid this?

  5. 0x2b3bfa0 commented on Jun 4, 2021

    @0x2b3bfa0
    Member

    So true, we already face this possible race condition. I guess that it would be a minor issue to live with: the worst case would imply feeding a single runner with two tasks serially.

  6. DavidGOrtega commented on Jun 8, 2021

    @DavidGOrtega
    Contributor

    As I stated runners takes jobs, thats it. So when we launch a workflow that launches one machine and we have already a runner with those tags what will happen is that the job will be taken by any of the runners, thats why we cleanup runners after idle. One of the runners will remain idle until idle-timeout happens and the other will reach the same fatal destiny after completing the job and idle-timeout happens 😈

  7. DavidGOrtega commented on Jun 8, 2021

    @DavidGOrtega
    Contributor

    We also have the option --single

  8. dacbd commented on May 12, 2022

    @dacbd
    Contributor

    I don't fully understand what is being proposed here so feel free to re-open.

    GitHub Actions will only distribute a job to a runner if it is idle, to run multiple jobs on a single instance you would need to register multiple runners as different independent services on the instance.

    the --single flag will ensure that only a job is run. w/o this instance will continue to pick jobs matching its provided labels until the idle timeout is reached, after which it will self-terminate.

  9. casperdcl commented on May 31, 2022

    @casperdcl
    Contributor

    use case explanation:

    1. cml runner --labels=xyz --single: con: often have to wait 5min+ to provision
    2. cml runner --labels=xyz --reuse: con: no parallel jobs (queue waiting for one runner)
    3. cml runner --labels=xyz --reuse-idle: this feature request: no need to wait to provision iff another job has just completed (so an idle runner is available)
  10. dacbd commented on Jun 3, 2022

    @dacbd
    Contributor

    So with --reuse-idle if:

    1. a runner is registered with that label
    2. that runner is idle

    cml runner exits so the dependant job can get picked up without creating a new instance,

  11. casperdcl commented on Jun 6, 2022

    @casperdcl
    Contributor
    1. a job is submitted & launches a runner (no --single)
    2. job finishes, runner waits for more jobs (upto idle_timeout)
    3. 10 jobs are submitted before idle_timeout is triggered. 1 job gets assigned the existing runner above, the remaining 9 jobs launch their own runners

    -- @casperdcl in #1025 (comment)

    Seems very reasonable, so cml runner should try to check for an existing one if present exit successfully so the dependant job can get picked up. Though this is dangerous territory for a race condition.

    I could see: 10 jobs get rapidly spawned, and there is 1 runner idle. The 10 jobs all do their check for idle runner and see one, so no new runner is created, a few seconds later, our existing runner has its new job but we have 9 waiting in the queue for that same runner.

    -- @dacbd in #1025 (comment)

  12. added a commit that references this issue on Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cml-runnerenhancementexternal-request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions