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

Apply load improve #1

Draft
wants to merge 4 commits into
base: apply_load_improve
Choose a base branch
from
Draft
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
275 changes: 97 additions & 178 deletions src/main/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,197 +1801,116 @@ runApplyLoad(CommandLineArgs const& args)
{
CommandLine::ConfigOption configOption;

uint64_t ledgerMaxInstructions = 0;
uint64_t ledgerMaxReadLedgerEntries = 0;
uint64_t ledgerMaxReadBytes = 0;
uint64_t ledgerMaxWriteLedgerEntries = 0;
uint64_t ledgerMaxWriteBytes = 0;
uint64_t ledgerMaxTxCount = 0;
uint64_t ledgerMaxTransactionsSizeBytes = 0;

ParserWithValidation ledgerMaxInstructionsParser{
clara::Opt(ledgerMaxInstructions,
"LedgerMaxInstructions")["--ledger-max-instructions"]
.required(),
[&] {
return ledgerMaxInstructions > 0
? ""
: "ledgerMaxInstructions must be > 0";
}};

ParserWithValidation ledgerMaxReadLedgerEntriesParser{
clara::Opt(ledgerMaxReadLedgerEntries,
"LedgerMaxReadLedgerEntries")["--ledger-max-read-entries"]
.required(),
[&] {
return ledgerMaxReadLedgerEntries > 0
? ""
: "ledgerMaxReadLedgerEntries must be > 0";
}};

ParserWithValidation ledgerMaxReadBytesParser{
clara::Opt(ledgerMaxReadBytes,
"LedgerMaxReadBytes")["--ledger-max-read-bytes"]
.required(),
[&] {
return ledgerMaxReadBytes > 0 ? ""
: "ledgerMaxReadBytes must be > 0";
}};

ParserWithValidation ledgerMaxWriteLedgerEntriesParser{
clara::Opt(ledgerMaxWriteLedgerEntries,
"LedgerMaxWriteLedgerEntries")["--ledger-max-write-entries"]
.required(),
[&] {
return ledgerMaxWriteLedgerEntries > 0
? ""
: "ledgerMaxWriteLedgerEntries must be > 0";
}};

ParserWithValidation ledgerMaxWriteBytesParser{
clara::Opt(ledgerMaxWriteBytes,
"LedgerMaxWriteBytes")["--ledger-max-write-bytes"]
.required(),
[&] {
return ledgerMaxWriteBytes > 0 ? ""
: "ledgerMaxWriteBytes must be > 0";
}};

ParserWithValidation ledgerMaxTxCountParser{
clara::Opt(ledgerMaxTxCount,
"LedgerMaxTxCount")["--ledger-max-tx-count"]
.required(),
[&] {
return ledgerMaxTxCount > 0 ? "" : "ledgerMaxTxCount must be > 0";
}};
return runWithHelp(args, {configurationParser(configOption)}, [&] {
auto config = configOption.getConfig();
config.RUN_STANDALONE = true;
config.MANUAL_CLOSE = true;
config.USE_CONFIG_FOR_GENESIS = true;
config.TESTING_UPGRADE_MAX_TX_SET_SIZE = 1000;
config.LEDGER_PROTOCOL_VERSION =
Config::CURRENT_LEDGER_PROTOCOL_VERSION;

ParserWithValidation ledgerMaxTransactionsSizeBytesParser{
clara::Opt(ledgerMaxTransactionsSizeBytes,
"LedgerMaxTransactionsSizeBytes")["--ledger-max-tx-size"]
.required(),
[&] {
return ledgerMaxTransactionsSizeBytes > 0
? ""
: "ledgerMaxTransactionsSizeBytes must be > 0";
}};
TmpDirManager tdm(std::string("soroban-storage-meta-"));
TmpDir td = tdm.tmpDir("soroban-meta-ok");
std::string metaPath = td.getName() + "/stream.xdr";

return runWithHelp(
args,
{configurationParser(configOption), ledgerMaxInstructionsParser,
ledgerMaxReadLedgerEntriesParser, ledgerMaxReadBytesParser,
ledgerMaxWriteLedgerEntriesParser, ledgerMaxWriteBytesParser,
ledgerMaxTxCountParser, ledgerMaxTransactionsSizeBytesParser},
[&] {
auto config = configOption.getConfig();
config.RUN_STANDALONE = true;
config.MANUAL_CLOSE = true;
config.USE_CONFIG_FOR_GENESIS = true;
config.TESTING_UPGRADE_MAX_TX_SET_SIZE = 1000;
config.LEDGER_PROTOCOL_VERSION =
Config::CURRENT_LEDGER_PROTOCOL_VERSION;
config.METADATA_OUTPUT_STREAM = metaPath;

VirtualClock clock(VirtualClock::REAL_TIME);
auto appPtr = Application::create(clock, config);

auto& app = *appPtr;
{
app.start();
VirtualClock clock(VirtualClock::REAL_TIME);
auto appPtr = Application::create(clock, config);

ApplyLoad al(app, ledgerMaxInstructions,
ledgerMaxReadLedgerEntries, ledgerMaxReadBytes,
ledgerMaxWriteLedgerEntries, ledgerMaxWriteBytes,
ledgerMaxTxCount, ledgerMaxTransactionsSizeBytes);
auto& app = *appPtr;
{
app.start();

auto& ledgerClose =
app.getMetrics().NewTimer({"ledger", "ledger", "close"});
ledgerClose.Clear();
ApplyLoad al(app);

auto& cpuInsRatio = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op",
"invoke-time-fsecs-cpu-insn-ratio"});
cpuInsRatio.Clear();
auto& ledgerClose =
app.getMetrics().NewTimer({"ledger", "ledger", "close"});
ledgerClose.Clear();

auto& cpuInsRatioExclVm = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op",
"invoke-time-fsecs-cpu-insn-ratio-excl-vm"});
cpuInsRatioExclVm.Clear();
auto& cpuInsRatio = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op", "invoke-time-fsecs-cpu-insn-ratio"});
cpuInsRatio.Clear();

auto& ledgerCpuInsRatio = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op", "ledger-cpu-insns-ratio"});
ledgerCpuInsRatio.Clear();
auto& cpuInsRatioExclVm = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op",
"invoke-time-fsecs-cpu-insn-ratio-excl-vm"});
cpuInsRatioExclVm.Clear();

auto& ledgerCpuInsRatioExclVm = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op",
"ledger-cpu-insns-ratio-excl-vm"});
ledgerCpuInsRatioExclVm.Clear();
auto& ledgerCpuInsRatio = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op", "ledger-cpu-insns-ratio"});
ledgerCpuInsRatio.Clear();

for (size_t i = 0; i < 100; ++i)
{
app.getBucketManager().getBucketList().resolveAllFutures();
releaseAssert(app.getBucketManager()
.getBucketList()
.futuresAllResolved());
al.benchmark();
}
auto& ledgerCpuInsRatioExclVm = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op", "ledger-cpu-insns-ratio-excl-vm"});
ledgerCpuInsRatioExclVm.Clear();

CLOG_INFO(Perf, "Max ledger close: {} milliseconds",
ledgerClose.max());
CLOG_INFO(Perf, "Min ledger close: {} milliseconds",
ledgerClose.min());
CLOG_INFO(Perf, "Mean ledger close: {} milliseconds",
ledgerClose.mean());
CLOG_INFO(Perf, "stddev ledger close: {} milliseconds",
ledgerClose.std_dev());

CLOG_INFO(Perf, "Max CPU ins ratio: {}",
cpuInsRatio.max() / 1000000);
CLOG_INFO(Perf, "Mean CPU ins ratio: {}",
cpuInsRatio.mean() / 1000000);

CLOG_INFO(Perf, "Max CPU ins ratio excl VM: {}",
cpuInsRatioExclVm.max() / 1000000);
CLOG_INFO(Perf, "Mean CPU ins ratio excl VM: {}",
cpuInsRatioExclVm.mean() / 1000000);
CLOG_INFO(Perf, "stddev CPU ins ratio excl VM: {}",
cpuInsRatioExclVm.std_dev() / 1000000);

CLOG_INFO(Perf, "Ledger Max CPU ins ratio: {}",
ledgerCpuInsRatio.max() / 1000000);
CLOG_INFO(Perf, "Ledger Mean CPU ins ratio: {}",
ledgerCpuInsRatio.mean() / 1000000);
CLOG_INFO(Perf, "Ledger stddev CPU ins ratio: {}",
ledgerCpuInsRatio.std_dev() / 1000000);

CLOG_INFO(Perf, "Ledger Max CPU ins ratio excl VM: {}",
ledgerCpuInsRatioExclVm.max() / 1000000);
CLOG_INFO(Perf, "Ledger Mean CPU ins ratio excl VM: {}",
ledgerCpuInsRatioExclVm.mean() / 1000000);
CLOG_INFO(
Perf,
"Ledger stddev CPU ins ratio excl VM: {} milliseconds",
ledgerCpuInsRatioExclVm.std_dev() / 1000000);

CLOG_INFO(Perf, "Tx count utilization {}%",
al.getTxCountUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Instruction utilization {}%",
al.getInstructionUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Tx size utilization {}%",
al.getTxSizeUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Read bytes utilization {}%",
al.getReadByteUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Write bytes utilization {}%",
al.getWriteByteUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Read entry utilization {}%",
al.getReadEntryUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Write entry utilization {}%",
al.getWriteEntryUtilization().mean() / 1000.0);

CLOG_INFO(Perf, "Tx Success Rate: {:f}%",
al.successRate() * 100);
for (size_t i = 0; i < 100; ++i)
{
app.getBucketManager().getBucketList().resolveAllFutures();
releaseAssert(app.getBucketManager()
.getBucketList()
.futuresAllResolved());
al.benchmark();
}

return 0;
});
CLOG_INFO(Perf, "Max ledger close: {} milliseconds",
ledgerClose.max());
CLOG_INFO(Perf, "Min ledger close: {} milliseconds",
ledgerClose.min());
CLOG_INFO(Perf, "Mean ledger close: {} milliseconds",
ledgerClose.mean());
CLOG_INFO(Perf, "stddev ledger close: {} milliseconds",
ledgerClose.std_dev());

CLOG_INFO(Perf, "Max CPU ins ratio: {}",
cpuInsRatio.max() / 1000000);
CLOG_INFO(Perf, "Mean CPU ins ratio: {}",
cpuInsRatio.mean() / 1000000);

CLOG_INFO(Perf, "Max CPU ins ratio excl VM: {}",
cpuInsRatioExclVm.max() / 1000000);
CLOG_INFO(Perf, "Mean CPU ins ratio excl VM: {}",
cpuInsRatioExclVm.mean() / 1000000);
CLOG_INFO(Perf, "stddev CPU ins ratio excl VM: {}",
cpuInsRatioExclVm.std_dev() / 1000000);

CLOG_INFO(Perf, "Ledger Max CPU ins ratio: {}",
ledgerCpuInsRatio.max() / 1000000);
CLOG_INFO(Perf, "Ledger Mean CPU ins ratio: {}",
ledgerCpuInsRatio.mean() / 1000000);
CLOG_INFO(Perf, "Ledger stddev CPU ins ratio: {}",
ledgerCpuInsRatio.std_dev() / 1000000);

CLOG_INFO(Perf, "Ledger Max CPU ins ratio excl VM: {}",
ledgerCpuInsRatioExclVm.max() / 1000000);
CLOG_INFO(Perf, "Ledger Mean CPU ins ratio excl VM: {}",
ledgerCpuInsRatioExclVm.mean() / 1000000);
CLOG_INFO(Perf,
"Ledger stddev CPU ins ratio excl VM: {} milliseconds",
ledgerCpuInsRatioExclVm.std_dev() / 1000000);

CLOG_INFO(Perf, "Tx count utilization {}%",
al.getTxCountUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Instruction utilization {}%",
al.getInstructionUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Tx size utilization {}%",
al.getTxSizeUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Read bytes utilization {}%",
al.getReadByteUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Write bytes utilization {}%",
al.getWriteByteUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Read entry utilization {}%",
al.getReadEntryUtilization().mean() / 1000.0);
CLOG_INFO(Perf, "Write entry utilization {}%",
al.getWriteEntryUtilization().mean() / 1000.0);

CLOG_INFO(Perf, "Tx Success Rate: {:f}%", al.successRate() * 100);
}

return 0;
});
}
#endif

Expand Down
63 changes: 63 additions & 0 deletions src/main/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,69 @@ Config::processConfig(std::shared_ptr<cpptoml::table> t)
APPLY_LOAD_EVENT_COUNT_DISTRIBUTION_FOR_TESTING =
readIntArray<uint32>(item);
}},
{"APPLY_LOAD_LEDGER_MAX_INSTRUCTIONS",
[&]() {
APPLY_LOAD_LEDGER_MAX_INSTRUCTIONS =
readInt<uint32_t>(item);
}},
{"APPLY_LOAD_TX_MAX_INSTRUCTIONS",
[&]() {
APPLY_LOAD_TX_MAX_INSTRUCTIONS = readInt<uint32_t>(item);
}},
{"APPLY_LOAD_LEDGER_MAX_READ_LEDGER_ENTRIES",
[&]() {
APPLY_LOAD_LEDGER_MAX_READ_LEDGER_ENTRIES =
readInt<uint32_t>(item);
}},
{"APPLY_LOAD_TX_MAX_READ_LEDGER_ENTRIES",
[&]() {
APPLY_LOAD_TX_MAX_READ_LEDGER_ENTRIES =
readInt<uint32_t>(item);
}},
{"APPLY_LOAD_LEDGER_MAX_WRITE_LEDGER_ENTRIES",
[&]() {
APPLY_LOAD_LEDGER_MAX_WRITE_LEDGER_ENTRIES =
readInt<uint32_t>(item);
}},
{"APPLY_LOAD_TX_MAX_WRITE_LEDGER_ENTRIES",
[&]() {
APPLY_LOAD_TX_MAX_WRITE_LEDGER_ENTRIES =
readInt<uint32_t>(item);
}},
{"APPLY_LOAD_LEDGER_MAX_READ_BYTES",
[&]() {
APPLY_LOAD_LEDGER_MAX_READ_BYTES = readInt<uint32_t>(item);
}},
{"APPLY_LOAD_TX_MAX_READ_BYTES",
[&]() {
APPLY_LOAD_TX_MAX_READ_BYTES = readInt<uint32_t>(item);
}},
{"APPLY_LOAD_LEDGER_MAX_WRITE_BYTES",
[&]() {
APPLY_LOAD_LEDGER_MAX_WRITE_BYTES =
readInt<uint32_t>(item);
}},
{"APPLY_LOAD_TX_MAX_WRITE_BYTES",
[&]() {
APPLY_LOAD_TX_MAX_WRITE_BYTES = readInt<uint32_t>(item);
}},
{"APPLY_LOAD_MAX_TX_SIZE_BYTES",
[&]() {
APPLY_LOAD_MAX_TX_SIZE_BYTES = readInt<uint32_t>(item);
}},
{"APPLY_LOAD_MAX_LEDGER_TX_SIZE_BYTES",
[&]() {
APPLY_LOAD_MAX_LEDGER_TX_SIZE_BYTES =
readInt<uint32_t>(item);
}},
{"APPLY_LOAD_MAX_CONTRACT_EVENT_SIZE_BYTES",
[&]() {
APPLY_LOAD_MAX_CONTRACT_EVENT_SIZE_BYTES =
readInt<uint32_t>(item);
}},
{"APPLY_LOAD_MAX_TX_COUNT",
[&]() { APPLY_LOAD_MAX_TX_COUNT = readInt<uint32_t>(item); }},

{"CATCHUP_WAIT_MERGES_TX_APPLY_FOR_TESTING",
[&]() {
CATCHUP_WAIT_MERGES_TX_APPLY_FOR_TESTING = readBool(item);
Expand Down
21 changes: 21 additions & 0 deletions src/main/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,27 @@ class Config : public std::enable_shared_from_this<Config>
// `APPLY_LOAD_BL_LAST_BATCH_LEDGERS`.
uint32_t APPLY_LOAD_BL_LAST_BATCH_SIZE = 100;

uint32_t APPLY_LOAD_LEDGER_MAX_INSTRUCTIONS = 0;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add comments and clear error messages for misconfiguration.

uint32_t APPLY_LOAD_TX_MAX_INSTRUCTIONS = 0;

uint32_t APPLY_LOAD_LEDGER_MAX_READ_LEDGER_ENTRIES = 0;
uint32_t APPLY_LOAD_TX_MAX_READ_LEDGER_ENTRIES = 0;

uint32_t APPLY_LOAD_LEDGER_MAX_WRITE_LEDGER_ENTRIES = 0;
uint32_t APPLY_LOAD_TX_MAX_WRITE_LEDGER_ENTRIES = 0;

uint32_t APPLY_LOAD_LEDGER_MAX_READ_BYTES = 0;
uint32_t APPLY_LOAD_TX_MAX_READ_BYTES = 0;

uint32_t APPLY_LOAD_LEDGER_MAX_WRITE_BYTES = 0;
uint32_t APPLY_LOAD_TX_MAX_WRITE_BYTES = 0;

uint32_t APPLY_LOAD_MAX_TX_SIZE_BYTES = 0;
uint32_t APPLY_LOAD_MAX_LEDGER_TX_SIZE_BYTES = 0;

uint32_t APPLY_LOAD_MAX_CONTRACT_EVENT_SIZE_BYTES = 0;
uint32_t APPLY_LOAD_MAX_TX_COUNT = 0;

// Number of read-only and read-write entries in the apply-load
// transactions. Every entry will have
// `APPLY_LOAD_DATA_ENTRY_SIZE_FOR_TESTING` size.
Expand Down
Loading