mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
autoclean: rest between cleanup calls.
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 <rusty@rustcorp.com.au>
This commit is contained in:
parent
49380239e9
commit
ccd9b21d04
@ -185,6 +185,9 @@ struct clean_info {
|
|||||||
struct command *cmd;
|
struct command *cmd;
|
||||||
size_t cleanup_reqs_remaining;
|
size_t cleanup_reqs_remaining;
|
||||||
|
|
||||||
|
/* When did we start making requests? */
|
||||||
|
struct timemono reqs_start;
|
||||||
|
|
||||||
struct per_subsystem per_subsystem[NUM_SUBSYSTEM_TYPES];
|
struct per_subsystem per_subsystem[NUM_SUBSYSTEM_TYPES];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -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)
|
static struct command_result *clean_finished_one(struct clean_info *cinfo)
|
||||||
{
|
{
|
||||||
assert(cinfo->cleanup_reqs_remaining != 0);
|
assert(cinfo->cleanup_reqs_remaining != 0);
|
||||||
if (--cinfo->cleanup_reqs_remaining > 0)
|
if (--cinfo->cleanup_reqs_remaining > 0)
|
||||||
return command_still_pending(cinfo->cmd);
|
return command_still_pending(cinfo->cmd);
|
||||||
|
|
||||||
/* See if there are more entries we need to list. */
|
/* See if there are more entries we need to list, but don't
|
||||||
return do_clean(cinfo);
|
* 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,
|
static struct command_result *del_done(struct command *cmd,
|
||||||
@ -537,6 +552,8 @@ static struct command_result *list_failed(struct command *cmd,
|
|||||||
static struct command_result *do_clean(struct clean_info *cinfo)
|
static struct command_result *do_clean(struct clean_info *cinfo)
|
||||||
{
|
{
|
||||||
cinfo->cleanup_reqs_remaining = 0;
|
cinfo->cleanup_reqs_remaining = 0;
|
||||||
|
cinfo->reqs_start = time_mono();
|
||||||
|
|
||||||
for (size_t i = 0; i < NUM_SUBSYSTEM_TYPES; i++) {
|
for (size_t i = 0; i < NUM_SUBSYSTEM_TYPES; i++) {
|
||||||
struct per_subsystem *ps = &cinfo->per_subsystem[i];
|
struct per_subsystem *ps = &cinfo->per_subsystem[i];
|
||||||
struct out_req *req;
|
struct out_req *req;
|
||||||
|
Loading…
Reference in New Issue
Block a user