Skip to content

A/B Testing Caching Stratejilerini

Yeni cache TTL veya breakpoint strateji denemek istiyorsun. Production trafiğini risk almadan nasıl test edersin? A/B testing patterns.

Şükrü Yusuf KAYA
10 min read
Intermediate

A/B Testing Cache Stratejileri

Yeni bir caching mimarisini production'a salmak risk. A/B testing ile %5 trafikte dene, metrikleri ölç, sonra %100'e geç.

Pattern: Feature Flag ile Routing#

python
import random
 
def get_cache_strategy(user_id):
"""%5 trafiği yeni stratejiye yönlendir."""
hash_val = hash(f"{user_id}-cache-experiment-v2") % 100
if hash_val < 5: # %5 user
return "new_strategy" # 4 breakpoint, 1h TTL
else:
return "control" # 2 breakpoint, 5m TTL
 
def make_request(user_id, query):
strategy = get_cache_strategy(user_id)
 
if strategy == "new_strategy":
# Yeni mimari
return client.messages.create(
system=[
{"text": KB, "cache_control": {"ttl": "1h"}},
{"text": TOOLS_GUIDE, "cache_control": {"ttl": "1h"}},
{"text": SYSTEM, "cache_control": {"ttl": "5m"}},
],
tools=tools_with_cache,
messages=[*history_with_cache, {"role": "user", "content": query}],
)
else:
# Kontrol grubu
return client.messages.create(
system=[{"text": KB + SYSTEM, "cache_control": {"ttl": "5m"}}],
messages=[{"role": "user", "content": query}],
)
Feature flag ile A/B

Tracking ve Metrikler#

Her grup için ayrı Prometheus label kullan:
python
from prometheus_client import Counter
 
cache_hits = Counter(
'llm_cache_hits_total',
'Cache read tokens',
['strategy'] # ← strateji label'ı
)
 
def instrument(strategy, usage):
cache_hits.labels(strategy=strategy).inc(usage.cache_read_input_tokens or 0)
# ... diğer metrikler
 
# Grafana'da iki strateji yan yana görülür
Strateji-bazlı metric labeling

Test Süresi ve Significance#

Test boyutuTest süresiNotes
%5 trafik, 1000 sorgu/saat~1 günİlk istatistiksel veri
%5 trafik, daha az trafik3-7 günMore confidence
Anlık kararı1-2 saatSadece "smoke test"
İstatistiksel Anlamlılık
Hata yapma: Test grubu çok küçükse (%1) istatistiksel anlamlılık zor. %5-10 ile başla, success metric'lere bak (hit rate, cost, error rate), sonra %100'e taşı.

✓ Pekiştir#

Bir Sonraki Derste#

Modül 11 bitirme sınavı.

Yorumlar & Soru-Cevap

(0)
Yorum yazmak için giriş yap.
Yorumlar yükleniyor...

Related Content