Skip to content

Commit

Permalink
Add loadgen "stop" mode (#4579)
Browse files Browse the repository at this point in the history
Resolves #4488

This should help speed up max TPS runs
  • Loading branch information
marta-lokhova authored Dec 17, 2024
2 parents 0e19194 + a12e0d7 commit e58133b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/software/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ this survey mechanism, just set `SURVEYOR_KEYS` to `$self` or a bogus key

### The following HTTP commands are exposed on test instances
* **generateload** `generateload[?mode=
(create|pay|pretend|mixed_classic|soroban_upload|soroban_invoke_setup|soroban_invoke|upgrade_setup|create_upgrade|mixed_classic_soroban)&accounts=N&offset=K&txs=M&txrate=R&spikesize=S&spikeinterval=I&maxfeerate=F&skiplowfeetxs=(0|1)&dextxpercent=D&minpercentsuccess=S&instances=Y&wasms=Z&payweight=P&sorobanuploadweight=Q&sorobaninvokeweight=R]`
(create|pay|pretend|mixed_classic|soroban_upload|soroban_invoke_setup|soroban_invoke|upgrade_setup|create_upgrade|mixed_classic_soroban|stop)&accounts=N&offset=K&txs=M&txrate=R&spikesize=S&spikeinterval=I&maxfeerate=F&skiplowfeetxs=(0|1)&dextxpercent=D&minpercentsuccess=S&instances=Y&wasms=Z&payweight=P&sorobanuploadweight=Q&sorobaninvokeweight=R]`

Artificially generate load for testing; must be used with
`ARTIFICIALLY_GENERATE_LOAD_FOR_TESTING` set to true.
Expand Down Expand Up @@ -532,6 +532,7 @@ this survey mechanism, just set `SURVEYOR_KEYS` to `$self` or a bogus key
`soroban_upload`, and `soroban_invoke` load with the likelihood of any
generated transaction falling into each mode being determined by the mode's
weight divided by the sum of all weights.
* `stop` mode stops any existing load generation run and marks it as "failed".

Non-`create` load generation makes use of the additional parameters:
* when a nonzero `spikeinterval` is given, a spike will occur every
Expand Down
13 changes: 11 additions & 2 deletions src/main/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,9 +1263,18 @@ CommandHandler::generateLoad(std::string const& params, std::string& retStr)
{
std::map<std::string, std::string> map;
http::server::server::parseParams(params, map);
auto modeStr =
parseOptionalParamOrDefault<std::string>(map, "mode", "create");
// First check if a current run needs to be stopped
if (modeStr == "stop")
{
mApp.getLoadGenerator().stop();
retStr = "Stopped load generation";
return;
}

GeneratedLoadConfig cfg;
cfg.mode = LoadGenerator::getMode(
parseOptionalParamOrDefault<std::string>(map, "mode", "create"));
cfg.mode = LoadGenerator::getMode(modeStr);

cfg.nAccounts =
parseOptionalParamOrDefault<uint32_t>(map, "accounts", 1000);
Expand Down
17 changes: 17 additions & 0 deletions src/simulation/LoadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@ LoadGenerator::resetSorobanState()
mContactOverheadBytes = 0;
}

void
LoadGenerator::stop()
{
ZoneScoped;
if (mStarted)
{
// Some residual transactions might still be pending in consensus, but
// that should be harmless.
if (mLoadTimer)
{
mLoadTimer->cancel();
}
mLoadgenFail.Mark();
reset();
}
}

void
LoadGenerator::start(GeneratedLoadConfig& cfg)
{
Expand Down
2 changes: 2 additions & 0 deletions src/simulation/LoadGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ class LoadGenerator
return mContactOverheadBytes;
}

void stop();

private:
struct TxMetrics
{
Expand Down
20 changes: 20 additions & 0 deletions src/simulation/test/LoadGeneratorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ TEST_CASE("generate load with unique accounts", "[loadgen]")
},
10 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false);
}
SECTION("stop loadgen")
{
loadGen.generateLoad(GeneratedLoadConfig::createAccountsLoad(
/* nAccounts */ 10000,
/* txRate */ 1));
simulation->crankForAtLeast(std::chrono::seconds(10), false);
auto& acc = app.getMetrics().NewMeter({"loadgen", "account", "created"},
"account");
auto numAccounts = acc.count();
REQUIRE(app.getMetrics()
.NewMeter({"loadgen", "run", "failed"}, "run")
.count() == 0);
loadGen.stop();
REQUIRE(app.getMetrics()
.NewMeter({"loadgen", "run", "failed"}, "run")
.count() == 1);
// No new txs submitted
simulation->crankForAtLeast(std::chrono::seconds(10), false);
REQUIRE(acc.count() == numAccounts);
}
}

TEST_CASE("modify soroban network config", "[loadgen][soroban]")
Expand Down

0 comments on commit e58133b

Please sign in to comment.