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

Soroban metrics improvement #4175

Merged
merged 7 commits into from
Feb 1, 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
92 changes: 51 additions & 41 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ loadgen.soroban.setup_invoke | meter | loadgenerator: soroban s
loadgen.soroban.setup_upgrade | meter | loadgenerator: soroban setup upgrades TXs submitted
loadgen.soroban.upload | meter | loadgenerator: soroban upload TXs submitted
loadgen.step.count | meter | loadgenerator: generated some transactions
loadgen.step.submit | timer | loadgenerator: time spent submiting transactions per step
loadgen.step.submit | timer | loadgenerator: time spent submitting transactions per step
loadgen.txn.attempted | meter | loadgenerator: transaction submitted
loadgen.txn.bytes | meter | loadgenerator: size of transactions submitted
loadgen.txn.rejected | meter | loadgenerator: transaction rejected
Expand Down Expand Up @@ -162,43 +162,53 @@ state-archival.eviction.bytes-scanned | counter | number of bytes that evi
state-archival.eviction.entries-evicted | counter | number of entries that have been evicted
state-archival.eviction.incomplete-scan | counter | number of buckets that were too large to be fully scanned for eviction
state-archival.eviction.period | counter | number of ledgers to complete an eviction scan
soroban.host-fn-op.read-entry | meter | number of entries read
soroban.host-fn-op.write-entry | meter | number of entries written
soroban.host-fn-op.read-key-byte | meter | number of key bytes in read entries
soroban.host-fn-op.write-key-byte | meter | number of key bytes in written entries
soroban.host-fn-op.read-ledger-byte | meter | number of data + code bytes in read entries
soroban.host-fn-op.read-data-byte | meter | number of data bytes in read entries
soroban.host-fn-op.read-code-byte | meter | number of code bytes in read entries
soroban.host-fn-op.write-ledger-byte | meter | number of data + code bytes in written entries
soroban.host-fn-op.write-data-byte | meter | number of data bytes in written entries
soroban.host-fn-op.write-code-byte | meter | number of code bytes in written entries
soroban.host-fn-op.emit-event | meter | number of events emitted
soroban.host-fn-op.emit-event-byte | meter | number of event bytes emitted
soroban.host-fn-op.cpu-insn | meter | metered cpu instructions
soroban.host-fn-op.mem-byte | meter | metered memory bytes
soroban.host-fn-op.invoke-time-nsecs | meter | time [nsecs] spent in `invoke_host_function`
soroban.host-fn-op.cpu-insn-excl-vm | meter | metered cpu instructions excluding VM instantation
soroban.host-fn-op.invoke-time-nsecs-excl-vm | meter | time [nsecs] spent in `invoke_host_function` excluding VM instantation
soroban.host-fn-op.max-rw-key-byte | meter | bytes of the largest key in entries read/written
soroban.host-fn-op.max-rw-data-byte | meter | bytes of the largest data entry read/written
soroban.host-fn-op.max-rw-code-byte | meter | bytes of the largest code entry read/written
soroban.host-fn-op.max-emit-event-byte | meter | bytes of the largest event emitted
soroban.host-fn-op.success | meter | if `InvokeHostFunctionOp` results in a success
soroban.host-fn-op.failure | meter | if `InvokeHostFunctionOp` results in a failure
soroban.host-fn-op.exec | timer | time spent in `InvokeHostFunctionOp`
soroban.config.contract-max-size-bytes | meter | soroban config setting `contract_max_size_bytes`
soroban.config.ledger-max-instructions | meter | soroban config setting `ledger_max_instructions`
soroban.config.tx-max-instructions | meter | soroban config setting `tx_max_instructions`
soroban.config.tx-memory-limit | meter | soroban config setting `tx_memory_limit`
soroban.config.ledger-max-read-ledger-entries | meter | soroban config setting `ledger_max_read_ledger_entries`
soroban.config.ledger-max-read-bytes | meter | soroban config setting `ledger_max_read_bytes`
soroban.config.ledger-max-write-ledger-entries | meter | soroban config setting `ledger_max_write_ledger_entries`
soroban.config.ledger-max-write-bytes | meter | soroban config setting `ledger_max_write_bytes`
soroban.config.tx-max-read-ledger-entries | meter | soroban config setting `tx_max_read_ledger_entries`
soroban.config.tx-max-read-bytes | meter | soroban config setting `tx_max_read_bytes`
soroban.config.tx-max-write-ledger-entries | meter | soroban config setting `tx_max_write_ledger_entries`
soroban.config.tx-max-write-bytes | meter | soroban config setting `tx_max_write_bytes`
soroban.config.bucket-list-target-size-bytes | meter | soroban config setting `bucket_list_target_size_bytes`
soroban.config.tx-max-contract-events-size-bytes | meter | soroban config setting `tx_max_contract_events_size_bytes`
soroban.config.contract-data-key-size-bytes | meter | soroban config setting `contract_data_key_size_bytes`
soroban.config.contract-data-entry-size-bytes | meter | soroban config setting `contract_data_entry_size_bytes`
soroban.host-fn-op.read-entry | meter | number of entries accessed (read or modified) during the `InvokeHostFunctionOp`
soroban.host-fn-op.write-entry | meter | number of entries modified during the `InvokeHostFunctionOp`
soroban.host-fn-op.read-key-byte | meter | number of `LedgerKey` bytes in entries accessed (read or modified) during the `InvokeHostFunctionOp`
soroban.host-fn-op.write-key-byte | meter | number of `LedgerKey` bytes in entries modified during the `InvokeHostFunctionOp`
soroban.host-fn-op.read-ledger-byte | meter | number of `LedgerEntry` bytes accessed (read or modified) during the `InvokeHostFunctionOp`
soroban.host-fn-op.read-data-byte | meter | number of `ContractDataEntry` bytes accessed (read or modified) during the `InvokeHostFunctionOp`
soroban.host-fn-op.read-code-byte | meter | number of `ContractCodeEntry` bytes accessed (read or modified) during the `InvokeHostFunctionOp`
soroban.host-fn-op.write-ledger-byte | meter | number of `LedgerEntry` bytes modified during the `InvokeHostFunctionOp`
soroban.host-fn-op.write-data-byte | meter | number of `ContractDataEntry` bytes modified during the `InvokeHostFunctionOp`
soroban.host-fn-op.write-code-byte | meter | number of `ContractCodeEntry` bytes modified during the `InvokeHostFunctionOp`
soroban.host-fn-op.emit-event | meter | number of events emitted during the `InvokeHostFunctionOp`
soroban.host-fn-op.emit-event-byte | meter | number of event bytes emitted during the `InvokeHostFunctionOp`
soroban.host-fn-op.cpu-insn | meter | number of metered cpu instructions during the `InvokeHostFunctionOp`
soroban.host-fn-op.mem-byte | meter | number of metered memory bytes during the `InvokeHostFunctionOp`
soroban.host-fn-op.invoke-time-nsecs | timer | time spent on the soroban host invocation. Note: this is **not** the total time of the operation, which is tracked under "soroban.host-fn-op.exec".
soroban.host-fn-op.cpu-insn-excl-vm | meter | number of metered cpu instructions excluding VM instantiation during the `InvokeHostFunctionOp`
soroban.host-fn-op.invoke-time-nsecs-excl-vm | timer | time spent in soroban host invocation excluding VM instantiation
soroban.host-fn-op.invoke-time-fsecs-cpu-insn-ratio | histogram | ratio between soroban host invocation time (femto-seconds) and metered cpu instructions
soroban.host-fn-op.invoke-time-fsecs-cpu-insn-ratio-excl-vm | histogram | ratio between soroban host invocation time (femto-seconds) and metered cpu instructions, excluding VM instantiation
soroban.host-fn-op.max-rw-key-byte | meter | size of the largest `LedgerKey` (in bytes) among all entires accessed (read or modified) during the `InvokeHostFunctionOp`
soroban.host-fn-op.max-rw-data-byte | meter | size of the largest `ContractDataEntry` (in bytes) among all entires accessed (read or modified) during the `InvokeHostFunctionOp`
soroban.host-fn-op.max-rw-code-byte | meter | size of the largest `ContractCodeEntry` (in bytes) among all entires accessed (read or modified) during the `InvokeHostFunctionOp`
soroban.host-fn-op.max-emit-event-byte | meter | size of the largest event emitted during the `InvokeHostFunctionOp`
soroban.host-fn-op.success | meter | number of successful `InvokeHostFunctionOp` operations
soroban.host-fn-op.failure | meter | number of failed `InvokeHostFunctionOp` operations
soroban.host-fn-op.exec | timer | total time spent during the `InvokeHostFunctionOp`
soroban.restore-fprint-op.read-ledger-byte | meter | number of `LedgerEntry` bytes accessed (read or modified) during the `RestoreFootprintOp`
soroban.restore-fprint-op.write-ledger-byte | meter | number of `LedgerEntry` bytes modified during the `RestoreFootprintOp`
soroban.ext-fprint-ttl-op.read-ledger-byte | meter | number of `LedgerEntry` bytes accessed (read or modified) during the `ExtendFootprintTTLOp`
soroban.ledger.cpu-insn | histogram | metered cpu instructions per ledger
soroban.ledger.read-entry | histogram | number of entries accessed (read or modified) per ledger
soroban.ledger.read-ledger-byte | histogram | number of `LedgerEntry` bytes accessed (read or modified) per ledger
soroban.ledger.write-entry | histogram | number of entries modified per ledger
soroban.ledger.write-ledger-byte | histogram | number of `LedgerEntry` bytes modified per ledger
soroban.config.contract-max-rw-key-byte | counter | soroban config setting `contract_data_key_size_bytes`
soroban.config.contract-max-rw-data-byte | counter | soroban config setting `contract_data_entry_size_bytes`
soroban.config.contract-max-rw-code-byte | counter | soroban config setting `contract_max_size_bytes`
soroban.config.tx-max-cpu-insn | counter | soroban config setting `tx_max_instructions`
soroban.config.tx-max-mem-byte | counter | soroban config setting `tx_memory_limit`
soroban.config.tx-max-read-entry | counter | soroban config setting `tx_max_read_ledger_entries`
soroban.config.tx-max-read-ledger-byte | counter | soroban config setting `tx_max_read_bytes`
soroban.config.tx-max-write-entry | counter | soroban config setting `tx_max_write_ledger_entries`
soroban.config.tx-max-write-ledger-byte | counter | soroban config setting `tx_max_write_bytes`
soroban.config.tx-max-emit-event-byte | counter | soroban config setting `tx_max_contract_events_size_bytes`
soroban.config.ledger-max-cpu-insn | counter | soroban config setting `ledger_max_instructions`
soroban.config.ledger-max-read-entry | counter | soroban config setting `ledger_max_read_ledger_entries`
soroban.config.ledger-max-read-ledger-byte | counter | soroban config setting `ledger_max_read_bytes`
soroban.config.ledger-max-write-entry | counter | soroban config setting `ledger_max_write_ledger_entries`
soroban.config.ledger-max-write-ledger-byte | counter | soroban config setting `ledger_max_write_bytes`
soroban.config.bucket-list-target-size-byte | counter | soroban config setting `bucket_list_target_size_bytes`
3 changes: 3 additions & 0 deletions src/ledger/LedgerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace stellar

class LedgerCloseData;
class Database;
class SorobanLedgerMetrics;

/**
* LedgerManager maintains, in memory, a logical pair of ledgers:
Expand Down Expand Up @@ -187,6 +188,8 @@ class LedgerManager

virtual void manuallyAdvanceLedgerHeader(LedgerHeader const& header) = 0;

virtual SorobanLedgerMetrics& getSorobanMetrics() = 0;

virtual ~LedgerManager()
{
}
Expand Down
146 changes: 98 additions & 48 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,58 @@ const uint32_t LedgerManager::GENESIS_LEDGER_BASE_RESERVE = 100000000;
const uint32_t LedgerManager::GENESIS_LEDGER_MAX_TX_SIZE = 100;
const int64_t LedgerManager::GENESIS_LEDGER_TOTAL_COINS = 1000000000000000000;

void
SorobanLedgerMetrics::accumulateLedgerCpuInsn(uint64_t cpuInsn)
{
mLedgerCpuInsn += cpuInsn;
}
void
SorobanLedgerMetrics::accumulateLedgerReadEntry(uint64_t readEntry)
{
mLedgerReadEntry += readEntry;
}
void
SorobanLedgerMetrics::accumulateLedgerReadByte(uint64_t readByte)
{
mLedgerReadByte += readByte;
}
void
SorobanLedgerMetrics::accumulateLedgerWriteEntry(uint64_t writeEntry)
{
mLedgerWriteEntry += writeEntry;
}
void
SorobanLedgerMetrics::accumulateLedgerWriteByte(uint64_t writeByte)
{
mLedgerWriteByte += writeByte;
}

void
SorobanLedgerMetrics::publishAndResetMetrics()
{
mMetrics.NewHistogram({"soroban", "ledger", "cpu-insn"})
.Update(mLedgerCpuInsn);
mMetrics.NewHistogram({"soroban", "ledger", "read-entry"})
.Update(mLedgerReadEntry);
mMetrics.NewHistogram({"soroban", "ledger", "read-ledger-byte"})
.Update(mLedgerReadByte);
mMetrics.NewHistogram({"soroban", "ledger", "write-entry"})
.Update(mLedgerWriteEntry);
mMetrics.NewHistogram({"soroban", "ledger", "write-ledger-byte"})
.Update(mLedgerWriteByte);
mLedgerCpuInsn = 0;
mLedgerReadEntry = 0;
mLedgerReadByte = 0;
mLedgerWriteEntry = 0;
mLedgerWriteByte = 0;
}

medida::MetricsRegistry&
SorobanLedgerMetrics::registry() const
{
return mMetrics;
}

std::unique_ptr<LedgerManager>
LedgerManager::create(Application& app)
{
Expand Down Expand Up @@ -128,6 +180,7 @@ LedgerManager::ledgerAbbrev(LedgerHeaderHistoryEntry const& he)

LedgerManagerImpl::LedgerManagerImpl(Application& app)
: mApp(app)
, mSorobanLedgerMetrics(app.getMetrics())
, mTransactionApply(
app.getMetrics().NewTimer({"ledger", "transaction", "apply"}))
, mTransactionCount(
Expand Down Expand Up @@ -554,12 +607,19 @@ LedgerManagerImpl::getMutableSorobanNetworkConfig()
}
#endif

SorobanLedgerMetrics&
LedgerManagerImpl::getSorobanMetrics()
{
return mSorobanLedgerMetrics;
}

void
LedgerManagerImpl::publishSorobanNetworkConfigMetrics()
LedgerManagerImpl::publishSorobanMetrics()
{
releaseAssert(mSorobanNetworkConfig);
medida::MetricsRegistry& metrics = mApp.getMetrics();
medida::MetricsRegistry& registry = mSorobanLedgerMetrics.registry();

// first publish the network config limits
auto contractMaxSizeBytes = mSorobanNetworkConfig->maxContractSizeBytes();
auto ledgerMaxInstructions = mSorobanNetworkConfig->ledgerMaxInstructions();
auto txMaxInstructions = mSorobanNetworkConfig->txMaxInstructions();
Expand All @@ -585,51 +645,41 @@ LedgerManagerImpl::publishSorobanNetworkConfigMetrics()
auto contractDataEntrySizeBytes =
mSorobanNetworkConfig->maxContractDataEntrySizeBytes();

metrics.NewMeter({"soroban", "config", "contract-max-size-bytes"}, "byte")
.Mark(contractMaxSizeBytes);
metrics.NewMeter({"soroban", "config", "ledger-max-instructions"}, "insn")
.Mark(ledgerMaxInstructions);
metrics.NewMeter({"soroban", "config", "tx-max-instructions"}, "insn")
.Mark(txMaxInstructions);
metrics.NewMeter({"soroban", "config", "tx-memory-limit"}, "byte")
.Mark(txMemoryLimit);
metrics
.NewMeter({"soroban", "config", "ledger-max-read-ledger-entries"},
"entry")
.Mark(ledgerMaxReadLedgerEntries);
metrics.NewMeter({"soroban", "config", "ledger-max-read-bytes"}, "byte")
.Mark(ledgerMaxReadBytes);
metrics
.NewMeter({"soroban", "config", "ledger-max-write-ledger-entries"},
"entry")
.Mark(ledgerMaxWriteLedgerEntries);
metrics.NewMeter({"soroban", "config", "ledger-max-write-bytes"}, "byte")
.Mark(ledgerMaxWriteBytes);
metrics
.NewMeter({"soroban", "config", "tx-max-read-ledger-entries"}, "entry")
.Mark(txMaxReadLedgerEntries);
metrics.NewMeter({"soroban", "config", "tx-max-read-bytes"}, "byte")
.Mark(txMaxReadBytes);
metrics
.NewMeter({"soroban", "config", "tx-max-write-ledger-entries"}, "entry")
.Mark(txMaxWriteLedgerEntries);
metrics.NewMeter({"soroban", "config", "tx-max-write-bytes"}, "byte")
.Mark(txMaxWriteBytes);
metrics
.NewMeter({"soroban", "config", "bucket-list-target-size-bytes"},
"byte")
.Mark(bucketListTargetSizeBytes);
metrics
.NewMeter({"soroban", "config", "tx-max-contract-events-size-bytes"},
"byte")
.Mark(txMaxContractEventsSizeBytes);
metrics
.NewMeter({"soroban", "config", "contract-data-key-size-bytes"}, "byte")
.Mark(contractDataKeySizeBytes);
metrics
.NewMeter({"soroban", "config", "contract-data-entry-size-bytes"},
"byte")
.Mark(contractDataEntrySizeBytes);
registry.NewCounter({"soroban", "config", "contract-max-rw-key-byte"})
.set_count(contractDataKeySizeBytes);
registry.NewCounter({"soroban", "config", "contract-max-rw-data-byte"})
.set_count(contractDataEntrySizeBytes);
registry.NewCounter({"soroban", "config", "contract-max-rw-code-byte"})
.set_count(contractMaxSizeBytes);
registry.NewCounter({"soroban", "config", "tx-max-cpu-insn"})
.set_count(txMaxInstructions);
registry.NewCounter({"soroban", "config", "tx-max-mem-byte"})
.set_count(txMemoryLimit);
registry.NewCounter({"soroban", "config", "tx-max-read-entry"})
.set_count(txMaxReadLedgerEntries);
registry.NewCounter({"soroban", "config", "tx-max-read-ledger-byte"})
.set_count(txMaxReadBytes);
registry.NewCounter({"soroban", "config", "tx-max-write-entry"})
.set_count(txMaxWriteLedgerEntries);
registry.NewCounter({"soroban", "config", "tx-max-write-ledger-byte"})
.set_count(txMaxWriteBytes);
registry.NewCounter({"soroban", "config", "tx-max-emit-event-byte"})
.set_count(txMaxContractEventsSizeBytes);
registry.NewCounter({"soroban", "config", "ledger-max-cpu-insn"})
.set_count(ledgerMaxInstructions);
registry.NewCounter({"soroban", "config", "ledger-max-read-entry"})
.set_count(ledgerMaxReadLedgerEntries);
registry.NewCounter({"soroban", "config", "ledger-max-read-ledger-byte"})
.set_count(ledgerMaxReadBytes);
registry.NewCounter({"soroban", "config", "ledger-max-write-entry"})
.set_count(ledgerMaxWriteLedgerEntries);
registry.NewCounter({"soroban", "config", "ledger-max-write-ledger-byte"})
.set_count(ledgerMaxWriteBytes);
registry.NewCounter({"soroban", "config", "bucket-list-target-size-byte"})
.set_count(bucketListTargetSizeBytes);

// then publish the actual ledger usage
mSorobanLedgerMetrics.publishAndResetMetrics();
}

// called by txherder
Expand Down Expand Up @@ -1306,7 +1356,7 @@ LedgerManagerImpl::updateNetworkConfig(AbstractLedgerTxn& rootLtx)
mSorobanNetworkConfig->loadFromLedger(
rootLtx, mApp.getConfig().CURRENT_LEDGER_PROTOCOL_VERSION,
ledgerVersion);
publishSorobanNetworkConfigMetrics();
publishSorobanMetrics();
}
else
{
Expand Down
Loading