]> git.hungrycats.org Git - bees/commit
context: speed up orderly process termination
authorZygo Blaxell <bees@furryterror.org>
Sat, 19 Nov 2022 07:45:15 +0000 (02:45 -0500)
committerZygo Blaxell <bees@furryterror.org>
Wed, 21 Dec 2022 01:50:58 +0000 (20:50 -0500)
commit31b2aa3c0dcf042559fa495b63a1bf22bac4d55d
tree27dc8e648e3ebf50f1218363d68c169640b2a290
parent594ad1786d40a72983594effd4f9d2d23f764c72
context: speed up orderly process termination

Quite often bees exceeds its service timeout for termination because
it is waiting for a loop embedded in a Task to finish some long-running
btrfs operation.  This can cause bees to be aborted by SIGKILL before
it can completely flush the hash table or save crawl state.

There are only two important things SIGTERM does when bees terminates:
 1.  Save crawl progress
 2.  Flush out the hash table

Everything else is automatically handled by the kernel when the process
is terminated by SIGKILL, so we don't have to bother doing it ourselves.
This can save considerable time at shutdown since we don't have to wait
for every thread to reach a point where it becomes idle, or force loops
to terminate by throwing exceptions, or check a condition every time we
access a pointer.  Instead, we need do only the things in the list
above, and then call _exit() to clean up everything else.

Hash table and crawl state writeback can happen in their background
threads instead of the foreground one.  Separate the "stop" method for
these classes into "stop_request" and "stop_wait" so that these writebacks
can run at the same time.

Deprecate and remove all references to the BeesHalt exception, and remove
several unnecessary checks for BeesContext::stop_requested.

Pause the task queue instead of cancelling it, which preserves the
crawl progress state and stops new Tasks from competing for iops and
CPU during writeback.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees-context.cc
src/bees-hash.cc
src/bees-roots.cc
src/bees.h