fix: limit concurrent Loads to improve stability

This commit is contained in:
Michael Vines 2018-11-01 20:35:19 -07:00
parent 7b1130b5bf
commit 8468d3ebd1
1 changed files with 10 additions and 1 deletions

View File

@ -51,7 +51,7 @@ export class Loader {
const chunkSize = 256;
let offset = 0;
let array = data;
const transactions = [];
let transactions = [];
while (array.length > 0) {
const bytes = array.slice(0, chunkSize);
const userdata = Buffer.alloc(chunkSize + 16);
@ -71,6 +71,15 @@ export class Loader {
});
transactions.push(sendAndConfirmTransaction(this.connection, program, transaction));
// Run up to 8 Loads in parallel to prevent too many parallel transactions from
// getting rejected with AccountInUse.
//
// TODO: 8 was selected empirically and should probably be revisited
if (transactions.length === 8) {
await Promise.all(transactions);
transactions = [];
}
offset += chunkSize;
array = array.slice(chunkSize);
}