https://dev.arvados.org/https://dev.arvados.org/favicon.ico?15576888422016-05-11T19:05:46ZArvadosArvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=389882016-05-11T19:05:46ZBrett Smithbrett.smith@curii.com
<ul><li><strong>Target version</strong> set to <i>Arvados Future Sprints</i></li></ul> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=389902016-05-11T19:07:08ZTom Cleggtom@curii.com
<ul></ul>See <a class="issue tracker-2 status-3 priority-4 priority-default closed parent" title="Feature: [Crunch2] API support for crunch-dispatch (Resolved)" href="https://dev.arvados.org/issues/8128">#8128</a>
<ul>
<li>Dispatchers should honor priority list: "order by priority DESC, modified_at ASC" </li>
<li>Also filter priority > 0</li>
<li>Slurm dispatcher should pass priority on sbatch command line, --priority=<value></li>
<li>Slurm dispatcher, when claiming a Locked container previously owned by itself, should check squeue to make sure the slurm job still exists, clean up record if not.</li>
<li>crunch-run needs to get the container auth, and pass that (instead of its own dispatch token) into the container env and arv-mount</li>
<li>changing state to Running should happen in crunch-run, not crunch-dispatch.</li>
</ul> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=390092016-05-11T19:23:31ZPeter Amstutzpeter.amstutz@curii.com
<ul><li><strong>Target version</strong> changed from <i>Arvados Future Sprints</i> to <i>2016-05-25 sprint</i></li></ul> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=390122016-05-11T19:24:08ZPeter Amstutzpeter.amstutz@curii.com
<ul><li><strong>Category</strong> set to <i>Crunch</i></li><li><strong>Assigned To</strong> set to <i>Peter Amstutz</i></li><li><strong>Story points</strong> set to <i>2.0</i></li></ul> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=393882016-05-25T16:19:27ZTom Cleggtom@curii.com
<ul></ul><p>Still need: "Slurm dispatcher should pass priority on sbatch command line, --priority=<value>"</p>
<p>Still need: "Slurm dispatcher, when claiming a Locked container previously owned by itself, should check squeue to make sure the slurm job still exists, clean up record if not."</p>
<p>dispatch.go</p>
<p>"XXX needs to handle paging" ... for now, maybe we should at least log something if <code>items_available>len(items)</code>? use limit=1000?</p>
<p>pollContainers() calls dispatcher.getContainers() to get updated state for containers that are "mine" but (according to the "locked_by_uuid" query) aren't locked by us. (Would something like "notReallyMine" be a more precise name for this "monitored" slice?) If I'm following correctly, a container that is now locked by a different dispatcher (e.g., this dispatcher unlocked it, and a different dispatcher took it) will then end up in the "State Locked || State Running" case in handleContainers(), where we start up a new monitoring goroutine, which seems wrong.</p>
<p>Inline function in handleContainers() seems redundant, suggest:<br /><pre><code class="diff syntaxhl"><span class="gd">- go func(uuid string, ch chan Container) {
- dispatcher.monitorContainer(dispatcher, uuid, ch)
- }(container.UUID, dispatcher.setMine(container.UUID))
</span><span class="gi">+ go dispatcher.monitorContainer(dispatcher, container.UUID, dispatcher.setMine(container.UUID))
</span></code></pre></p>
<p>updateMine() needs its comment ... updated.</p>
<p>Suggest renaming "DispatcherState" to "Dispatcher".</p>
<p>Rather than mapping each Dispatcher field to a MakeDispatcher argument, we could make the caller-controlled fields public (e.g., PollInterval, RunContainer, MonitorContainer), add comments in the type definition to explain how they work, and put the private initialization stuff in RunDispatcher(). That way we can add fields without having to update all callers. So, instead of MakeDispatcher(...), callers would say</p>
<pre>
d := &Dispatcher{
RunContainer: myRunFunc,
PollInterval: time.Minute,
...,
}
d.Run()
</pre>
<p>Suggest changing "framework" / "framework struct" to "object".</p>
<p>Suggest renaming handleContainers to handleUpdates. Changing it to handleUpdate() and putting the range loop in RunDispatcher might make tests a little more convenient.</p>
<p>The monitorContainer interface seems a bit weird: it seems to mean "start a goroutine and listen on this channel for updates". Wouldn't it be easier to just send each update directly to a "handleUpdate" callback? It seems the local case would be simpler if runContainer() started a goroutine to wait for the child proc to finish (it's a bit awkward for monitorRun to do this because there isn't necessarily a process to wait for). The slurm case would just lose boilerplate.</p>
<p>crunch-dispatch-slurm.go</p>
<p>The first "container" variable here seems to be useless:<br /><pre>
var container dispatch.Container
dispatcher.Arv.Get("containers", uuid, nil, &container)
for container := range status {
</pre></p>
<p><code>dispatcher.Arv.Update("containers", ...</code> -- should this be dispatcher.UpdateState()?</p>
<p>review/update comments in crunch-dispatch-*.go on the funcs that were rewritten to use Dispatcher.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=393892016-05-25T16:22:02ZTom Cleggtom@curii.com
<ul></ul><p><del>Also still need: "crunch-run needs to get the container auth, and pass that (instead of its own dispatch token) into the container env and arv-mount"</del> oh yeah, we moved that to <a class="issue tracker-2 status-3 priority-4 priority-default closed parent" title="Feature: [Crunch2] Pass container auth token (not dispatch token) to arv-mount, and (if requested) into th... (Resolved)" href="https://dev.arvados.org/issues/9272">#9272</a></p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=393922016-05-25T17:35:48ZTom Cleggtom@curii.com
<ul></ul><p>Why is the Locked→Complete state transition allowed? This seems wrong: how can it be complete if nobody ever started running it?</p>
<p>If we somehow decide after locking that it's not possible for any dispatcher to run the container, shouldn't we call that Cancelled?</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=393942016-05-25T18:03:28ZPeter Amstutzpeter.amstutz@curii.com
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>In Progress</i></li></ul> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=394112016-05-25T18:59:33ZBrett Smithbrett.smith@curii.com
<ul><li><strong>Target version</strong> changed from <i>2016-05-25 sprint</i> to <i>2016-06-08 sprint</i></li></ul> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=394152016-05-25T19:04:52ZPeter Amstutzpeter.amstutz@curii.com
<ul></ul><p>Tom Clegg wrote:</p>
<blockquote>
<p>Why is the Locked→Complete state transition allowed? This seems wrong: how can it be complete if nobody ever started running it?</p>
</blockquote>
<blockquote>
<p>If we somehow decide after locking that it's not possible for any dispatcher to run the container, shouldn't we call that Cancelled?</p>
</blockquote>
<p>If the container was locked but then determined to be unrunnable, what should it do?</p>
<p>If the container is started, but then the system crashes and we have a ghost record in the "Locked" state, what should it do?</p>
<p>We could transition to "Cancelled", but I thought "Cancelled" means that it was cancelled intentionally when the user sets priority to 0. You're suggesting that "Cancelled" is overloaded to also mean the container was unrunnable or lost for some other reason. When we discussed it yesterday, you said that the "Complete" state with a null return code means "the container was lost or something went wrong" which is why I did changed the API server. I would vastly prefer to have an unambiguous representation with an explicit "Error" state for the above conditions.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=394182016-05-25T19:10:19ZPeter Amstutzpeter.amstutz@curii.com
<ul><li><strong>Story points</strong> changed from <i>2.0</i> to <i>1.0</i></li></ul> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=394512016-05-25T22:20:14ZTom Cleggtom@curii.com
<ul></ul><p>Peter Amstutz wrote:</p>
<blockquote>
<p>Tom Clegg wrote:</p>
<blockquote>
<p>If we somehow decide after locking that it's not possible for any dispatcher to run the container, shouldn't we call that Cancelled?</p>
</blockquote>
<p>If the container was locked but then determined to be unrunnable, what should it do?</p>
</blockquote>
<p>Set state to Cancelled. (If you mean "unrunnable by anything", that is. If you mean "_this_ dispatcher can't run it right now, possibly ever", set state to Queued.)</p>
<blockquote>
<p>If the container is started, but then the system crashes and we have a ghost record in the "Locked" state, what should it do?</p>
</blockquote>
<p>Surely it's an error to start a container without changing state to Running?</p>
<p>If the dispatcher crashes while the container is Locked, and then restarts, it should either unlock it (if it can assure itself a crunch-run process isn't still working on it -- e.g., by checking the slurm queue) or leave it alone.</p>
<p>If a container is in the Running state, but crunch-run crashes and loses its ability to track the container's progress, the container is effectively cancelled, so we should set state to Cancelled.</p>
<p>But it's really not crunch-dispatch's job to clean up abandoned containers. That has to happen higher up anyway, so we can clean up containers that are locked by crunch-dispatch processes/tokens that don't exist, for example.</p>
<blockquote>
<p>We could transition to "Cancelled", but I thought "Cancelled" means that it was cancelled intentionally when the user sets priority to 0. You're suggesting that "Cancelled" is overloaded to also mean the container was unrunnable or lost for some other reason. When we discussed it yesterday, you said that the "Complete" state with a null return code means "the container was lost or something went wrong" which is why I did changed the API server. I would vastly prefer to have an unambiguous representation with an explicit "Error" state for the above conditions.</p>
</blockquote>
<p>Sorry, I guess I misspoke. I didn't intend to creep API changes into this story.</p>
<p>I did make a distinction between "container definitely didn't start" and "container did (or maybe did) start". This is the Locked→Running distinction. If we never even got to Running state, it makes sense to put the container back in the queue and retry -- even if the user asked for retries=0 -- because we <em>know</em> it wasn't the container's own fault. Once we invoke the container, though, we shouldn't put it back in the queue: we allocated resources and ran user-provided code, so it makes sense to show the user "we ran your container on machine M, and X happened".</p>
<p>"Cancelled" means we (the infrastructure) terminated the container: it did not run to completion. ("User sets priority to zero" isn't the only case where we'd do that deliberately.)</p>
<p>The difference between Complete and Cancelled is that Complete means the container exited on its own accord. In the case of Cancelled, for purposes of using the result it doesn't much matter whether we deliberately cut it off before it had a chance to exit by itself, or we accidentally lost track of it and don't know what happened to it -- we have effectively cancelled it and can't say anything about the container's outcome (output / exit code). It doesn't make sense to reuse this result to satisfy a different container request, or even say "this program, when run on this input, is known to fail".</p>
<p>Deciding whether a failure was caused by infrastructure seems orthogonal to this distinction, and something we can deal with separately. For example, if a container exits non-zero after timing out connecting to the API server, is that an infrastructure error? I think a user would say yes, but detecting that and calling it state=Error would be hard to get right.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=394672016-05-26T20:41:43ZPeter Amstutzpeter.amstutz@curii.com
<ul></ul><p>Tom Clegg wrote:</p>
<blockquote>
<p>Still need: "Slurm dispatcher should pass priority on sbatch command line, --priority=<value>"</p>
</blockquote>
<p>Done</p>
<blockquote>
<p>Still need: "Slurm dispatcher, when claiming a Locked container previously owned by itself, should check squeue to make sure the slurm job still exists, clean up record if not."</p>
</blockquote>
<p>Done.</p>
<blockquote>
<p>dispatch.go</p>
<p>"XXX needs to handle paging" ... for now, maybe we should at least log something if <code>items_available>len(items)</code>? use limit=1000?</p>
</blockquote>
<p>Done.</p>
<blockquote>
<p>pollContainers() calls dispatcher.getContainers() to get updated state for containers that are "mine" but (according to the "locked_by_uuid" query) aren't locked by us. (Would something like "notReallyMine" be a more precise name for this "monitored" slice?) If I'm following correctly, a container that is now locked by a different dispatcher (e.g., this dispatcher unlocked it, and a different dispatcher took it) will then end up in the "State Locked || State Running" case in handleContainers(), where we start up a new monitoring goroutine, which seems wrong.</p>
</blockquote>
<p>The reason it has to do this is because when a container record goes to "Cancelled" or "Complete" state, the "locked_by_uuid" field gets set to nil (because <code>need_lock = nil</code> if the state is not Locked or Running in validate_lock of container.rb). I don't know if that was the intended behavior but that's what it does now. You're right, this could be a problem if the dispatcher put a locked container back into the queue, but that currently doesn't happen.</p>
<blockquote>
<p>updateMine() needs its comment ... updated.</p>
</blockquote>
<p>Done</p>
<blockquote>
<p>Suggest renaming "DispatcherState" to "Dispatcher".</p>
</blockquote>
<p>Done</p>
<blockquote>
<p>Rather than mapping each Dispatcher field to a MakeDispatcher argument, we could make the caller-controlled fields public (e.g., PollInterval, RunContainer, MonitorContainer), add comments in the type definition to explain how they work, and put the private initialization stuff in RunDispatcher(). That way we can add fields without having to update all callers. So, instead of MakeDispatcher(...), callers would say</p>
</blockquote>
<p>Done</p>
<blockquote>
<p>Suggest renaming handleContainers to handleUpdates. Changing it to handleUpdate() and putting the range loop in RunDispatcher might make tests a little more convenient.</p>
</blockquote>
<p>Done.</p>
<blockquote>
<p>The monitorContainer interface seems a bit weird: it seems to mean "start a goroutine and listen on this channel for updates". Wouldn't it be easier to just send each update directly to a "handleUpdate" callback? It seems the local case would be simpler if runContainer() started a goroutine to wait for the child proc to finish (it's a bit awkward for monitorRun to do this because there isn't necessarily a process to wait for). The slurm case would just lose boilerplate.</p>
</blockquote>
<p>I simplified this to a single RunContainer callback goroutine which is responsible for determining if it should execute/submit a container, monitor an existing submission, or clean up a stale record.</p>
<p>The idea to use a channel is to decouple the get containers / send updates process from the goroutines that babysit each individual container. It feels cleaner than a callback, because the goroutines have the flexibility to process status changes only when it is appropriate.</p>
<p>Now @ <a class="changeset" title="9187: Refactor dispatcher support into common library and update to use Locking API. New dispatc..." href="https://dev.arvados.org/projects/arvados/repository/arvados/revisions/4153cb6cfad920ed0b1a4b818d3bcc8de492d134">4153cb6</a></p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=394792016-05-27T14:43:38ZPeter Amstutzpeter.amstutz@curii.com
<ul></ul><blockquote>
<p>The reason it has to do this is because when a container record goes to "Cancelled" or "Complete" state, the "locked_by_uuid" field gets set to nil (because need_lock = nil if the state is not Locked or Running in validate_lock of container.rb). I don't know if that was the intended behavior but that's what it does now. You're right, this could be a problem if the dispatcher put a locked container back into the queue, but that currently doesn't happen.</p>
</blockquote>
<p>I see from your comments on <a class="issue tracker-2 status-3 priority-4 priority-default closed parent" title="Feature: [Crunch2] Pass container auth token (not dispatch token) to arv-mount, and (if requested) into th... (Resolved)" href="https://dev.arvados.org/issues/9272">#9272</a>, that putting a locked container back to "queued" can happen now.</p>
<p>On further consideration, I think the logic just needs to be tweaked to something like "if locked_by_uuid is nil and container is complete or cancelled or queued then release it"</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=394902016-05-27T21:01:44ZTom Cleggtom@curii.com
<ul></ul><p>Peter Amstutz wrote:</p>
<blockquote>
<p>Tom Clegg wrote:</p>
<blockquote>
<p>Still need: "Slurm dispatcher should pass priority on sbatch command line, --priority=<value>"</p>
</blockquote>
<p>Done</p>
</blockquote>
<p>I know my comment above says "--priority=x" but did you try this? I get:</p>
<pre>
crunch@c97qk:~$ sbatch --priority=123 test
sbatch: unrecognized option '--priority=123'
Try "sbatch --help" for more information
crunch@c97qk:~$ sbatch --nice=-123 test
sbatch: error: Nice value must be non-negative, value ignored
Submitted batch job 556
crunch@c97qk:~$ sbatch --nice=0 test
Submitted batch job 557
crunch@c97qk:~$ sbatch --nice=100 test
Submitted batch job 558
</pre>
<p>Thoughts?</p>
<blockquote><blockquote>
<p>Still need: "Slurm dispatcher, when claiming a Locked container previously owned by itself, should check squeue to make sure the slurm job still exists, clean up record if not."</p>
</blockquote>
<p>Done.</p>
</blockquote>
<p>checkSqueue should check squeue's exit code.</p>
<p>An error in checkSqueue() doesn't mean our job has disappeared from the queue, so we shouldn't cancel the container in this case. It just means we don't know what's in the slurm queue right now. We should probably just log the error and try again. Can we move the squeue check into the "range status" loop so we notice even if slurm drops it on the floor but crunch-dispatch-slurm is still running?</p>
<p><del>crunch-dispatch-slurm should notice when a monitored container disappears from the slurm queue even if the Dispatcher doesn't send any updates about that container.</del> Dispatcher sends periodic updates about every running/owned container even when nothing has changed, so this isn't necessary, right?</p>
<blockquote><blockquote>
<p>pollContainers() calls dispatcher.getContainers() to get updated state for containers that are "mine" but (according to the "locked_by_uuid" query) aren't locked by us. (Would something like "notReallyMine" be a more precise name for this "monitored" slice?) If I'm following correctly, a container that is now locked by a different dispatcher (e.g., this dispatcher unlocked it, and a different dispatcher took it) will then end up in the "State Locked || State Running" case in handleContainers(), where we start up a new monitoring goroutine, which seems wrong.</p>
</blockquote>
<p>The reason it has to do this is because when a container record goes to "Cancelled" or "Complete" state, the "locked_by_uuid" field gets set to nil (because <code>need_lock = nil</code> if the state is not Locked or Running in validate_lock of container.rb). I don't know if that was the intended behavior but that's what it does now. You're right, this could be a problem if the dispatcher put a locked container back into the queue, but that currently doesn't happen.</p>
</blockquote>
<p>The API already allows Locked→Queued, and I think it has to: otherwise a slurm dispatcher would prematurely fail all containers if it started getting errors running "sbatch", instead of letting someone else (or itself) try to run them, for example. <a class="issue tracker-5 status-5 priority-4 priority-default closed child" title="Task: Tag Set Specifications (Closed)" href="https://dev.arvados.org/issues/7292">#7292</a> does this in crunch-run: if we aren't able to start the container, just put it back in the queue so someone else can take it.</p>
<p>Anyway, it seems like the bug can be fixed by adding a filter like ["locked_by_uuid","=",dispatcher.auth.UUID]. Anything that isn't locked by our token (and wasn't already received in the earlier "queued" query) should be un-monitored, regardless of state, right?</p>
<p>Basically it seems like "Dispatcher doesn't give you updates about containers that don't actually belong to you" would be a sensible feature.</p>
<blockquote>
<p>I simplified this to a single RunContainer callback goroutine which is responsible for determining if it should execute/submit a container, monitor an existing submission, or clean up a stale record.</p>
</blockquote>
<p>I think this is better, but can you update RunDispatcher's comment to reflect the new behavior?</p>
<p>getContainers() should return after logging the API error, instead of pyramiding the rest of the function in an else.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=395032016-05-28T03:01:53ZTom Cleggtom@curii.com
<ul></ul><p>If "cancel container if it disappears from the queue without cleaning itself up" moved into the "range status" loop, then we could drop the "crunch-finish-slurm.sh" thing and the dependency on Ruby etc. Is that right?</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=395432016-05-31T14:30:54ZPeter Amstutzpeter.amstutz@curii.com
<ul></ul><p>Tom Clegg wrote:</p>
<blockquote>
<p>I know my comment above says "--priority=x" but did you try this? I get:</p>
<p>[...]</p>
<p>Thoughts?</p>
</blockquote>
<pre>
root@75d5ed700c4d:/# echo '#!/bin/sh\necho foo' | sbatch --priority=5
Submitted batch job 2
root@75d5ed700c4d:/# sbatch --version
slurm 14.03.9
</pre>
<blockquote><blockquote><blockquote>
<p>Still need: "Slurm dispatcher, when claiming a Locked container previously owned by itself, should check squeue to make sure the slurm job still exists, clean up record if not."</p>
</blockquote>
<p>Done.</p>
</blockquote>
<p>checkSqueue should check squeue's exit code.</p>
</blockquote>
<p>Done.</p>
<blockquote>
<p>An error in checkSqueue() doesn't mean our job has disappeared from the queue, so we shouldn't cancel the container in this case. It just means we don't know what's in the slurm queue right now. We should probably just log the error and try again. Can we move the squeue check into the "range status" loop so we notice even if slurm drops it on the floor but crunch-dispatch-slurm is still running?</p>
</blockquote>
<p>Sure. Now on each status tick it checks squeue and updates state if not in the queue.</p>
<blockquote>
<p><del>crunch-dispatch-slurm should notice when a monitored container disappears from the slurm queue even if the Dispatcher doesn't send any updates about that container.</del> Dispatcher sends periodic updates about every running/owned container even when nothing has changed, so this isn't necessary, right?</p>
</blockquote>
<p>FWIW part of the reasoning for the design is to make it easy to plug in websockets or some other notification mechanism instead of polling in the future. In which case there won't be a default "heartbeat".</p>
<blockquote><blockquote><blockquote>
<p>pollContainers() calls dispatcher.getContainers() to get updated state for containers that are "mine" but (according to the "locked_by_uuid" query) aren't locked by us. (Would something like "notReallyMine" be a more precise name for this "monitored" slice?) If I'm following correctly, a container that is now locked by a different dispatcher (e.g., this dispatcher unlocked it, and a different dispatcher took it) will then end up in the "State Locked || State Running" case in handleContainers(), where we start up a new monitoring goroutine, which seems wrong.</p>
</blockquote></blockquote></blockquote>
<p>Fixed. Now stops monitoring any container where <code>container.LockedByUUID != dispatcher.Auth.UUID</code> and not Queued.</p>
<blockquote>
<p>The API already allows Locked→Queued, and I think it has to: otherwise a slurm dispatcher would prematurely fail all containers if it started getting errors running "sbatch", instead of letting someone else (or itself) try to run them, for example. <a class="issue tracker-5 status-5 priority-4 priority-default closed child" title="Task: Tag Set Specifications (Closed)" href="https://dev.arvados.org/issues/7292">#7292</a> does this in crunch-run: if we aren't able to start the container, just put it back in the queue so someone else can take it.</p>
</blockquote>
<p>So the intended behavior is that any errors that occur up to actually running the container should move it from "Locked" to "Queued"? Ok. Fixed.</p>
<blockquote>
<p>Anyway, it seems like the bug can be fixed by adding a filter like ["locked_by_uuid","=",dispatcher.auth.UUID]. Anything that isn't locked by our token (and wasn't already received in the earlier "queued" query) should be un-monitored, regardless of state, right?</p>
</blockquote>
<p>There's 3 queries that the dispatcher makes:</p>
<ol>
<li>for queued containers with > 0</li>
<li>for containers where locked_by_uuid = dispatcher.auth.uuid</li>
<li>for containers that known to the dispatcher and not included in either of the prior two queries. This is necessary to notice the transitions that result in locked_by_uuid = null; e.g. when a container goes from "Running" to "Complete".</li>
</ol>
<p>Containers retrieved in the last query will probably also result in "notMine()" being called in handleUpdate().</p>
<blockquote>
<p>Basically it seems like "Dispatcher doesn't give you updates about containers that don't actually belong to you" would be a sensible feature.</p>
</blockquote>
<p>Done.</p>
<blockquote><blockquote>
<p>I simplified this to a single RunContainer callback goroutine which is responsible for determining if it should execute/submit a container, monitor an existing submission, or clean up a stale record.</p>
</blockquote>
<p>I think this is better, but can you update RunDispatcher's comment to reflect the new behavior?</p>
</blockquote>
<p>Done.</p>
<blockquote>
<p>getContainers() should return after logging the API error, instead of pyramiding the rest of the function in an else.</p>
</blockquote>
<p>Done.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=396002016-06-01T13:45:52ZTom Cleggtom@curii.com
<ul></ul><p>Peter Amstutz wrote:</p>
<blockquote>
<pre>root@75d5ed700c4d:/# echo '#!/bin/sh\necho foo' | sbatch --priority=5
Submitted batch job 2
root@75d5ed700c4d:/# sbatch --version
slurm 14.03.9</pre>
</blockquote>
<p>Please clarify. Does this mean we depend on slurm >= 14 (?) and crunch-dispatch should submit jobs as root?</p>
<p>This is supposed to run jobs on existing slurm installations that aren't "owned" by Arvados -- it seems like either one of those could be a non-starter.</p>
<p>(fwiw, debian7 has 2.3.4, ubuntu1404 has 2.6.5.)</p>
<blockquote><blockquote>
<p><del>crunch-dispatch-slurm should notice when a monitored container disappears from the slurm queue even if the Dispatcher doesn't send any updates about that container.</del> Dispatcher sends periodic updates about every running/owned container even when nothing has changed, so this isn't necessary, right?</p>
</blockquote>
<p>FWIW part of the reasoning for the design is to make it easy to plug in websockets or some other notification mechanism instead of polling in the future. In which case there won't be a default "heartbeat".</p>
</blockquote>
<p>I guess Dispatcher should explicitly document what the caller is supposed to expect (update when something changes? or periodic updates even when nothing changes?) and crunch-dispatch-slurm should either rely on the heartbeat or not, accordingly.</p>
<p>Suggest previewing the godoc page by running <code>GOPATH={buildtmp}/GOPATH godoc -http :6060</code> and looking at <code>http://localhost:6060/pkg/git.curoverse.com/arvados.git/sdk/go/dispatch/</code>, if you haven't already.</p>
<p>(It sounds like you have some unpushed commits? 9187-crunchv2-dispatching is at <a class="changeset" title="9187: Refactor dispatcher support into common library and update to use Locking API. New dispatc..." href="https://dev.arvados.org/projects/arvados/repository/arvados/revisions/4153cb6cfad920ed0b1a4b818d3bcc8de492d134">4153cb6</a>)</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=396062016-06-01T14:52:44ZBrett Smithbrett.smith@curii.com
<ul></ul><p>Tom Clegg wrote:</p>
<blockquote>
<p>This is supposed to run jobs on existing slurm installations that aren't "owned" by Arvados -- it seems like either one of those could be a non-starter.</p>
<p>(fwiw, debian7 has 2.3.4, ubuntu1404 has 2.6.5.)</p>
</blockquote>
<p>I'm not sure how much we should care about Debian 7 anymore, since it's out of official security support and off to the LTS team. But the point about Ubuntu 14.04 is pretty compelling.</p>
<p>RHEL 6 came out in November 2010, and is still fully supported. SLURM 2.1 was the latest version at that time; SLURM 2.2 came out in December 2010. If we're going to require a later version (and I realize that's still an "if" from the comments), we need to have a discussion about what we're imposing on our customers.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=396222016-06-01T19:57:41ZPeter Amstutzpeter.amstutz@curii.com
<ul></ul><p>Tom Clegg wrote:</p>
<blockquote>
<p>Peter Amstutz wrote:</p>
<blockquote>
<p>[...]</p>
</blockquote>
<p>Please clarify. Does this mean we depend on slurm >= 14 (?) and crunch-dispatch should submit jobs as root?</p>
</blockquote>
<p>It does seem to be an issue with the slurm version. We don't need to submit jobs as root, that's just an artifact of happening to run sbatch as root from within the arvbox container.</p>
<blockquote>
<p>This is supposed to run jobs on existing slurm installations that aren't "owned" by Arvados -- it seems like either one of those could be a non-starter.</p>
</blockquote>
<blockquote>
<p>(fwiw, debian7 has 2.3.4, ubuntu1404 has 2.6.5.)</p>
</blockquote>
<p>Ok, we need check with users what version to target.</p>
<blockquote><blockquote><blockquote>
<p><del>crunch-dispatch-slurm should notice when a monitored container disappears from the slurm queue even if the Dispatcher doesn't send any updates about that container.</del> Dispatcher sends periodic updates about every running/owned container even when nothing has changed, so this isn't necessary, right?</p>
</blockquote>
<p>FWIW part of the reasoning for the design is to make it easy to plug in websockets or some other notification mechanism instead of polling in the future. In which case there won't be a default "heartbeat".</p>
</blockquote>
<p>I guess Dispatcher should explicitly document what the caller is supposed to expect (update when something changes? or periodic updates even when nothing changes?) and crunch-dispatch-slurm should either rely on the heartbeat or not, accordingly.</p>
</blockquote>
<p>Documentation is updated to reflect that.</p>
<blockquote>
<p>Suggest previewing the godoc page by running <code>GOPATH={buildtmp}/GOPATH godoc -http :6060</code> and looking at <code>http://localhost:6060/pkg/git.curoverse.com/arvados.git/sdk/go/dispatch/</code>, if you haven't already.</p>
<p>(It sounds like you have some unpushed commits? 9187-crunchv2-dispatching is at <a class="changeset" title="9187: Refactor dispatcher support into common library and update to use Locking API. New dispatc..." href="https://dev.arvados.org/projects/arvados/repository/arvados/revisions/4153cb6cfad920ed0b1a4b818d3bcc8de492d134">4153cb6</a>)</p>
</blockquote>
<p>Coming right up...</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=396242016-06-01T20:08:32ZPeter Amstutzpeter.amstutz@curii.com
<ul></ul><p>Now @ <a class="changeset" title="9187: Slurm dispatcher improvements around squeue * Clarify that status updates are not guarante..." href="https://dev.arvados.org/projects/arvados/repository/arvados/revisions/3ae9a789410e93eeb31ca5670c17a6d03d77f608">3ae9a789410e93eeb31ca5670c17a6d03d77f608</a></p>
<p>Slurm dispatcher improvements around squeue:</p>
<ul>
<li>Clarify that status updates are not guaranteed to be delivered on a<br /> heartbeat.</li>
<li>Refactor slurm dispatcher to monitor the container in squeue in a separate<br /> goroutine.</li>
<li>Refactor polling squeue to a single goroutine and cache the results so that<br /> monitoring 100 containers doesn't result in 100 calls to squeue.</li>
<li>No longer set up strigger to cancel job on finish, instead cancel running<br /> jobs not in squeue.</li>
<li>Test both cases where a job is/is not in squeue.</li>
</ul> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=396722016-06-02T17:06:54ZTom Cleggtom@curii.com
<ul></ul><p>Thanks for reducing "one squeue per poll per container" to "one squeue per poll", and getting rid of strigger. This is looking much better.</p>
<blockquote><blockquote>
<p>An error in checkSqueue() doesn't mean our job has disappeared from the queue, so we shouldn't cancel the container in this case. It just means we don't know what's in the slurm queue right now. We should probably just log the error and try again.</p>
</blockquote></blockquote>
<p>I think we still have this problem in the <code>if container.State == dispatch.Locked</code> block: if we get an squeue error we unlock/re-queue the container, but we shouldn't touch it in this case: we don't actually know what's happening.</p>
<p>Perhaps we could address this by doing all of the checking in one goroutine (i.e., the body of run()), something like this:</p>
<pre>
submitted := false
for { select {
case tick:
inQ, err := CheckSqueue()
if err {
log
} else if inQ {
submitted = true
} else if !submitted {
submit
} else {
change state Locked->Queued or Running->Cancelled
}
case status:
if status is closed {
break
}
if submitted && priority == 0 {
scancel
}
}}
</pre>
<p>Comments on Squeue methods would be helpful.</p>
<p>Might be better to log squeue errors in CheckSqueue instead of in run() -- that way logs will reveal when squeue is failing, even if no new containers are starting.</p>
<p>nit: could use an RWMutex in Squeue -- CheckSqueue could use squeue.RLocker().Lock(), so many goroutines can read the squeue (but writes are still safe).</p>
<p>nit: updating squeue.squeueContents seems like it could be done in runSqueue. Then SyncSqueue could call runSqueue, and CheckSqueue wouldn't need the "empty uuid means I'm just using you to call runSqueue" feature.</p>
run() has a variable <code>uuid</code> which is just container.UUID, but most of the code still uses container.UUID instead of the local copy anyway. The place that <em>does</em> need its own copy (to avoid races with the <code>for container = ...</code> loop) is the squeue-checking goroutine. Suggest:
<ul>
<li>removing the variable and using container.UUID instead in the ~4 affected places in the main func</li>
<li>passing a copy of container into the goroutine func. <code>go func(container dispatch.Container) { ... }(container)</code> (unless we get rid of the goroutine as above, of course)</li>
</ul>
<p>Change formally→formerly in handleUpdate comment</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=397022016-06-03T02:47:13ZPeter Amstutzpeter.amstutz@curii.com
<ul></ul><p>Tom Clegg wrote:</p>
<blockquote>
<p>Thanks for reducing "one squeue per poll per container" to "one squeue per poll", and getting rid of strigger. This is looking much better.</p>
</blockquote>
<p>Agree. I further and added an condition variable so that the monitoring goroutines only turn over when squeue has actually been successfully updated. This has some benefits for reasoning about sequencing because CheckSqueue() now blocks until the next update instead of having to interleave polling with calls to run squeue immediately to ensure that the results of sbatch/scancel show up.</p>
<blockquote>
<p>Perhaps we could address this by doing all of the checking in one goroutine (i.e., the body of run()), something like this:</p>
<p>[...]</p>
</blockquote>
<p>Done. Except it needs to be in a separate goroutine, because you can't use the <code>select { }</code> construct on mutexes or condition variables. (An alternate construct would be to have a goroutine which waits on CheckSqueue() and sends events over a channel, but I'm not sure if that would have any advantages here.)</p>
<blockquote>
<p>Comments on Squeue methods would be helpful.</p>
</blockquote>
<p>Done.</p>
<blockquote>
<p>Might be better to log squeue errors in CheckSqueue instead of in run() -- that way logs will reveal when squeue is failing, even if no new containers are starting.</p>
</blockquote>
<p>Done.</p>
<blockquote>
<p>nit: could use an RWMutex in Squeue -- CheckSqueue could use squeue.RLocker().Lock(), so many goroutines can read the squeue (but writes are still safe).</p>
</blockquote>
<p>It's structured a little bit differently now so the lock doesn't extend over the loop that searches the array. The critical section is extremely small, just enough to read or write the squeueContents field.</p>
<p>(As an aside, read-write locks are not actually more efficient than standard mutexes because you still need to perform an atomic operation on each RLock/RUnlock, and when the critical section is small the overhead of the atomic operations dominate the time spent in the critical section.)</p>
<blockquote>
<p>nit: updating squeue.squeueContents seems like it could be done in runSqueue. Then SyncSqueue could call runSqueue, and CheckSqueue wouldn't need the "empty uuid means I'm just using you to call runSqueue" feature.</p>
</blockquote>
<p>Done, along with the more substantial refactor of CheckSqueue() into a blocking operation.</p>
<blockquote>
run() has a variable <code>uuid</code> which is just container.UUID, but most of the code still uses container.UUID instead of the local copy anyway. The place that <em>does</em> need its own copy (to avoid races with the <code>for container = ...</code> loop) is the squeue-checking goroutine. Suggest:
<ul>
<li>removing the variable and using container.UUID instead in the ~4 affected places in the main func</li>
<li>passing a copy of container into the goroutine func. <code>go func(container dispatch.Container) { ... }(container)</code> (unless we get rid of the goroutine as above, of course)</li>
</ul>
</blockquote>
<p>Cleaned that up.</p>
<blockquote>
<p>Change formally→formerly in handleUpdate comment</p>
</blockquote>
<p>now @ <a class="changeset" title="9187: Fix comment typo" href="https://dev.arvados.org/projects/arvados/repository/arvados/revisions/bb10b7777ed6db229fbb35e6a829bec4e8efcd23">bb10b77</a></p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=397462016-06-03T21:18:27ZTom Cleggtom@curii.com
<ul></ul><p>Refactoring mishap -- Squeue's methods have a pointer receiver called "squeue" but they all seem to ignore it and operate on the squeueUpdater global instead.</p>
<p>RunSqueue only calls Broadcast when it successfully gets fresh squeue information. Meanwhile, CheckSqueue returns an error if squeueError != nil after Wait(). I see that it's possible for squeueError to be non-nil after Wait(), but I don't think it actually matters. What matters is that, if Wait() returns, squeueContents is fresh (newer than when we called Wait()). If, in the time since we called Wait(), there has been a successful update followed by an error, we do have fresh information to return, right? If I'm following correctly, this means CheckSqueue() doesn't need to return an error. As its comment says, it simply doesn't return until there is a successful update.</p>
<p>This also seems to mean squeueError is useless, which would be nice, because RunSqueue could lose some repetitive Lock/Unlock code.</p>
<p>StartMonitor calls RunSqueue() once before starting the periodic updates, which I assume is intended to try preloading a good squeue. But I suspect this is in vain: this first result (if any) can never be used, because no caller can possibly be waiting in squeueCond.Wait() yet.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=397732016-06-06T18:20:43ZPeter Amstutzpeter.amstutz@curii.com
<ul></ul><p>Tom Clegg wrote:</p>
<blockquote>
<p>Refactoring mishap -- Squeue's methods have a pointer receiver called "squeue" but they all seem to ignore it and operate on the squeueUpdater global instead.</p>
</blockquote>
<p><strong>facepalm</strong> you're right. Fixed.</p>
<blockquote>
<p>RunSqueue only calls Broadcast when it successfully gets fresh squeue information. Meanwhile, CheckSqueue returns an error if squeueError != nil after Wait(). I see that it's possible for squeueError to be non-nil after Wait(), but I don't think it actually matters. What matters is that, if Wait() returns, squeueContents is fresh (newer than when we called Wait()). If, in the time since we called Wait(), there has been a successful update followed by an error, we do have fresh information to return, right? If I'm following correctly, this means CheckSqueue() doesn't need to return an error. As its comment says, it simply doesn't return until there is a successful update.</p>
<p>This also seems to mean squeueError is useless, which would be nice, because RunSqueue could lose some repetitive Lock/Unlock code.</p>
</blockquote>
<p>That's a good insight. The key is to wait for a successful squeue check occuring strictly after sbatch/scancel. Removed squeueError.</p>
<blockquote>
<p>StartMonitor calls RunSqueue() once before starting the periodic updates, which I assume is intended to try preloading a good squeue. But I suspect this is in vain: this first result (if any) can never be used, because no caller can possibly be waiting in squeueCond.Wait() yet.</p>
</blockquote>
<p>Done.</p>
<p>I also refactored the tests a little bit and added a new test for the priority=0 -> scancel case.</p>
<p>now @ c405873d87e0764acf3855c559c85fa6d7a63cfb</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=397762016-06-06T19:22:25ZTom Cleggtom@curii.com
<ul></ul><p>LGTM @ <a class="changeset" title="9187: Remove "squeueError" because checkSqueue for a successful squeue run. Refactor tests a bit..." href="https://dev.arvados.org/projects/arvados/repository/arvados/revisions/c405873d87e0764acf3855c559c85fa6d7a63cfb">c405873</a></p>
<p>Aside: I accidentally ran tests with an out-of-date API server, and got to observe an unfortunate interaction between the signal handling and "25 retries": the dispatcher can take a while to get through 26 API calls before eventually noticing SIGTERM, which seemed especially silly because [a] the failing API call was "lock container" which gets retried by crunch-dispatch-slurm itself on the next squeue update anyway, and [b] the API error was 422 because the request was invalid, but we consider that retryable (because Rails/API uses 422 for "miscellaneous"?).</p>
<p>Given dispatch's "figure out what to do next; do it; repeat" approach, I wonder whether the 25 retries are really worth anything -- or, if we reduced it to zero, would everything still work correctly in the face of failures? It seems like <em>sometimes</em> even 25 retries won't be enough anyway, so it might be better (wrt heisenbugs) to use one fault tolerance path more often, rather than relying on 25 retries most of the time, and relying on crunch-dispatch's own fault tolerance only in the cases where retrying doesn't work.</p>
<p>I'd be fine with retries=0, or a smaller number than 25, or just leaving it alone for now, whatever you think is good. This story has crept enough already...</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=397782016-06-06T19:30:07ZPeter Amstutzpeter.amstutz@curii.com
<ul><li><strong>Status</strong> changed from <i>In Progress</i> to <i>Resolved</i></li><li><strong>% Done</strong> changed from <i>67</i> to <i>100</i></li></ul><p>Applied in changeset arvados|commit:55febaa6856eb2d77657edd685aaae78bba0ec82.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=399342016-06-09T15:08:55ZPeter Amstutzpeter.amstutz@curii.com
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>In Progress</i></li></ul><p>Reopened for 9187-requeued-containers bug fixes based on testing.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=399392016-06-09T15:29:05ZTom Cleggtom@curii.com
<ul></ul><p>checkMine's doc comment isn't quite correct: it says it only returns true if update is true.</p>
<p>I think it would be helpful to add a comment on the "if Queued and already mine" case. The idea here is that we close the existing monitoring channel, open a new one, and start a new RunContainer() goroutine, right? Normally this means crunch-dispatch-* or crunch-run has set state back to Queued after some failure... And in other cases a lost-and-confused crunch-run process is expected to die naturally due to changed auth token, because some version of <a class="issue tracker-6 status-5 priority-4 priority-default closed" title="Idea: [Crunch2] Prevent dispatch races (Closed)" href="https://dev.arvados.org/issues/9328">#9328</a> will be in place... But in any case it doesn't make sense to sit around waiting for the failed attempt to do something interesting... right?</p>
<p>Aside from adding/fixing comments, LGTM. Thanks.</p> Arvados - Idea #9187: [Crunch2] Update dispatcher to use new API supporthttps://dev.arvados.org/issues/9187?journal_id=399592016-06-09T20:25:07ZPeter Amstutzpeter.amstutz@curii.com
<ul><li><strong>Status</strong> changed from <i>In Progress</i> to <i>Resolved</i></li><li><strong>% Done</strong> changed from <i>50</i> to <i>100</i></li></ul><p>Applied in changeset arvados|commit:84b538b627cba20558e0a52f3efe73eec90a46fe.</p>