> ## 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ガイド](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`): この`slot`までに処理されたトランザクション（投票トランザクションおよび非投票トランザクションを含む）の総数。
* **`numSlots`** (`u64`): この`slot`までに処理されたスロットの数。
* **`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`フィールドは各サンプルの実際の期間を示します。
* **履歴データ制限:** 最大`limit`は720サンプルで、約12時間の履歴データのウィンドウを提供します。長期間のパフォーマンス分析には、外部のデータロギングと集計が必要です。
* **投票トランザクションと非投票トランザクション:** `numTransactions`はすべてのトランザクションを含みますが、`numNonVoteTransactions`はコンセンサス投票プロセスに含まれないものを特にカウントします。後者はユーザーによるネットワーク活動のより良い指標です。
* **ノードの変動性:** 正確なデータは、サンプルが取得されたときの同期状態とネットワークのローカルビューに応じて、異なるRPCノード間でわずかに異なる場合があります。

`getRecentPerformanceSamples`を利用することで、開発者やネットワークオブザーバーはSolanaネットワークの運用状態とスループットについて貴重な洞察を得ることができます。
