Get TPS (Transactions Per Second)
The Get TPS
tool, part of AgentiPy, is used to fetch and analyze Transactions Per Second (TPS) data from the Solana blockchain. It can retrieve current TPS and also track performance metrics over time.
Functionality
The tool consists of a standalone function fetch_performance_samples
and a class SolanaPerformanceTracker
.
Key Functions/Classes:
fetch_performance_samples(agent: SolanaAgentKit, sample_count: int = 1) -> List[NetworkPerformanceMetrics]
:Asynchronously fetches a specified number of recent performance samples from the Solana network using
agent.connection.get_recent_performance_samples()
.Each sample contains data like the number of transactions and the sample period.
Converts these samples into a list of
NetworkPerformanceMetrics
objects, which include calculated TPS, total transactions, sampling period, and current slot.
SolanaPerformanceTracker
:__init__(self, agent: SolanaAgentKit)
: Initializes the tracker with aSolanaAgentKit
instance.record_latest_metrics(self) -> NetworkPerformanceMetrics
: Fetches the single latest performance sample usingfetch_performance_samples
and stores it in an internalmetrics_history
.calculate_average_tps(self) -> Optional[float]
: Calculates the average TPS from all metrics stored inmetrics_history
.find_maximum_tps(self) -> Optional[float]
: Finds the maximum TPS from themetrics_history
.reset_metrics_history(self) -> None
: Clears themetrics_history
.fetch_current_tps(agent: SolanaAgentKit) -> float
(static method): A static method to quickly fetch the current TPS based on the latest single performance sample. This is likely the most commonly used function for a quick TPS check.
Source Code
You can find the source code for this tool on GitHub: https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/get_tps.py
Last updated