@@ -185,6 +185,9 @@ struct clean_info {
185185 struct command * cmd ;
186186 size_t cleanup_reqs_remaining ;
187187
188+ /* When did we start making requests? */
189+ struct timemono reqs_start ;
190+
188191 struct per_subsystem per_subsystem [NUM_SUBSYSTEM_TYPES ];
189192};
190193
@@ -294,14 +297,26 @@ static struct command_result *clean_finished(struct clean_info *cinfo)
294297 }
295298}
296299
300+ static struct command_result * do_clean_after_sleep (struct command * timer_cmd ,
301+ struct clean_info * cinfo )
302+ {
303+ do_clean (cinfo );
304+ return timer_complete (timer_cmd );
305+ }
306+
297307static struct command_result * clean_finished_one (struct clean_info * cinfo )
298308{
299309 assert (cinfo -> cleanup_reqs_remaining != 0 );
300310 if (-- cinfo -> cleanup_reqs_remaining > 0 )
301311 return command_still_pending (cinfo -> cmd );
302312
303- /* See if there are more entries we need to list. */
304- return do_clean (cinfo );
313+ /* See if there are more entries we need to list, but don't
314+ * use more than half the node's RPC capacity: sleep as long
315+ * as the last cleans took. */
316+ notleak (command_timer (cinfo -> cmd ,
317+ timemono_between (time_mono (), cinfo -> reqs_start ),
318+ do_clean_after_sleep , cinfo ));
319+ return command_still_pending (cinfo -> cmd );
305320}
306321
307322static struct command_result * del_done (struct command * cmd ,
@@ -537,6 +552,8 @@ static struct command_result *list_failed(struct command *cmd,
537552static struct command_result * do_clean (struct clean_info * cinfo )
538553{
539554 cinfo -> cleanup_reqs_remaining = 0 ;
555+ cinfo -> reqs_start = time_mono ();
556+
540557 for (size_t i = 0 ; i < NUM_SUBSYSTEM_TYPES ; i ++ ) {
541558 struct per_subsystem * ps = & cinfo -> per_subsystem [i ];
542559 struct out_req * req ;
0 commit comments