Parameters

limit
number

Number of samples to return (default: 720)

Response

result
array

Array of performance sample objects

slot
number

Slot number

numSlots
number

Number of slots in the sample

numTransactions
number

Number of transactions in the sample

samplePeriodSecs
number

Sample period in seconds

numNonVoteTransaction
number

Number of non-vote transactions

Code Examples

Basic Request

curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getRecentPerformanceSamples",
  "params": []
}'

Request with Limit

curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getRecentPerformanceSamples",
  "params": [
    100
  ]
}'

Using web3.js

import { Connection } from '@solana/web3.js';

const connection = new Connection('https://rpc.orbitflare.com');

// Get recent performance samples
const samples = await connection.getRecentPerformanceSamples();
console.log('Performance samples:', samples);

// Calculate average TPS
function calculateAverageTPS(samples: any[]): number {
  const totalTransactions = samples.reduce(
    (sum, sample) => sum + sample.numTransactions,
    0
  );
  const totalSeconds = samples.reduce(
    (sum, sample) => sum + sample.samplePeriodSecs,
    0
  );
  return totalTransactions / totalSeconds;
}

Notes

  1. Returns recent performance samples from the network
  2. Each sample covers a period of time (typically 60 seconds)
  3. Samples include transaction counts and slot information
  4. The response is immediate as it reads from the current state
  5. The default limit is 720 samples (approximately 12 hours)

Best Practices

  1. Use appropriate limit based on your analysis needs
  2. Cache results when appropriate to reduce RPC load
  3. Monitor for significant changes in performance
  4. Consider using websocket subscription for real-time updates
  5. Handle network errors and retry when appropriate

Common Errors

CodeMessageSolution
-32601Method not foundVerify you’re connected to a Solana RPC node
-32602Invalid paramsCheck limit parameter
-32007Performance samples unavailableNode may be bootstrapping or syncing

Use Cases

  1. Performance Analysis

    interface PerformanceMetrics {
      averageTPS: number;
      peakTPS: number;
      totalTransactions: number;
      totalSlots: number;
      metadata: {
        timestamp: number;
        sampleCount: number;
      };
    }
    
    async function analyzePerformance(
      limit: number = 720
    ): Promise<PerformanceMetrics> {
      const samples = await connection.getRecentPerformanceSamples(limit);
      
      const totalTransactions = samples.reduce(
        (sum, sample) => sum + sample.numTransactions,
        0
      );
      const totalSeconds = samples.reduce(
        (sum, sample) => sum + sample.samplePeriodSecs,
        0
      );
      const peakTPS = Math.max(
        ...samples.map(sample => sample.numTransactions / sample.samplePeriodSecs)
      );
      
      return {
        averageTPS: totalTransactions / totalSeconds,
        peakTPS,
        totalTransactions,
        totalSlots: samples.reduce((sum, sample) => sum + sample.numSlots, 0),
        metadata: {
          timestamp: Date.now(),
          sampleCount: samples.length
        }
      };
    }
    
  2. Performance Monitoring

    interface PerformanceAlert {
      type: 'high_tps' | 'low_tps' | 'anomaly';
      currentTPS: number;
      threshold: number;
      metadata: {
        timestamp: number;
        slot: number;
      };
    }
    
    class PerformanceMonitor {
      private previousTPS: number | null = null;
      private readonly threshold = 0.2; // 20% change threshold
      
      async monitorPerformance(
        interval: number = 60000
      ): Promise<PerformanceAlert | null> {
        const samples = await connection.getRecentPerformanceSamples(1);
        const currentSample = samples[0];
        const currentTPS = currentSample.numTransactions / currentSample.samplePeriodSecs;
        
        if (this.previousTPS === null) {
          this.previousTPS = currentTPS;
          return null;
        }
        
        const change = Math.abs(currentTPS - this.previousTPS) / this.previousTPS;
        
        if (change > this.threshold) {
          const alert: PerformanceAlert = {
            type: change > 0 ? 'high_tps' : 'low_tps',
            currentTPS,
            threshold: this.threshold,
            metadata: {
              timestamp: Date.now(),
              slot: currentSample.slot
            }
          };
          
          this.previousTPS = currentTPS;
          return alert;
        }
        
        return null;
      }
    }
    
  3. Performance History

    interface PerformanceHistory {
      samples: Array<{
        slot: number;
        tps: number;
        nonVoteTPS: number;
        timestamp: number;
      }>;
      summary: {
        averageTPS: number;
        peakTPS: number;
        totalTransactions: number;
      };
      metadata: {
        startTime: number;
        endTime: number;
        sampleCount: number;
      };
    }
    
    async function getPerformanceHistory(
      limit: number = 720
    ): Promise<PerformanceHistory> {
      const samples = await connection.getRecentPerformanceSamples(limit);
      
      const processedSamples = samples.map(sample => ({
        slot: sample.slot,
        tps: sample.numTransactions / sample.samplePeriodSecs,
        nonVoteTPS: sample.numNonVoteTransaction / sample.samplePeriodSecs,
        timestamp: Date.now() - (samples.length - samples.indexOf(sample)) * sample.samplePeriodSecs * 1000
      }));
      
      const totalTransactions = samples.reduce(
        (sum, sample) => sum + sample.numTransactions,
        0
      );
      const totalSeconds = samples.reduce(
        (sum, sample) => sum + sample.samplePeriodSecs,
        0
      );
      
      return {
        samples: processedSamples,
        summary: {
          averageTPS: totalTransactions / totalSeconds,
          peakTPS: Math.max(...processedSamples.map(sample => sample.tps)),
          totalTransactions
        },
        metadata: {
          startTime: processedSamples[0].timestamp,
          endTime: processedSamples[processedSamples.length - 1].timestamp,
          sampleCount: samples.length
        }
      };
    }