fix: limit concurrent Loads to improve stability
This commit is contained in:
parent
7b1130b5bf
commit
8468d3ebd1
|
@ -51,7 +51,7 @@ export class Loader {
|
||||||
const chunkSize = 256;
|
const chunkSize = 256;
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
let array = data;
|
let array = data;
|
||||||
const transactions = [];
|
let transactions = [];
|
||||||
while (array.length > 0) {
|
while (array.length > 0) {
|
||||||
const bytes = array.slice(0, chunkSize);
|
const bytes = array.slice(0, chunkSize);
|
||||||
const userdata = Buffer.alloc(chunkSize + 16);
|
const userdata = Buffer.alloc(chunkSize + 16);
|
||||||
|
@ -71,6 +71,15 @@ export class Loader {
|
||||||
});
|
});
|
||||||
transactions.push(sendAndConfirmTransaction(this.connection, program, transaction));
|
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;
|
offset += chunkSize;
|
||||||
array = array.slice(chunkSize);
|
array = array.slice(chunkSize);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue