프록시 대역폭 최적화: 성능을 희생하지 않고 비용 절감
Source: Dev.to
Residential and mobile proxy bandwidth is expensive — $5‑50 per GB. Every wasted byte is wasted money. A typical web page is 2‑5 MB; if you only need a price or title, you’re wasting 99 % of the bandwidth on images, CSS, JavaScript, and ads. Heavy resources, poor caching, and failed requests quickly add up.
Source: …
프록시 대역폭 절감 기술
헤드리스 브라우저에서 이미지 및 미디어 차단
# playwright_sync_example.py
from playwright.sync_api import sync_playwright
def create_optimized_page(browser):
page = browser.new_page()
# Block images, fonts, stylesheets, media, analytics, tracking, ads
page.route("**/*.{png,jpg,jpeg,gif,svg,webp}", lambda route: route.abort())
page.route("**/*.{woff,woff2,ttf,eot}", lambda route: route.abort())
page.route("**/*.css", lambda route: route.abort())
page.route("**/analytics*", lambda route: route.abort())
page.route("**/tracking*", lambda route: route.abort())
page.route("**/ads*", lambda route: route.abort())
return page
이러한 리소스를 차단하면 대역폭을 60‑80 % 절감할 수 있습니다.
헤드리스 브라우저보다 직접 HTTP 요청 사용
import requests
# Headless browser: Downloads 3‑5 MB per page
# Direct HTTP: Downloads 50‑200 KB per page
response = requests.get(
url,
proxies=proxy,
headers={"Accept-Encoding": "gzip, deflate, br"},
timeout=15,
)
JavaScript 렌더링이 필요할 때만 헤드리스 브라우저를 사용하세요.
압축 활성화
headers = {
"Accept-Encoding": "gzip, deflate, br", # Server will send compressed response
# `requests` automatically decompresses the payload
}
압축을 사용하면 HTML 페이로드를 70‑80 % 정도 줄일 수 있습니다.
HTML 스크래핑 대신 구조화된 API 사용
# Scraping HTML: ~200 KB per product
html_resp = requests.get("https://site.com/product/123")
# Using API: ~2 KB per product (100× smaller)
api_resp = requests.get("https://api.site.com/products/123")
API는 압축된 JSON을 반환하므로 대역폭을 크게 낮출 수 있습니다.
로컬 캐시 구현
import hashlib, json, time
class ProxyCache:
def __init__(self, cache_ttl=3600):
self.cache = {}
self.ttl = cache_ttl
def get(self, url):
key = hashlib.md5(url.encode()).hexdigest()
entry = self.cache.get(key)
if entry and time.time() - entry["timestamp"] < self.ttl:
return entry["data"] # Cache hit – zero bandwidth
return None
def set(self, url, data):
key = hashlib.md5(url.encode()).hexdigest()
self.cache[key] = {"data": data, "timestamp": time.time()}
캐시 히트가 발생하면 네트워크 트래픽이 전혀 발생하지 않습니다.
조건부 요청 사용
# First request
resp = requests.get(url, proxies=proxy)
etag = resp.headers.get("ETag")
last_modified = resp.headers.get("Last-Modified")
# Subsequent requests
headers = {}
if etag:
headers["If-None-Match"] = etag
if last_modified:
headers["If-Modified-Since"] = last_modified
resp = requests.get(url, proxies=proxy, headers=headers)
if resp.status_code == 304:
# Content unchanged – minimal bandwidth used
pass
조건부 GET은 변경되지 않은 콘텐츠를 다운로드하지 않으므로 95 % 이상의 페이로드를 절감합니다.
스마트 재시도 로직
def smart_retry(url, proxy_manager, max_retries=3):
for attempt in range(max_retries):
proxy = proxy_manager.get_fresh_proxy() # Different proxy each time
try:
response = requests.get(url, proxies=proxy, timeout=10)
if response.status_code == 200:
return response
if response.status_code in (403, 429):
proxy_manager.mark_failed(proxy)
continue # Try a different proxy
except requests.Timeout:
proxy_manager.mark_slow(proxy)
continue
return None
같은 프록시에서 즉시 재시도하는 것을 피해 불필요한 대역폭 낭비를 줄입니다.
대역폭 감소 요약
| 기법 | 대역폭 감소 |
|---|---|
| 이미지/미디어 차단 | 60‑80 % |
| HTTP vs. 헤드리스 브라우저 | 90‑95 % |
| 압축 활성화 | 70‑80 % |
| API 사용 vs. 스크래핑 | 95‑99 % |
| 캐싱 | 캐시 적중 시 100 % |
| 조건부 요청 | 변경되지 않은 콘텐츠에 대해 95 % 이상 |
비용 비교
| 방법 | 페이지당 크기 | 일일 대역폭 | 월 비용 ($10/GB) |
|---|---|---|---|
| 헤드리스, 최적화 없음 | 3 MB | 30 GB | $300 |
| 헤드리스, 차단된 리소스 | 500 KB | 5 GB | $50 |
| 직접 HTTP, 압축됨 | 50 KB | 500 MB | $5 |
| API 요청 | 2 KB | 20 MB | $0.20 |
최적화를 통해 프록시 비용을 최대 **99 %**까지 절감할 수 있습니다.
프록시 최적화 가이드와 비용 절감 전략에 대해 더 알아보려면 DataResearchTools 를 방문하세요.