posthog-performance-tuning
PostHog APIのパフォーマンスをキャッシング、バッチ処理、コネクションプーリングで最適化できます。APIレスポンスが遅い場合、キャッシング戦略を導入する場合、またはPostHog連携のリクエストスループットを最適化する場合に使用します。「posthog performance」「optimize posthog」「posthog latency」「posthog caching」「posthog slow」「posthog batch」などのフレーズでトリガーされます。
description の原文を見る
Optimize PostHog API performance with caching, batching, and connection pooling. Use when experiencing slow API responses, implementing caching strategies, or optimizing request throughput for PostHog integrations. Trigger with phrases like "posthog performance", "optimize posthog", "posthog latency", "posthog caching", "posthog slow", "posthog batch".
SKILL.md 本文
PostHog パフォーマンスチューニング
概要
キャッシング、バッチ処理、コネクションプーリングを使用して PostHog API のパフォーマンスを最適化します。
前提条件
- PostHog SDK がインストールされていること
- 非同期パターンの理解
- Redis またはメモリ内キャッシュが利用可能(オプション)
- パフォーマンス監視が導入済み
レイテンシベンチマーク
| 操作 | P50 | P95 | P99 |
|---|---|---|---|
| Read | 50ms | 150ms | 300ms |
| Write | 100ms | 250ms | 500ms |
| List | 75ms | 200ms | 400ms |
キャッシング戦略
レスポンスキャッシング
import { LRUCache } from 'lru-cache';
const cache = new LRUCache<string, any>({
max: 1000,
ttl: 60000, // 1 minute
updateAgeOnGet: true,
});
async function cachedPostHogRequest<T>(
key: string,
fetcher: () => Promise<T>,
ttl?: number
): Promise<T> {
const cached = cache.get(key);
if (cached) return cached as T;
const result = await fetcher();
cache.set(key, result, { ttl });
return result;
}
Redis キャッシング(分散型)
import Redis from 'ioredis';
const redis = new Redis(process.env.REDIS_URL);
async function cachedWithRedis<T>(
key: string,
fetcher: () => Promise<T>,
ttlSeconds = 60
): Promise<T> {
const cached = await redis.get(key);
if (cached) return JSON.parse(cached);
const result = await fetcher();
await redis.setex(key, ttlSeconds, JSON.stringify(result));
return result;
}
リクエストバッチ処理
import DataLoader from 'dataloader';
const posthogLoader = new DataLoader<string, any>(
async (ids) => {
// Batch fetch from PostHog
const results = await posthogClient.batchGet(ids);
return ids.map(id => results.find(r => r.id === id) || null);
},
{
maxBatchSize: 100,
batchScheduleFn: callback => setTimeout(callback, 10),
}
);
// Usage - automatically batched
const [item1, item2, item3] = await Promise.all([
posthogLoader.load('id-1'),
posthogLoader.load('id-2'),
posthogLoader.load('id-3'),
]);
コネクション最適化
import { Agent } from 'https';
// Keep-alive connection pooling
const agent = new Agent({
keepAlive: true,
maxSockets: 10,
maxFreeSockets: 5,
timeout: 30000,
});
const client = new PostHogClient({
apiKey: process.env.POSTHOG_API_KEY!,
httpAgent: agent,
});
ページネーション最適化
async function* paginatedPostHogList<T>(
fetcher: (cursor?: string) => Promise<{ data: T[]; nextCursor?: string }>
): AsyncGenerator<T> {
let cursor: string | undefined;
do {
const { data, nextCursor } = await fetcher(cursor);
for (const item of data) {
yield item;
}
cursor = nextCursor;
} while (cursor);
}
// Usage
for await (const item of paginatedPostHogList(cursor =>
posthogClient.list({ cursor, limit: 100 })
)) {
await process(item);
}
パフォーマンス監視
async function measuredPostHogCall<T>(
operation: string,
fn: () => Promise<T>
): Promise<T> {
const start = performance.now();
try {
const result = await fn();
const duration = performance.now() - start;
console.log({ operation, duration, status: 'success' });
return result;
} catch (error) {
const duration = performance.now() - start;
console.error({ operation, duration, status: 'error', error });
throw error;
}
}
手順
ステップ 1: ベースラインの確立
PostHog の重要な操作の現在のレイテンシを測定します。
ステップ 2: キャッシングの実装
頻繁にアクセスされるデータのレスポンスキャッシングを追加します。
ステップ 3: バッチ処理の有効化
DataLoader またはそれに相当するものを使用して、自動リクエストバッチ処理を実現します。
ステップ 4: コネクションの最適化
keep-alive を使用したコネクションプーリングを構成します。
出力
- API レイテンシの削減
- キャッシング層の実装完了
- リクエストバッチ処理の有効化
- コネクションプーリングの設定完了
エラー処理
| 問題 | 原因 | 解決方法 |
|---|---|---|
| キャッシュミスストーム | TTL 期限切れ | stale-while-revalidate を使用 |
| バッチタイムアウト | 項目数が多すぎる | バッチサイズを削減 |
| コネクション枯渇 | プーリングなし | maxSockets を設定 |
| メモリ圧力 | キャッシュが大きすぎる | キャッシュエントリの最大数を設定 |
例
クイックパフォーマンスラッパー
const withPerformance = <T>(name: string, fn: () => Promise<T>) =>
measuredPostHogCall(name, () =>
cachedPostHogRequest(`cache:${name}`, fn)
);
リソース
次のステップ
コスト最適化については、posthog-cost-tuning を参照してください。
ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- Brmbobo
- リポジトリ
- Brmbobo/Web2podcast
- ライセンス
- MIT
- 最終更新
- 2026/1/26
Source: https://github.com/Brmbobo/Web2podcast / ライセンス: MIT
関連スキル
superpowers-streamer-cli
SuperPowers デスクトップストリーマーの npm パッケージをインストール、ログイン、実行、トラブルシューティングできます。ユーザーが npm から `superpowers-ai` をセットアップしたい場合、メールまたは電話でサインインもしくはアカウント作成を行いたい場合、ストリーマーを起動したい場合、表示されたコントロールリンクを開きたい場合、後で停止したい場合、またはソースコードへのアクセスなしに npm やランタイムの一般的な問題から復旧したい場合に使用します。
catc-client-ops
Catalyst Centerのクライアント操作・監視機能 - 有線・無線クライアントのリスト表示・フィルタリング、MACアドレスによる詳細なクライアント検索、クライアント数分析、時間軸での分析、SSIDおよび周波数帯によるフィルタリング、無線トラブルシューティング機能を提供します。MACアドレスやIPアドレスでのクライアント検索、サイト別やSSID別のクライアント数集計、無線周波数帯の分布分析、Wi-Fi信号の問題調査が必要な場合に活用できます。
ci-cd-and-automation
CI/CDパイプラインの設定を自動化します。ビルドおよびデプロイメントパイプラインの構築または変更時に使用できます。品質ゲートの自動化、CI内のテストランナー設定、またはデプロイメント戦略の確立が必要な場合に活用します。
shipping-and-launch
本番環境へのリリース準備を行います。本番環境へのデプロイ準備が必要な場合、リリース前チェックリストが必要な場合、監視機能の設定を行う場合、段階的なロールアウトを計画する場合、またはロールバック戦略が必要な場合に使用します。
linear-release-setup
Linear Releaseに向けたCI/CD設定を生成します。リリース追跡の設定、LinearのCIパイプライン構築、またはLinearリリースとのデプロイメント連携を実施する際に利用できます。GitHub Actions、GitLab CI、CircleCIなど複数のプラットフォームに対応しています。
tracking-application-response-times
API エンドポイント、データベースクエリ、サービスコール全体にわたるアプリケーションのレスポンスタイムを追跡・最適化できます。パフォーマンス監視やボトルネック特定の際に活用してください。「レスポンスタイムを追跡する」「API パフォーマンスを監視する」「遅延を分析する」といった表現で呼び出せます。