mirror of
https://github.com/Zygo/bees.git
synced 2025-07-01 00:02:27 +02:00
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>
This commit is contained in:
14
src/bees.h
14
src/bees.h
@ -423,7 +423,8 @@ public:
|
||||
BeesHashTable(shared_ptr<BeesContext> ctx, string filename, off_t size = BLOCK_SIZE_HASHTAB_EXTENT);
|
||||
~BeesHashTable();
|
||||
|
||||
void stop();
|
||||
void stop_request();
|
||||
void stop_wait();
|
||||
|
||||
vector<Cell> find_cell(HashType hash);
|
||||
bool push_random_hash_addr(HashType hash, AddrType addr);
|
||||
@ -595,7 +596,8 @@ friend class BeesTempFile;
|
||||
public:
|
||||
BeesRoots(shared_ptr<BeesContext> ctx);
|
||||
void start();
|
||||
void stop();
|
||||
void stop_request();
|
||||
void stop_wait();
|
||||
|
||||
Fd open_root(uint64_t root);
|
||||
Fd open_root_ino(uint64_t root, uint64_t ino);
|
||||
@ -720,10 +722,6 @@ struct BeesResolveAddrResult {
|
||||
bool is_toxic() const { return m_is_toxic; }
|
||||
};
|
||||
|
||||
struct BeesHalt : exception {
|
||||
const char *what() const noexcept override;
|
||||
};
|
||||
|
||||
class BeesContext : public enable_shared_from_this<BeesContext> {
|
||||
Fd m_home_fd;
|
||||
|
||||
@ -749,10 +747,6 @@ class BeesContext : public enable_shared_from_this<BeesContext> {
|
||||
bool m_stop_requested = false;
|
||||
bool m_stop_status = false;
|
||||
|
||||
mutable mutex m_abort_mutex;
|
||||
condition_variable m_abort_condvar;
|
||||
bool m_abort_requested = false;
|
||||
|
||||
shared_ptr<BeesThread> m_progress_thread;
|
||||
shared_ptr<BeesThread> m_status_thread;
|
||||
|
||||
|
Reference in New Issue
Block a user