본문 바로가기
C.W.K.
Stream
Lesson 05 of 05 · published

Cache 산수: Worked Example

~24 min · cost, math, savings

Level 0Window Watcher
0 XP0/50 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

숫자를 대보면 바로 납득돼

caching이 왜 이득인지는 실제 워크플로로 셈을 해보면 즉시 보여. 50K token짜리 코드베이스를 훑고 8K token짜리 피드백을 뽑는 일을, 예시용 Sonnet 가격($3/M input, $15/M output, $0.30/M cached input)으로 계산해보자.

경우의 수 셋

A — 한 방에 끝내기: 50K input × $3/M + 8K output × $15/M = $0.27.

B — 열 번 더 주고받기, cache 없음: 대화가 turn마다 불어나서(50K에서 100K쯤으로) input이 값을 지배해. input 약 $3.50 + output 약 $1.20 = 약 $4.70.

C — 열 번 더 주고받기, cache 있음: stable prefix(45K쯤)가 cache에 얹히고 turn마다 새로 드는 input은 5K쯤. input 약 $0.40 + output 약 $1.20 = 약 $1.60. 같은 대화인데 3배 싸.

Caching이 제일 빨리 본전 뽑는 데

stable prefix가 크고(규칙 + tool schema + 자료), 짧은 후속 turn이 많고, variable tail이 짧은 워크플로야. coding agent, 고객 응대 봇, 오래 가는 조사 대화가 대표적인 승리 사례고. 한 번 쓰고 마는 prompt는 얻는 게 거의 없어.

Code

Cache 산수 계산기·python
def estimate(prefix_tokens, tail_tokens, output_tokens, turns,
             p_input=3.0, p_cached=0.30, p_output=15.0):
    # All prices per million tokens.
    no_cache = (prefix_tokens + tail_tokens) * turns / 1e6 * p_input \
             + output_tokens * turns / 1e6 * p_output
    with_cache = (prefix_tokens / 1e6 * p_input                     # first turn full price
                 + prefix_tokens * (turns - 1) / 1e6 * p_cached     # next turns cached
                 + tail_tokens * turns / 1e6 * p_input              # tail always fresh
                 + output_tokens * turns / 1e6 * p_output)
    return {"no_cache": round(no_cache, 2), "with_cache": round(with_cache, 2)}
한 번 돌려본 결과·python
estimate(prefix_tokens=45_000, tail_tokens=5_000,
         output_tokens=2_000, turns=10)
# -> { "no_cache": 1.80, "with_cache": 0.71 }  (illustrative)

External links

Exercise

실제로 오래 도는 AI 워크플로 하나 골라봐. 현실적인 prefix/tail/output token 수랑 turn 수를 계산기에 넣어. caching이 있을 때랑 없을 때 비용을 뽑고, cache 구조에 손댈지 결정해봐.
Hint
cache 쓴 비용이 안 쓴 것보다 30% 넘게 싸면, caching은 사실상 공돈이야.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.