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

# getRecentPerformanceSamples 사용 방법

> getRecentPerformanceSamples 사용 사례, 코드 예제, 요청 매개 변수, 응답 구조, 그리고 팁을 학습합니다.

[`getRecentPerformanceSamples`](https://www.helius.dev/docs/api-reference/rpc/http/getrecentperformancesamples) RPC 메서드는 Solana 네트워크의 최근 성능을 스냅샷으로 제공합니다. 이 메서드는 약 60초마다 채택된 샘플 리스트를 반환하며, 해당 기간 동안 처리된 트랜잭션 수와 슬롯을 자세히 기록합니다. 이 데이터는 네트워크 처리량과 건강 상태를 모니터링하는 데 매우 유용합니다. TPS 및 슬롯 시간과 같은 Solana의 성능 지표에 대한 더 많은 정보를 얻으려면 [Solana for Enterprise guide](https://www.helius.dev/blog/solana-for-enterprise)를 읽어보세요.

## 일반적인 사용 사례

* **네트워크 건강 모니터링:** 트랜잭션 처리 속도와 슬롯 생성을 추적하여 전체 네트워크 건강 상태를 평가하고 잠재적인 혼잡이나 지연을 식별합니다.
* **성능 분석:** 다양한 조건에서 네트워크 동작을 이해하기 위해 과거 성능 데이터를 분석합니다.
* **대시보드:** 트랜잭션 속도(TPS) 및 분당 슬롯 수와 같은 주요 성능 지표(KPI)를 모니터링 대시보드에 표시합니다.
* **용량 계획:** 애플리케이션이나 인프라에 대한 확장 결정을 알리기 위해 네트워크 부하의 추세를 관찰합니다.

## 요청 매개 변수

1. **`limit`** (`usize`, 선택 사항):
   * 반환할 가장 최근 성능 샘플의 수입니다.
   * 최대값: `720` (샘플은 매 60초마다 채택되므로 약 12시간의 데이터에 해당).
   * 생략할 경우, RPC 노드는 기본 샘플 수를 반환합니다(정확한 기본값은 RPC 공급자에 따라 다를 수 있습니다).

## 응답 구조

JSON-RPC 응답의 `result` 필드는 성능 샘플 객체의 배열로, 가장 최근 샘플이 첫 번째로 오며 역순으로 반환됩니다. 각 객체는 다음 구조를 갖습니다:

* **`slot`** (`u64`): 이 성능 샘플이 기록된 슬롯 번호입니다.
* **`numTransactions`** (`u64`): 이 `samplePeriodSecs`에 대해 처리된 전체 트랜잭션 수(투표 및 비투표 트랜잭션 포함)입니다.
* **`numSlots`** (`u64`): 이 `samplePeriodSecs`에 대해 처리된 슬롯 수입니다.
* **`samplePeriodSecs`** (`u16`): 이 샘플을 채택하는 데 소요된 시간(초)이며, 일반적으로 `60`입니다.
* **`numNonVoteTransactions`** (`u64`): 이 `samplePeriodSecs` 동안 처리된 합의 투표 트랜잭션이 아닌 트랜잭션 수입니다.

## 예제

### 1. 최근 5개의 성능 샘플 가져오기

이 예제는 네트워크에서 가장 최근의 성능 샘플 5개를 요청합니다.

<CodeGroup>
  ```bash cURL theme={"system"}
  # Replace <api-key> with your Helius API key
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getRecentPerformanceSamples",
      "params": [5]
    }'
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  // Replace <api-key> with your Helius API key
  const { Connection } = require('@solana/web3.js');

  async function fetchRecentPerformance() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    try {
      const samples = await connection.getRecentPerformanceSamples(5);
      if (samples && samples.length > 0) {
        console.log(`Fetched ${samples.length} performance samples:`);
        samples.forEach((sample, index) => {
          console.log(`--- Sample ${index + 1} ---`);
          console.log(`  Slot: ${sample.slot}`);
          console.log(`  Number of Slots in Period: ${sample.numSlots}`);
          console.log(`  Total Transactions: ${sample.numTransactions}`);
          console.log(`  Non-Vote Transactions: ${sample.numNonVoteTransactions}`);
          console.log(`  Sample Period (seconds): ${sample.samplePeriodSecs}`);
          const tps = sample.numTransactions / sample.samplePeriodSecs;
          const nonVoteTps = sample.numNonVoteTransactions / sample.samplePeriodSecs;
          console.log(`  Average TPS (Total): ${tps.toFixed(2)}`);
          console.log(`  Average TPS (Non-Vote): ${nonVoteTps.toFixed(2)}`);
        });
      } else {
        console.log('No performance samples returned.');
      }
    } catch (error) {
      console.error('Error fetching recent performance samples:', error);
    }
  }

  fetchRecentPerformance();
  ```
</CodeGroup>

### 2. 기본 성능 샘플 수 가져오기

이 예제는 `limit` 매개 변수를 생략하여 RPC 노드의 기본 샘플 수를 요청합니다.

<CodeGroup>
  ```bash cURL theme={"system"}
  # Replace <api-key> with your Helius API key
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getRecentPerformanceSamples"
    }'
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  // Replace <api-key> with your Helius API key
  const { Connection } = require('@solana/web3.js');

  async function fetchDefaultPerformanceSamples() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    try {
      const samples = await connection.getRecentPerformanceSamples(); // No limit parameter
      if (samples && samples.length > 0) {
        console.log(`Fetched ${samples.length} (default) performance samples:`);
        // Process or log samples as needed - e.g., the first one
        const sample = samples[0];
        console.log(`--- Most Recent Sample ---`);
        console.log(`  Slot: ${sample.slot}`);
        console.log(`  Total Transactions: ${sample.numTransactions}`);
        console.log(`  Non-Vote Transactions: ${sample.numNonVoteTransactions}`);
        console.log(`  Slots in Period: ${sample.numSlots}`);
        console.log(`  Sample Period (seconds): ${sample.samplePeriodSecs}`);
      } else {
        console.log('No performance samples returned.');
      }
    } catch (error) {
      console.error('Error fetching default performance samples:', error);
    }
  }

  fetchDefaultPerformanceSamples();
  ```
</CodeGroup>

## 개발자 팁

* **샘플링 간격:** 샘플은 일반적으로 60초마다 채택되지만, 이는 예상치입니다. 응답의 `samplePeriodSecs` 필드는 각 샘플의 실제 기간을 나타냅니다.
* **역사적 데이터 제한:** 720개의 샘플에 대한 최대 `limit`는 약 12시간의 역사적 데이터를 제공합니다. 장기적인 성능 분석을 위해서는 외부 데이터 로깅 및 집계가 필요합니다.
* **투표 대 비투표 트랜잭션:** `numTransactions`는 모든 트랜잭션을 포함하고, `numNonVoteTransactions`는 합의 투표 프로세스에 포함되지 않는 트랜잭션을 구체적으로 계산합니다. 후자는 사용자 주도의 네트워크 활동을 더 잘 나타냅니다.
* **노드 변동성:** 각 노드의 동기화 상태와 샘플이 채택되는 시점에서의 네트워크 로컬 뷰에 따라 데이터는 다소 다를 수 있습니다.

`getRecentPerformanceSamples`를 활용하여 개발자와 네트워크 관찰자는 Solana 네트워크의 운영 상태와 처리량에 대한 귀중한 인사이트를 얻을 수 있습니다.
