Skip to content

Commit

Permalink
autoclean: rest between cleanup calls.
Browse files Browse the repository at this point in the history
This means we don't consume *all* the CPU.

Changelog-Fixed: Plugins: `autoclean` is now gentler on the node when doing giant cleans.
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and vincenzopalazzo committed Nov 12, 2024
1 parent 4938023 commit ccd9b21
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions plugins/autoclean.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ struct clean_info {
struct command *cmd;
size_t cleanup_reqs_remaining;

/* When did we start making requests? */
struct timemono reqs_start;

struct per_subsystem per_subsystem[NUM_SUBSYSTEM_TYPES];
};

Expand Down Expand Up @@ -294,14 +297,26 @@ static struct command_result *clean_finished(struct clean_info *cinfo)
}
}

static struct command_result *do_clean_after_sleep(struct command *timer_cmd,
struct clean_info *cinfo)
{
do_clean(cinfo);
return timer_complete(timer_cmd);
}

static struct command_result *clean_finished_one(struct clean_info *cinfo)
{
assert(cinfo->cleanup_reqs_remaining != 0);
if (--cinfo->cleanup_reqs_remaining > 0)
return command_still_pending(cinfo->cmd);

/* See if there are more entries we need to list. */
return do_clean(cinfo);
/* See if there are more entries we need to list, but don't
* use more than half the node's RPC capacity: sleep as long
* as the last cleans took. */
notleak(command_timer(cinfo->cmd,
timemono_between(time_mono(), cinfo->reqs_start),
do_clean_after_sleep, cinfo));
return command_still_pending(cinfo->cmd);
}

static struct command_result *del_done(struct command *cmd,
Expand Down Expand Up @@ -537,6 +552,8 @@ static struct command_result *list_failed(struct command *cmd,
static struct command_result *do_clean(struct clean_info *cinfo)
{
cinfo->cleanup_reqs_remaining = 0;
cinfo->reqs_start = time_mono();

for (size_t i = 0; i < NUM_SUBSYSTEM_TYPES; i++) {
struct per_subsystem *ps = &cinfo->per_subsystem[i];
struct out_req *req;
Expand Down

0 comments on commit ccd9b21

Please sign in to comment.