Merge benchmark implementation for Grid5000

This commit is contained in:
Boss Marco 2021-11-18 13:50:11 +01:00
commit 525fcc48dc
No known key found for this signature in database
GPG Key ID: 89A3EC33C625C3DF

View File

@ -22,11 +22,13 @@ import {
codecForNumber,
codecForString,
codecOptional,
Logger,
} from "@gnu-taler/taler-util";
import {
getDefaultNodeWallet,
NodeHttpLib,
WalletApiOperation,
Wallet,
} from "@gnu-taler/taler-wallet-core";
/**
@ -36,6 +38,9 @@ import {
* set up its own services.
*/
export async function runBench1(configJson: any): Promise<void> {
const logger = new Logger("Bench1");
// Validate the configuration file for this benchmark.
const b1conf = codecForBench1Config().decode(configJson);
@ -43,17 +48,36 @@ export async function runBench1(configJson: any): Promise<void> {
myHttpLib.setThrottling(false);
const numIter = b1conf.iterations ?? 1;
const numDeposits = b1conf.deposits ?? 5;
const restartWallet = b1conf.restartAfter ?? 20;
const withdrawAmount = (numDeposits + 1) * 10;
logger.info(`Starting Benchmark iterations=${numIter} deposits=${numDeposits}`);
let wallet = {} as Wallet;
for (let i = 0; i < numIter; i++) {
const wallet = await getDefaultNodeWallet({
// No persistent DB storage.
persistentStoragePath: undefined,
httpLib: myHttpLib,
});
await wallet.client.call(WalletApiOperation.InitWallet, {});
// Create a new wallet in each iteration
// otherwise the TPS go down
// my assumption is that the in-memory db file gets too large
if (i % restartWallet == 0) {
if (Object.keys(wallet).length !== 0) {
wallet.stop();
}
wallet = await getDefaultNodeWallet({
// No persistent DB storage.
persistentStoragePath: undefined,
httpLib: myHttpLib,
});
await wallet.client.call(WalletApiOperation.InitWallet, {});
}
logger.trace(`Starting withdrawal amount=${withdrawAmount}`);
let start = Date.now();
await wallet.client.call(WalletApiOperation.WithdrawFakebank, {
amount: "TESTKUDOS:10",
amount: b1conf.currency + ":" + withdrawAmount,
bank: b1conf.bank,
exchange: b1conf.exchange,
});
@ -62,16 +86,24 @@ export async function runBench1(configJson: any): Promise<void> {
stopWhenDone: true,
});
await wallet.client.call(WalletApiOperation.CreateDepositGroup, {
amount: "TESTKUDOS:5",
depositPaytoUri: "payto://x-taler-bank/localhost/foo",
});
logger.info(`Finished withdrawal amount=${withdrawAmount} time=${Date.now() - start}`);
await wallet.runTaskLoop({
stopWhenDone: true,
});
for (let i = 0; i < numDeposits; i++) {
wallet.stop();
logger.trace(`Starting deposit amount=10`);
start = Date.now()
await wallet.client.call(WalletApiOperation.CreateDepositGroup, {
amount: b1conf.currency + ":10",
depositPaytoUri: b1conf.payto,
});
await wallet.runTaskLoop({
stopWhenDone: true,
});
logger.info(`Finished deposit amount=10 time=${Date.now() - start}`);
}
}
}
@ -84,6 +116,11 @@ interface Bench1Config {
*/
bank: string;
/**
* Payto url for deposits.
*/
payto: string;
/**
* Base URL of the exchange.
*/
@ -94,6 +131,16 @@ interface Bench1Config {
* Defaults to 1.
*/
iterations?: number;
currency: string;
deposits?: number;
/**
* How any iterations run until the wallet db gets purged
* Defaults to 20.
*/
restartAfter?: number;
}
/**
@ -102,6 +149,10 @@ interface Bench1Config {
const codecForBench1Config = () =>
buildCodecForObject<Bench1Config>()
.property("bank", codecForString())
.property("payto", codecForString())
.property("exchange", codecForString())
.property("iterations", codecOptional(codecForNumber()))
.property("deposits", codecOptional(codecForNumber()))
.property("currency", codecForString())
.property("restartAfter", codecOptional(codecForNumber()))
.build("Bench1Config");