> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbitflare.com/llms.txt
> Use this file to discover all available pages before exploring further.

# getRecentPerformanceSamples

> Returns recent performance samples

## Parameters

<ResponseField name="limit" type="number" optional>
  Number of samples to return (default: 720)
</ResponseField>

## Response

<ResponseField name="result" type="array">
  Array of performance sample objects

  <ResponseField name="slot" type="number">
    Slot number
  </ResponseField>

  <ResponseField name="numSlots" type="number">
    Number of slots in the sample
  </ResponseField>

  <ResponseField name="numTransactions" type="number">
    Number of transactions in the sample
  </ResponseField>

  <ResponseField name="samplePeriodSecs" type="number">
    Sample period in seconds
  </ResponseField>

  <ResponseField name="numNonVoteTransaction" type="number">
    Number of non-vote transactions
  </ResponseField>
</ResponseField>

## Code Examples

### Basic Request

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getRecentPerformanceSamples",
  "params": []
}'
```

### Request with Limit

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getRecentPerformanceSamples",
  "params": [
    100
  ]
}'
```

### Using web3.js

```typescript theme={null}
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

// 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

| Code   | Message                         | Solution                                     |
| ------ | ------------------------------- | -------------------------------------------- |
| -32601 | Method not found                | Verify you're connected to a Solana RPC node |
| -32602 | Invalid params                  | Check limit parameter                        |
| -32007 | Performance samples unavailable | Node may be bootstrapping or syncing         |

## Use Cases

1. **Performance Analysis**
   ```typescript theme={null}
   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**
   ```typescript theme={null}
   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**
   ```typescript theme={null}
   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
       }
     };
   }
   ```
