You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""
Simple stress test focusing on rate limiting without info issues
"""
import time
import threading
from concurrent.futures import ThreadPoolExecutor, as_completed
import yfinance_plus as yf
# Test tickers
TEST_TICKERS = [
'AAPL', 'MSFT', 'GOOGL', 'AMZN', 'TSLA', 'META', 'NVDA', 'NFLX', 'BABA', 'V',
'JPM', 'JNJ', 'WMT', 'PG', 'UNH', 'DIS', 'HD', 'PYPL', 'BAC', 'MA',
'ADBE', 'CRM', 'PFE', 'XOM', 'VZ', 'INTC', 'CMCSA', 'T', 'ABT', 'KO'
]
def test_history_only(symbol, test_id=""):
"""Test only history data to avoid info issues"""
try:
start_time = time.time()
ticker = yf.Ticker(symbol)
# Only test history which is most reliable
hist = ticker.history(period='1mo')
duration = time.time() - start_time
success = not hist.empty
status = "" if success else ""
print(f"{test_id}{status} {symbol}: {duration:.2f}s - {len(hist)} rows")
return {
'symbol': symbol,
'duration': duration,
'success': success,
'rows': len(hist) if success else 0
}
except Exception as e:
duration = time.time() - start_time
print(f"{test_id}{symbol}: {duration:.2f}s - ERROR: {str(e)[:50]}")
return {
'symbol': symbol,
'duration': duration,
'success': False,
'error': str(e)
}
def run_parallel_test(max_workers=10):
"""Run parallel test with specified workers"""
print(f"\n🚀 Parallel Test ({max_workers} workers)")
print("=" * 40)
yf.clear_cache()
start_time = time.time()
results = []
with ThreadPoolExecutor(max_workers=max_workers) as executor:
future_to_symbol = {
executor.submit(test_history_only, symbol, f"[{i+1:2d}] "): symbol
for i, symbol in enumerate(TEST_TICKERS)
}
for future in as_completed(future_to_symbol):
try:
result = future.result()
results.append(result)
except Exception as e:
symbol = future_to_symbol[future]
results.append({
'symbol': symbol,
'duration': 0,
'success': False,
'error': f"Thread error: {e}"
})
total_time = time.time() - start_time
successful = sum(1 for r in results if r['success'])
failed = len(results) - successful
print(f"\n📊 Results ({max_workers} workers):")
print(f"Total time: {total_time:.2f}s")
print(f"Success rate: {successful}/{len(results)} ({successful/len(results)*100:.1f}%)")
print(f"Average per ticker: {total_time/len(results):.2f}s")
if failed > 0:
print(f"\n❌ Failed ({failed}):")
for r in results:
if not r['success']:
print(f" {r['symbol']}: {r.get('error', 'Unknown')}")
return results
if __name__ == "__main__":
print("🧪 Simple Stress Test - Rate Limiting Focus")
print("=" * 50)
# Test different worker counts
for workers in [1, 3, 5, 8, 10, 15]:
run_parallel_test(workers)
time.sleep(2) # Brief pause between tests
print("\n🎯 Summary: Rate limiting effectiveness varies with worker count")