Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loadgen "stop" mode #4579

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
SirTyson marked this conversation as resolved.
Show resolved Hide resolved
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
Loading