Skip to content

Commit bee028f

Browse files
committed
bookkeeper: restore limit on asking for all channelmoves at once.
Now we've found all the issues, the latency spike (4 seconds on my laptop) for querying 2M elements remains. Restore the limited sampling which we reverted, but make it 10,000 now. This doesn't help our worst-case latency, because sql still asks for all 2M entries on first access. We address that next. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 46c551e commit bee028f

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

plugins/bkpr/bookkeeper.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ static struct refresh_info *use_rinfo(struct refresh_info *rinfo)
5454
return rinfo;
5555
}
5656

57+
/* Recursion */
58+
static struct command_result *limited_listchannelmoves(struct command *cmd,
59+
struct refresh_info *rinfo);
60+
5761
static struct command_result *rinfo_one_done(struct command *cmd,
5862
struct refresh_info *rinfo)
5963
{
@@ -104,6 +108,7 @@ static struct fee_sum *find_sum_for_txid(struct fee_sum **sums,
104108
return NULL;
105109
}
106110

111+
#define LISTCHANNELMOVES_LIMIT 10000
107112
static struct command_result *listchannelmoves_done(struct command *cmd,
108113
const char *method,
109114
const char *buf,
@@ -125,16 +130,36 @@ static struct command_result *listchannelmoves_done(struct command *cmd,
125130
"create-or-replace",
126131
datastore_done, NULL, use_rinfo(rinfo));
127132

133+
/* If there might be more, try asking for more */
134+
if (moves->size == LISTCHANNELMOVES_LIMIT)
135+
limited_listchannelmoves(cmd, rinfo);
136+
128137
return rinfo_one_done(cmd, rinfo);
129138
}
130139

140+
/* We do 1000 at a time to avoid overwhelming lightningd */
141+
static struct command_result *limited_listchannelmoves(struct command *cmd,
142+
struct refresh_info *rinfo)
143+
{
144+
struct bkpr *bkpr = bkpr_of(cmd->plugin);
145+
struct out_req *req;
146+
147+
req = jsonrpc_request_start(cmd, "listchannelmoves",
148+
listchannelmoves_done,
149+
plugin_broken_cb,
150+
use_rinfo(rinfo));
151+
json_add_string(req->js, "index", "created");
152+
json_add_u64(req->js, "start", bkpr->channelmoves_index + 1);
153+
json_add_u64(req->js, "limit", LISTCHANNELMOVES_LIMIT);
154+
return send_outreq(req);
155+
}
156+
131157
static struct command_result *listchainmoves_done(struct command *cmd,
132158
const char *method,
133159
const char *buf,
134160
const jsmntok_t *result,
135161
struct refresh_info *rinfo)
136162
{
137-
struct out_req *req;
138163
const jsmntok_t *moves, *t;
139164
size_t i;
140165
struct bkpr *bkpr = bkpr_of(cmd->plugin);
@@ -150,13 +175,7 @@ static struct command_result *listchainmoves_done(struct command *cmd,
150175
"create-or-replace",
151176
datastore_done, NULL, use_rinfo(rinfo));
152177

153-
req = jsonrpc_request_start(cmd, "listchannelmoves",
154-
listchannelmoves_done,
155-
plugin_broken_cb,
156-
use_rinfo(rinfo));
157-
json_add_string(req->js, "index", "created");
158-
json_add_u64(req->js, "start", bkpr->channelmoves_index + 1);
159-
send_outreq(req);
178+
limited_listchannelmoves(cmd, rinfo);
160179
return rinfo_one_done(cmd, rinfo);
161180
}
162181

0 commit comments

Comments
 (0)