Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchdog #1870

Merged
merged 12 commits into from
Dec 13, 2023
Merged

Watchdog #1870

merged 12 commits into from
Dec 13, 2023

Conversation

igor-egorov
Copy link
Contributor

@igor-egorov igor-egorov commented Nov 16, 2023

Referenced issues

Description of the Change

An implementation of in-process watchdog based on timing out boost asio loops.

Default timeout is set to be 15 min.

Benefits

Not an over-complicated implementation.

Possible Drawbacks

The watchdog would not track the whole process state.

turuslan and others added 6 commits October 26, 2023 18:02
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
Signed-off-by: Igor Egorov <igor@qdrvm.io>
Signed-off-by: Igor Egorov <igor@qdrvm.io>
Signed-off-by: Igor Egorov <igor@qdrvm.io>
Signed-off-by: Igor Egorov <igor@qdrvm.io>
Signed-off-by: Igor Egorov <igor@qdrvm.io>
std::shared_ptr<Atomic> count_;

void operator()() {
++*count_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
++*count_;
count_->fetch_add(1);

core/utils/watchdog.hpp Show resolved Hide resolved
if (lag > timeout) {
std::stringstream s;
s << it->first;
fmt::print(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use SL_CRITICAL. It flushes all collected buffers after add log message

core/utils/watchdog.hpp Show resolved Hide resolved
void run(std::shared_ptr<boost::asio::io_context> io) {
auto ping = add();
while (not stopped_ and not io.unique()) {
#if 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if constexpr (false) would be better - selective compilation with checking both branches.

Copy link
Contributor

@turuslan turuslan Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if constexpr (false) doesn't compile here (requires template).

std::chrono::seconds wait{1};
[&](auto &io) {
  boost::system::error_code ec;
  auto wait_us = std::chrono::duration_cast<std::chrono::microseconds>(wait);
  if constexpr (requires { io->impl_.wait_one(wait_us.count(), ec); }) {
    io->impl_.wait_one(wait_us.count(), ec);
    ping();
    io->poll_one();
  } else {
    io->run_one_for(wait);
  }
}(io);

@igor-egorov igor-egorov merged commit 357fb81 into master Dec 13, 2023
13 checks passed
@igor-egorov igor-egorov deleted the feature/watchdogo branch December 13, 2023 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add watchdog
3 participants