mirror of
https://github.com/hanzoai/skills.git
synced 2026-11-19 00:47:36 +00:00
hanzoskills.com/llms.txt now opens with the install line, the API reference index and the company index, so an agent that lands on any one of the three can find the rest. robots.txt claimed 537 documents while llms.txt counts 920. The number is gone from robots.txt; llms.txt derives it. public/ is regenerated from scripts/site.py, which it had fallen behind: the copy-prompt menu and agent bar were in the generator and not in the committed pages. tests/site.mjs passes against the result. Co-authored-by: Hanzo Dev <[email protected]>
711 lines
37 KiB
HTML
711 lines
37 KiB
HTML
<!doctype html>
|
|
<html lang="en"><head>
|
|
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>engineering-capacity-planning</title>
|
|
<meta name="color-scheme" content="dark">
|
|
<style>
|
|
/* Committed to one visual world: a dark instrument panel. No light variant —
|
|
the dot field and the hairline rules only read on black, and a naive
|
|
inversion would wash both out. Every colour is painted explicitly so the page
|
|
never borrows a host background. */
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
|
|
|
|
:root{
|
|
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
|
|
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
|
|
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
|
|
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
|
|
--font-zen-pixel-square:'Zen Pixel Square',monospace;
|
|
--mono:var(--font-zen-mono);
|
|
--sans:var(--font-zen-sans);
|
|
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
|
|
--r:999px; --r-soft:14px;
|
|
}
|
|
*{box-sizing:border-box}
|
|
html{-webkit-text-size-adjust:100%}
|
|
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
|
|
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
|
|
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
|
|
|
|
/* The dot field. A halftone made of one repeating radial-gradient, faded out
|
|
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
|
|
/* No overflow clip here: the dot field is inset to the box already, and a clip
|
|
would cut off the copy-prompt menu. */
|
|
.hero{position:relative;border-bottom:1px solid var(--line)}
|
|
.hero::before{content:"";position:absolute;inset:0;
|
|
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
|
|
background-size:7px 7px;
|
|
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
pointer-events:none}
|
|
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
|
|
|
|
nav{border-bottom:1px solid var(--line)}
|
|
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
|
|
justify-content:space-between;align-items:center;gap:1rem}
|
|
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--ink);text-decoration:none;
|
|
display:inline-flex;align-items:center;gap:.6rem}
|
|
.brand i{font-style:normal;color:var(--faint)}
|
|
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
|
|
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--soft);text-decoration:none}
|
|
nav a.up:hover{color:var(--ink)}
|
|
|
|
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
|
|
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
|
|
h1 em{font-style:normal;color:var(--faint)}
|
|
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
|
|
|
|
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
|
|
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
|
|
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
|
|
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
|
|
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
|
|
line-height:1.2;font-weight:400}
|
|
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
|
|
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
|
|
.btn.solid:hover{background:#d8d8d4}
|
|
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
|
|
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
|
|
|
|
/* Copy-prompt selector. Each row copies the prompt for its own target. */
|
|
.copy{position:relative;display:inline-flex}
|
|
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
|
|
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
|
|
padding:.4rem;display:flex;flex-direction:column;
|
|
box-shadow:0 12px 32px rgba(0,0,0,.75)}
|
|
.menu[hidden]{display:none}
|
|
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
|
|
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
|
|
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
|
|
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
|
|
white-space:nowrap}
|
|
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
|
|
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
|
|
.mi:hover .mark{color:var(--ink)}
|
|
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
|
|
letter-spacing:.1em;text-transform:uppercase}
|
|
|
|
/* Works-with bar: one scrolling row, name and mark per agent. */
|
|
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
|
|
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
|
|
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
|
|
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
|
|
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
|
|
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
|
|
display:flex;align-items:center}
|
|
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
|
|
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
|
|
-webkit-overflow-scrolling:touch;
|
|
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
|
|
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
|
|
.bar::-webkit-scrollbar{display:none}
|
|
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
|
|
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
|
|
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
|
|
text-decoration:none;background:var(--ground)}
|
|
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
|
|
.agent .mark{width:.95rem;height:.95rem}
|
|
|
|
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
|
|
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
|
|
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
|
|
p{margin:0 0 1rem;max-width:70ch}
|
|
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
|
|
li{margin:.22rem 0}
|
|
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
|
|
text-decoration-color:var(--line-hi)}
|
|
a:hover{text-decoration-color:var(--ink)}
|
|
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
|
|
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
|
|
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
|
|
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
|
|
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
|
|
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
|
|
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
|
|
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
|
|
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
|
|
display:block;overflow-x:auto}
|
|
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
|
|
|
|
.curl{display:block;background:var(--panel);border:1px solid var(--line);
|
|
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
|
|
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
|
|
white-space:pre;line-height:1.9}
|
|
.curl b{color:var(--ink);font-weight:400}
|
|
.curl i{font-style:normal;color:var(--faint)}
|
|
|
|
/* index */
|
|
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
|
|
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
|
|
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
|
|
#q:focus{outline:none;border-color:var(--soft)}
|
|
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
|
|
text-transform:uppercase;margin:0 0 2rem}
|
|
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
|
|
padding-bottom:.45rem}
|
|
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
|
|
border-radius:var(--r-soft);text-decoration:none}
|
|
.row:hover{background:#0a0a0a}
|
|
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
|
|
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
|
|
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
|
|
color:var(--faint);font-size:.85rem}
|
|
footer a{color:var(--soft)}
|
|
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
|
|
margin:0 0 2rem;font-size:.85rem}
|
|
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
|
|
border-bottom:1px solid var(--line);padding-bottom:.4rem}
|
|
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
|
|
.fmap a:hover{text-decoration:underline}
|
|
.fmap div{color:var(--faint);line-height:1.5}
|
|
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
|
|
|
|
@media (max-width:640px){
|
|
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
|
|
.btns{gap:.5rem}
|
|
.btn{padding:.75rem 1.15rem;font-size:.68rem}
|
|
.copy,.copy .btn{width:100%;justify-content:center}
|
|
.menu{left:0;right:0;min-width:0}
|
|
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
|
|
.strip b{border-right:0;padding-right:0}
|
|
.bar{width:100%}
|
|
}
|
|
</style>
|
|
<link rel="alternate" type="text/markdown" href="/engineering-capacity-planning.md">
|
|
|
|
<link rel="icon" href="/favicon.svg">
|
|
<link rel="canonical" href="https://hanzoskills.com/engineering-capacity-planning">
|
|
</head>
|
|
<!-- Reading this with a machine? Every page here is also plain markdown.
|
|
This one: https://hanzoskills.com/engineering-capacity-planning.md
|
|
Index: https://hanzoskills.com/llms.txt
|
|
Corpus: https://hanzoskills.com/all.md
|
|
Append .md to any path for the markdown twin. -->
|
|
<body>
|
|
<nav><div class="in">
|
|
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
|
|
<a class="up" href="/">All skills</a>
|
|
</div></nav>
|
|
|
|
<div class="wrap">
|
|
<h1>engineering-capacity-planning</h1><p class="lede">Comprehensive capacity planning including forecasting, resource modeling, load testing, scaling strategies, cost optimization, and disaster recovery planning for production systems</p><h1>Capacity Planning</h1>
|
|
<p><strong>Scope</strong>: Forecasting methods, resource modeling (CPU/memory/disk/network), load testing, scaling strategies (vertical/horizontal/auto-scaling), cost optimization, cloud resource planning, database capacity planning, traffic analysis, disaster recovery capacity</p>
|
|
<p><strong>Lines</strong>: ~850</p>
|
|
<p><strong>Last Updated</strong>: 2025-10-27</p>
|
|
<p><strong>Format Version</strong>: 1.0 (Atomic)</p>
|
|
<hr>
|
|
<h2>When to Use This Skill</h2>
|
|
<p>Activate this skill when:</p>
|
|
<ul><li>Planning capacity for new services or features</li><li>Forecasting future resource needs</li><li>Conducting load testing and stress testing</li><li>Designing auto-scaling policies</li><li>Optimizing cloud costs</li><li>Planning database capacity and scaling</li><li>Analyzing traffic patterns and growth</li><li>Sizing disaster recovery infrastructure</li><li>Preparing for seasonal traffic spikes</li><li>Evaluating scaling architecture decisions</li></ul>
|
|
<p>Don't use this skill for:</p>
|
|
<ul><li>Real-time monitoring (see <code>monitoring-alerts.md</code>)</li><li>Incident response (see <code>incident-response.md</code>)</li><li>Performance optimization (see <code>performance-optimization.md</code>)</li><li>Cost tracking (see <code>cloud-cost-management.md</code>)</li></ul>
|
|
<hr>
|
|
<h2>Core Concepts</h2>
|
|
<h3>Concept 1: Capacity Planning Fundamentals</h3>
|
|
<p><strong>Definition</strong>: Proactive planning to ensure systems have sufficient resources to meet current and future demand</p>
|
|
<p><strong>Key Principles</strong>:</p>
|
|
<pre><code>Measure → Forecast → Plan → Provision → Monitor
|
|
↓ ↓ ↓ ↓ ↓
|
|
Current Future Resource Deploy Validate
|
|
Usage Demand Sizing Changes Results</code></pre>
|
|
<p><strong>Planning Horizons</strong>:</p>
|
|
<pre><code>Immediate (Days-Weeks):
|
|
├─ Handle current load spikes
|
|
├─ Address urgent capacity constraints
|
|
└─ Emergency scaling
|
|
|
|
Short-term (1-3 Months):
|
|
├─ Known launches or campaigns
|
|
├─ Seasonal patterns
|
|
└─ Planned migrations
|
|
|
|
Long-term (6-12+ Months):
|
|
├─ Business growth projections
|
|
├─ Architecture changes
|
|
└─ Strategic planning</code></pre>
|
|
<p><strong>Resource Types</strong>:</p>
|
|
<ul><li><strong>Compute</strong>: CPU cores, vCPUs, processing power</li><li><strong>Memory</strong>: RAM for application workloads</li><li><strong>Storage</strong>: Disk space, IOPS, throughput</li><li><strong>Network</strong>: Bandwidth, connections, latency</li><li><strong>Application</strong>: Connection pools, worker threads, queues</li></ul>
|
|
<hr>
|
|
<h3>Concept 2: Forecasting Methods</h3>
|
|
<p><strong>Definition</strong>: Predict future resource usage based on historical data and growth patterns</p>
|
|
<p><strong>Linear Forecasting</strong>:</p>
|
|
<pre><code class="lang-python"># Simple linear regression
|
|
# Usage = baseline + growth_rate * time
|
|
# Best for: Steady, predictable growth
|
|
|
|
future_usage = current_usage + (growth_rate * time_periods)
|
|
|
|
# Example: 100 GB today, growing 10 GB/month
|
|
# In 6 months: 100 + (10 * 6) = 160 GB</code></pre>
|
|
<p><strong>Exponential Forecasting</strong>:</p>
|
|
<pre><code class="lang-python"># Exponential growth
|
|
# Usage = baseline * (1 + growth_rate) ^ time
|
|
# Best for: Viral growth, compound growth
|
|
|
|
future_usage = current_usage * ((1 + growth_rate) ** time_periods)
|
|
|
|
# Example: 1000 users, growing 20%/month
|
|
# In 6 months: 1000 * (1.2^6) = 2,986 users</code></pre>
|
|
<p><strong>Seasonal Forecasting (Prophet)</strong>:</p>
|
|
<pre><code class="lang-python"># Facebook Prophet for seasonal patterns
|
|
# Best for: Weekly/monthly patterns, holidays
|
|
|
|
from prophet import Prophet
|
|
|
|
df = pd.DataFrame({
|
|
'ds': dates, # Date column
|
|
'y': usage # Usage metric
|
|
})
|
|
|
|
model = Prophet(
|
|
yearly_seasonality=True,
|
|
weekly_seasonality=True,
|
|
daily_seasonality=False
|
|
)
|
|
model.fit(df)
|
|
|
|
# Forecast 90 days
|
|
future = model.make_future_dataframe(periods=90)
|
|
forecast = model.predict(future)</code></pre>
|
|
<p><strong>Time-Series Analysis (ARIMA)</strong>:</p>
|
|
<pre><code class="lang-python"># ARIMA for complex patterns
|
|
# Best for: Multiple trends, autocorrelation
|
|
|
|
from statsmodels.tsa.arima.model import ARIMA
|
|
|
|
model = ARIMA(usage_data, order=(p, d, q))
|
|
fitted = model.fit()
|
|
|
|
# Forecast next 30 days
|
|
forecast = fitted.forecast(steps=30)</code></pre>
|
|
<p><strong>Machine Learning (LSTM)</strong>:</p>
|
|
<pre><code class="lang-python"># Neural networks for complex patterns
|
|
# Best for: Non-linear relationships, multiple features
|
|
|
|
from tensorflow.keras import Sequential
|
|
from tensorflow.keras.layers import LSTM, Dense
|
|
|
|
model = Sequential([
|
|
LSTM(50, return_sequences=True, input_shape=(lookback, features)),
|
|
LSTM(50),
|
|
Dense(1)
|
|
])
|
|
|
|
model.compile(optimizer='adam', loss='mse')
|
|
model.fit(X_train, y_train, epochs=50)</code></pre>
|
|
<hr>
|
|
<h3>Concept 3: Resource Modeling</h3>
|
|
<p><strong>Definition</strong>: Model resource consumption based on workload characteristics</p>
|
|
<p><strong>CPU Modeling</strong>:</p>
|
|
<pre><code>CPU_needed = (requests_per_second * cpu_per_request) / cores_per_instance
|
|
|
|
Example:
|
|
- 1000 req/sec
|
|
- 10ms CPU per request
|
|
- 4 vCPU per instance
|
|
|
|
CPU_usage = (1000 * 0.010) / 4 = 2.5 cores (62.5% utilization)
|
|
|
|
Add headroom: 2.5 / 0.7 = 3.6 cores → Need 1 instance</code></pre>
|
|
<p><strong>Memory Modeling</strong>:</p>
|
|
<pre><code>Memory_needed = base_memory + (connections * memory_per_connection)
|
|
|
|
Example:
|
|
- Base: 500 MB
|
|
- 1000 concurrent connections
|
|
- 2 MB per connection
|
|
|
|
Memory = 500 + (1000 * 2) = 2500 MB = 2.5 GB
|
|
|
|
Add headroom: 2.5 / 0.8 = 3.1 GB → Need 4 GB instance</code></pre>
|
|
<p><strong>Storage Modeling</strong>:</p>
|
|
<pre><code>Storage_growth = current_size + (daily_growth * days) + retention
|
|
|
|
Example:
|
|
- Current: 1 TB
|
|
- Growth: 10 GB/day
|
|
- Forecast: 180 days
|
|
- Retention: 90 days
|
|
|
|
Storage = 1000 + (10 * 180) + (10 * 90) = 2800 GB = 2.8 TB
|
|
|
|
Add safety margin (20%): 2.8 * 1.2 = 3.4 TB</code></pre>
|
|
<p><strong>Network Modeling</strong>:</p>
|
|
<pre><code>Bandwidth = (requests_per_second * avg_response_size) / (1024 * 1024)
|
|
|
|
Example:
|
|
- 5000 req/sec
|
|
- 50 KB avg response
|
|
|
|
Bandwidth = (5000 * 50) / 1024 = 244 MB/sec ≈ 2 Gbps
|
|
|
|
Peak traffic (3x): 6 Gbps required</code></pre>
|
|
<hr>
|
|
<h2>Patterns</h2>
|
|
<h3>Pattern 1: Headroom and Safety Margins</h3>
|
|
<p><strong>Problem</strong>: Systems fail when running at 100% capacity</p>
|
|
<p><strong>Headroom Strategy</strong>:</p>
|
|
<pre><code>Resource Type | Target Utilization | Safety Margin
|
|
-----------------|-------------------|---------------
|
|
CPU | 70% | 30%
|
|
Memory | 80% | 20%
|
|
Disk Space | 80% | 20%
|
|
IOPS | 75% | 25%
|
|
Network | 60% | 40%
|
|
Connection Pools | 75% | 25%</code></pre>
|
|
<p><strong>Why Headroom Matters</strong>:</p>
|
|
<pre><code>Without Headroom (100% target):
|
|
├─ No room for traffic spikes
|
|
├─ Deployment requires downtime
|
|
├─ Single failure cascades
|
|
└─ Performance degradation
|
|
|
|
With Headroom (70% target):
|
|
├─ Handles 43% traffic increase
|
|
├─ Rolling deployments safe
|
|
├─ Failure tolerance
|
|
└─ Consistent performance</code></pre>
|
|
<p><strong>Calculating Headroom</strong>:</p>
|
|
<pre><code class="lang-python">def calculate_headroom(current_usage, capacity, target_util=0.7):
|
|
"""Calculate remaining headroom."""
|
|
current_util = current_usage / capacity
|
|
remaining = (target_util - current_util) * capacity
|
|
return {
|
|
'current_utilization': current_util,
|
|
'remaining_headroom': remaining,
|
|
'time_to_capacity': estimate_time_to_capacity(current_usage, remaining)
|
|
}</code></pre>
|
|
<hr>
|
|
<h3>Pattern 2: Load Testing Strategy</h3>
|
|
<p><strong>Problem</strong>: Need to validate capacity under realistic load</p>
|
|
<p><strong>Load Testing Pyramid</strong>:</p>
|
|
<pre><code> ┌─────────────────┐
|
|
│ Chaos Testing │ (Rare, extreme scenarios)
|
|
└─────────────────┘
|
|
┌───────────────────────┐
|
|
│ Stress Testing │ (Beyond limits)
|
|
└───────────────────────┘
|
|
┌───────────────────────────────┐
|
|
│ Load Testing │ (Expected peak)
|
|
└───────────────────────────────┘
|
|
┌───────────────────────────────────────┐
|
|
│ Baseline Testing │ (Normal load)
|
|
└───────────────────────────────────────┘</code></pre>
|
|
<p><strong>Load Test Types</strong>:</p>
|
|
<pre><code class="lang-yaml">Baseline Test:
|
|
duration: 10 minutes
|
|
load: Normal traffic (e.g., 100 req/sec)
|
|
goal: Establish performance baseline
|
|
metrics: P50, P95, P99 latency, error rate
|
|
|
|
Load Test:
|
|
duration: 30 minutes
|
|
load: Expected peak (e.g., 500 req/sec)
|
|
goal: Verify capacity for known peaks
|
|
metrics: Latency, throughput, resource usage
|
|
|
|
Stress Test:
|
|
duration: 15 minutes
|
|
load: Beyond peak (e.g., 1000 req/sec)
|
|
goal: Find breaking point
|
|
metrics: When does it fail? How does it fail?
|
|
|
|
Soak Test:
|
|
duration: 4-24 hours
|
|
load: Sustained normal-high load
|
|
goal: Find memory leaks, resource exhaustion
|
|
metrics: Memory growth, connection leaks
|
|
|
|
Spike Test:
|
|
duration: 2 minutes
|
|
load: Sudden 10x increase
|
|
goal: Validate auto-scaling response
|
|
metrics: Scale-up time, recovery time</code></pre>
|
|
<p><strong>Locust Load Test Example</strong>:</p>
|
|
<pre><code class="lang-python">from locust import HttpUser, task, between
|
|
|
|
class APIUser(HttpUser):
|
|
wait_time = between(1, 3)
|
|
|
|
@task(3)
|
|
def get_items(self):
|
|
self.client.get("/api/items")
|
|
|
|
@task(1)
|
|
def create_item(self):
|
|
self.client.post("/api/items", json={
|
|
"name": "test",
|
|
"value": 42
|
|
})
|
|
|
|
# Run: locust -f loadtest.py --users 1000 --spawn-rate 10</code></pre>
|
|
<hr>
|
|
<h3>Pattern 3: Auto-Scaling Strategy</h3>
|
|
<p><strong>Problem</strong>: Manual scaling is slow and error-prone</p>
|
|
<p><strong>Horizontal Pod Autoscaler (Kubernetes)</strong>:</p>
|
|
<pre><code class="lang-yaml">apiVersion: autoscaling/v2
|
|
kind: HorizontalPodAutoscaler
|
|
metadata:
|
|
name: api-hpa
|
|
spec:
|
|
scaleTargetRef:
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
name: api
|
|
minReplicas: 3
|
|
maxReplicas: 20
|
|
metrics:
|
|
# CPU-based scaling
|
|
- type: Resource
|
|
resource:
|
|
name: cpu
|
|
target:
|
|
type: Utilization
|
|
averageUtilization: 70
|
|
|
|
# Memory-based scaling
|
|
- type: Resource
|
|
resource:
|
|
name: memory
|
|
target:
|
|
type: Utilization
|
|
averageUtilization: 80
|
|
|
|
# Custom metric (RPS)
|
|
- type: Pods
|
|
pods:
|
|
metric:
|
|
name: requests_per_second
|
|
target:
|
|
type: AverageValue
|
|
averageValue: "100"
|
|
|
|
behavior:
|
|
scaleDown:
|
|
stabilizationWindowSeconds: 300 # Wait 5 min before scale down
|
|
policies:
|
|
- type: Percent
|
|
value: 50 # Remove max 50% of pods
|
|
periodSeconds: 60
|
|
scaleUp:
|
|
stabilizationWindowSeconds: 0 # Scale up immediately
|
|
policies:
|
|
- type: Percent
|
|
value: 100 # Double pods if needed
|
|
periodSeconds: 30
|
|
- type: Pods
|
|
value: 5 # Add max 5 pods
|
|
periodSeconds: 30</code></pre>
|
|
<p><strong>AWS Auto Scaling</strong>:</p>
|
|
<pre><code class="lang-json">{
|
|
"ServiceNamespace": "ecs",
|
|
"ScalableDimension": "ecs:service:DesiredCount",
|
|
"PolicyType": "TargetTrackingScaling",
|
|
"TargetTrackingScalingPolicyConfiguration": {
|
|
"TargetValue": 70.0,
|
|
"PredefinedMetricSpecification": {
|
|
"PredefinedMetricType": "ECSServiceAverageCPUUtilization"
|
|
},
|
|
"ScaleOutCooldown": 60,
|
|
"ScaleInCooldown": 300
|
|
}
|
|
}</code></pre>
|
|
<p><strong>Scaling Triggers</strong>:</p>
|
|
<pre><code>Metric Type | Scale Up Threshold | Scale Down Threshold
|
|
------------------|--------------------|-----------------------
|
|
CPU | >70% for 2 min | <30% for 10 min
|
|
Memory | >80% for 2 min | <40% for 10 min
|
|
Request Rate | >80% capacity | <40% capacity
|
|
Response Time | P95 > 500ms | P95 < 200ms
|
|
Queue Depth | >100 messages | <10 messages
|
|
Error Rate | >1% | <0.1%</code></pre>
|
|
<hr>
|
|
<h3>Pattern 4: Cost Optimization</h3>
|
|
<p><strong>Problem</strong>: Over-provisioning wastes money, under-provisioning hurts users</p>
|
|
<p><strong>Cost Optimization Strategies</strong>:</p>
|
|
<pre><code>1. Right-sizing:
|
|
├─ Analyze actual usage vs provisioned
|
|
├─ Downsize over-provisioned resources
|
|
└─ Use smaller instance types where possible
|
|
|
|
2. Reserved/Committed Capacity:
|
|
├─ 1-year commitment: ~30% discount
|
|
├─ 3-year commitment: ~50% discount
|
|
└─ Use for baseline capacity
|
|
|
|
3. Spot/Preemptible Instances:
|
|
├─ 70-90% discount
|
|
├─ Use for batch workloads
|
|
└─ Fault-tolerant services
|
|
|
|
4. Auto-scaling:
|
|
├─ Scale down during off-peak
|
|
├─ Match capacity to demand
|
|
└─ Avoid idle resources
|
|
|
|
5. Storage Tiering:
|
|
├─ Hot data: SSD
|
|
├─ Warm data: HDD
|
|
└─ Cold data: Archive (S3 Glacier)</code></pre>
|
|
<p><strong>Cost Analysis</strong>:</p>
|
|
<pre><code class="lang-python">def analyze_cost_optimization(resources):
|
|
"""Identify cost optimization opportunities."""
|
|
|
|
opportunities = []
|
|
|
|
for resource in resources:
|
|
utilization = resource.avg_utilization
|
|
cost = resource.monthly_cost
|
|
|
|
# Under-utilized (< 30% for 30 days)
|
|
if utilization < 0.30:
|
|
savings = cost * 0.5 # Estimate 50% savings
|
|
opportunities.append({
|
|
'resource': resource.name,
|
|
'action': 'Downsize or terminate',
|
|
'current_util': utilization,
|
|
'potential_savings': savings
|
|
})
|
|
|
|
# No reservation (stable workload)
|
|
if not resource.is_reserved and resource.age_days > 90:
|
|
savings = cost * 0.35 # 35% with 1-year RI
|
|
opportunities.append({
|
|
'resource': resource.name,
|
|
'action': 'Purchase reserved capacity',
|
|
'potential_savings': savings
|
|
})
|
|
|
|
return opportunities</code></pre>
|
|
<hr>
|
|
<h2>Checklist</h2>
|
|
<h3>Capacity Planning Checklist</h3>
|
|
<p><strong>Data Collection</strong>:</p>
|
|
<ul><li>[ ] Collect 30+ days of historical metrics</li><li>[ ] Identify all resource types (CPU, memory, disk, network)</li><li>[ ] Document current capacity and utilization</li><li>[ ] Identify peak usage patterns</li><li>[ ] Collect business growth projections</li><li>[ ] Document seasonal patterns</li><li>[ ] Identify upcoming launches or campaigns</li></ul>
|
|
<p><strong>Forecasting</strong>:</p>
|
|
<ul><li>[ ] Choose forecasting method (linear, exponential, seasonal)</li><li>[ ] Generate forecasts with confidence intervals</li><li>[ ] Account for known future events</li><li>[ ] Include business growth projections</li><li>[ ] Model multiple scenarios (conservative, expected, aggressive)</li><li>[ ] Review forecasts with stakeholders</li></ul>
|
|
<p><strong>Capacity Planning</strong>:</p>
|
|
<ul><li>[ ] Calculate required resources with headroom</li><li>[ ] Identify scaling bottlenecks</li><li>[ ] Plan scaling approach (vertical vs horizontal)</li><li>[ ] Design auto-scaling policies</li><li>[ ] Document capacity constraints</li><li>[ ] Create procurement timeline</li><li>[ ] Estimate costs for capacity changes</li></ul>
|
|
<p><strong>Testing</strong>:</p>
|
|
<ul><li>[ ] Conduct baseline load tests</li><li>[ ] Run load tests at expected peak</li><li>[ ] Perform stress testing to find limits</li><li>[ ] Test auto-scaling behavior</li><li>[ ] Validate disaster recovery capacity</li><li>[ ] Document test results and limits</li></ul>
|
|
<p><strong>Implementation</strong>:</p>
|
|
<ul><li>[ ] Provision additional capacity</li><li>[ ] Configure auto-scaling</li><li>[ ] Update monitoring and alerts</li><li>[ ] Document capacity decisions</li><li>[ ] Train team on new capacity</li><li>[ ] Plan rollback if issues arise</li></ul>
|
|
<p><strong>Monitoring</strong>:</p>
|
|
<ul><li>[ ] Monitor utilization trends</li><li>[ ] Track forecast accuracy</li><li>[ ] Alert on capacity thresholds</li><li>[ ] Review capacity monthly</li><li>[ ] Update forecasts quarterly</li><li>[ ] Conduct load tests quarterly</li></ul>
|
|
<hr>
|
|
<h2>Anti-Patterns</h2>
|
|
<p><strong>Planning Anti-Patterns</strong>:</p>
|
|
<pre><code>❌ No historical data → Guessing instead of forecasting
|
|
❌ Short history (< 30 days) → Missing patterns
|
|
❌ Ignore seasonality → Under-capacity during peaks
|
|
❌ No headroom → Systems at 100%, no room for spikes
|
|
❌ Only plan for average → Fail during peak load
|
|
❌ Plan for 1 year out → Inaccurate, wasted effort</code></pre>
|
|
<p><strong>Testing Anti-Patterns</strong>:</p>
|
|
<pre><code>❌ Test in production → Risk customer impact
|
|
❌ No load testing → Discover limits during incidents
|
|
❌ Test with synthetic data → Doesn't match real usage
|
|
❌ Single load test → Miss edge cases
|
|
❌ No stress testing → Don't know breaking point
|
|
❌ Ignore test failures → Launch without confidence</code></pre>
|
|
<p><strong>Scaling Anti-Patterns</strong>:</p>
|
|
<pre><code>❌ Manual scaling only → Slow response to load changes
|
|
❌ Aggressive scale-down → Flapping, instability
|
|
❌ No scale-up delay → Over-react to spikes
|
|
❌ Scale on CPU only → Miss memory constraints
|
|
❌ No max replicas → Runaway scaling, cost explosion
|
|
❌ No monitoring → Don't know if scaling works</code></pre>
|
|
<p><strong>Cost Anti-Patterns</strong>:</p>
|
|
<pre><code>❌ Over-provision "to be safe" → Wasted money
|
|
❌ No reservation strategy → Pay full price
|
|
❌ Ignore right-sizing → Pay for unused resources
|
|
❌ No cost monitoring → Surprise bills
|
|
❌ No auto-scaling → Pay for idle resources
|
|
❌ No storage lifecycle → Pay for old data</code></pre>
|
|
<hr>
|
|
<h2>Recovery</h2>
|
|
<p><strong>When Forecasts Are Wrong</strong>:</p>
|
|
<pre><code>1. MEASURE actual vs predicted variance
|
|
2. IDENTIFY root cause (unexpected growth, bad model, missing data)
|
|
3. ADJUST forecast model or parameters
|
|
4. UPDATE capacity plan with new forecast
|
|
5. COMMUNICATE changes to stakeholders
|
|
6. DOCUMENT lessons learned</code></pre>
|
|
<p><strong>When Load Tests Reveal Issues</strong>:</p>
|
|
<pre><code>1. DOCUMENT the issue and load level
|
|
2. DETERMINE impact (hard limit or degradation?)
|
|
3. IDENTIFY bottleneck (CPU, memory, database, network)
|
|
4. CALCULATE capacity needed to pass
|
|
5. IMPLEMENT fixes (optimize or add capacity)
|
|
6. RE-TEST to validate
|
|
7. UPDATE capacity plan</code></pre>
|
|
<p><strong>When Scaling Fails</strong>:</p>
|
|
<pre><code>1. REVERT to manual scaling if safe
|
|
2. DIAGNOSE root cause (metrics, limits, quotas)
|
|
3. TEST fixes in non-production
|
|
4. DEPLOY fix with monitoring
|
|
5. VALIDATE auto-scaling behavior
|
|
6. DOCUMENT failure and resolution</code></pre>
|
|
<hr>
|
|
<h2>Level 3: Resources</h2>
|
|
<p><strong>Extended Documentation</strong>: <a href="resources/REFERENCE.md">REFERENCE.md</a> (2,800+ lines)</p>
|
|
<ul><li>Comprehensive capacity planning methodologies</li><li>Detailed forecasting techniques (linear, exponential, Prophet, ARIMA, LSTM)</li><li>Resource modeling formulas and examples</li><li>Load testing strategies and tools (Locust, k6, JMeter, Gatling)</li><li>Scaling strategies (vertical, horizontal, auto-scaling)</li><li>Cost optimization techniques across cloud providers</li><li>Database capacity planning (RDBMS, NoSQL, caching)</li><li>Network capacity planning</li><li>Disaster recovery capacity planning</li><li>Compliance and headroom requirements</li><li>Traffic analysis and prediction methods</li><li>Cloud resource planning (AWS, GCP, Azure)</li></ul>
|
|
<p><strong>Scripts</strong>: Production-ready tools in <code>resources/scripts/</code></p>
|
|
<ul><li><code>forecast_capacity.py</code> (850 lines): Time-series forecasting with multiple algorithms (linear regression, exponential smoothing, Prophet, ARIMA), seasonality detection, confidence intervals, multi-resource modeling, visualization</li><li><code>analyze_resource_usage.py</code> (780 lines): Historical usage analysis, trend detection, anomaly detection, peak usage patterns, cost analysis, utilization reports, right-sizing recommendations</li><li><code>test_scaling.py</code> (720 lines): Load testing orchestration, measure scaling efficiency, test auto-scaling triggers, validate resource limits, cost-performance analysis, generate reports</li></ul>
|
|
<p><strong>Examples</strong>: Production-ready examples in <code>resources/examples/</code></p>
|
|
<ul><li><strong>forecasting/</strong>:</li><li><code>prophet_forecast.py</code>: Complete Prophet-based forecasting model with seasonality</li><li><code>multi_metric_forecast.py</code>: Forecast multiple resources simultaneously</li><li><strong>dashboards/</strong>:</li><li><code>capacity_dashboard.json</code>: Grafana dashboard for capacity monitoring</li><li><code>forecast_dashboard.json</code>: Visualization of capacity forecasts</li><li><strong>auto-scaling/</strong>:</li><li><code>kubernetes_hpa.yaml</code>: Comprehensive HPA configuration</li><li><code>kubernetes_vpa.yaml</code>: Vertical Pod Autoscaler configuration</li><li><code>aws_autoscaling.json</code>: AWS Auto Scaling policies</li><li><code>gcp_autoscaling.yaml</code>: GCP autoscaling configuration</li><li><strong>load-testing/</strong>:</li><li><code>locust_loadtest.py</code>: Production Locust load test scenario</li><li><code>k6_script.js</code>: k6 load testing script with scenarios</li><li><strong>cost-optimization/</strong>:</li><li><code>analyze_costs.py</code>: Cloud cost analysis and optimization</li><li><code>rightsizing_recommendations.py</code>: Instance right-sizing tool</li><li><strong>database/</strong>:</li><li><code>database_capacity_model.py</code>: Database capacity modeling</li><li><strong>examples/</strong>:</li><li><code>traffic_prediction.py</code>: Traffic pattern analysis and prediction</li><li><code>capacity_report.py</code>: Generate comprehensive capacity reports</li></ul>
|
|
<p>All scripts include:</p>
|
|
<ul><li><code>--help</code> for comprehensive usage documentation</li><li><code>--json</code> output for programmatic integration</li><li>Executable permissions and proper shebang lines</li><li>Type hints and docstrings</li><li>Error handling and validation</li><li>Example usage in main block</li></ul>
|
|
<p><strong>Usage</strong>:</p>
|
|
<pre><code class="lang-bash"># Forecast capacity for next 90 days
|
|
./forecast_capacity.py --metric cpu_usage --period 90 \
|
|
--method prophet --output forecast.json --visualize
|
|
|
|
# Analyze resource usage patterns
|
|
./analyze_resource_usage.py --days 30 --resources cpu,memory,disk \
|
|
--detect-anomalies --json
|
|
|
|
# Test scaling behavior
|
|
./test_scaling.py --target api-service --duration 30 \
|
|
--max-rps 1000 --test-autoscaling --report scaling_report.html
|
|
|
|
# Generate capacity forecast
|
|
python examples/forecasting/prophet_forecast.py \
|
|
--input metrics.csv --forecast-days 60
|
|
|
|
# Analyze costs
|
|
python examples/cost-optimization/analyze_costs.py \
|
|
--provider aws --region us-east-1 --optimize</code></pre>
|
|
<hr>
|
|
<h2>Related Skills</h2>
|
|
<ul><li><code>monitoring-alerts.md</code>: Real-time capacity monitoring</li><li><code>performance-optimization.md</code>: Optimize resource usage</li><li><code>cloud-cost-management.md</code>: Track and optimize costs</li><li><code>database-scaling.md</code>: Database-specific capacity planning</li><li><code>sre-practices.md</code>: SLOs and error budgets for capacity</li><li><code>deployment-strategies.md</code>: Safe capacity changes</li><li><code>incident-response.md</code>: Respond to capacity incidents</li></ul>
|
|
<hr>
|
|
<p><strong>Last Updated</strong>: 2025-10-27 <strong>Format Version</strong>: 1.0 (Atomic) <strong>Level 3 Resources</strong>: Available</p>
|
|
<footer>
|
|
<div class="fmap">
|
|
<div><b>Build</b>
|
|
<a href="https://hanzo.app">hanzo.app</a> app builder
|
|
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
|
|
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
|
|
<div><b>Run</b>
|
|
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
|
|
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
|
|
<div><b>Account</b>
|
|
<a href="https://hanzo.id">hanzo.id</a> sign in
|
|
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
|
|
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
|
|
<div><b>Company</b>
|
|
<a href="https://hanzo.ai">hanzo.ai</a> canonical
|
|
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
|
|
</div>
|
|
<div class="fend"><a href="/engineering-capacity-planning.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
|
|
</footer>
|
|
</div></body></html> |