feat: update docs and components, fix DLQ demo bug
This commit is contained in:
+229
-57
@@ -3,11 +3,14 @@
|
||||
<!-- Timeline -->
|
||||
<div class="timeline-container">
|
||||
<div class="timeline-track"></div>
|
||||
<button
|
||||
v-for="(stage, index) in stages"
|
||||
<button
|
||||
v-for="(stage, index) in stages"
|
||||
:key="index"
|
||||
class="timeline-node"
|
||||
:class="{ active: currentStage === index, passed: currentStage > index }"
|
||||
:class="{
|
||||
active: currentStage === index,
|
||||
passed: currentStage > index
|
||||
}"
|
||||
@click="currentStage = index"
|
||||
>
|
||||
<div class="node-dot">
|
||||
@@ -26,7 +29,9 @@
|
||||
<div :key="currentStage" class="stage-content">
|
||||
<div class="header-section">
|
||||
<h3>
|
||||
<span class="stage-index">{{ indexToRoman(currentStage + 1) }}.</span>
|
||||
<span class="stage-index"
|
||||
>{{ indexToRoman(currentStage + 1) }}.</span
|
||||
>
|
||||
{{ stages[currentStage].title }}
|
||||
</h3>
|
||||
<p>{{ stages[currentStage].desc }}</p>
|
||||
@@ -44,7 +49,6 @@
|
||||
<div class="window-title">Server Architecture</div>
|
||||
</div>
|
||||
<div class="arch-canvas">
|
||||
|
||||
<!-- Stage 0: CGI/Static -->
|
||||
<div v-if="currentStage === 0" class="arch-static">
|
||||
<div class="server-box">
|
||||
@@ -64,7 +68,9 @@
|
||||
<!-- Stage 1: Monolith -->
|
||||
<div v-if="currentStage === 1" class="arch-monolith">
|
||||
<div class="server-box big">
|
||||
<div class="server-icon">🦍 Monolithic App (Tomcat/Django)</div>
|
||||
<div class="server-icon">
|
||||
🦍 Monolithic App (Tomcat/Django)
|
||||
</div>
|
||||
<div class="modules-grid">
|
||||
<div class="module">User</div>
|
||||
<div class="module">Order</div>
|
||||
@@ -110,7 +116,6 @@
|
||||
<span>BaaS (Auth0, Supabase, Stripe)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -122,7 +127,9 @@
|
||||
<div class="ops-canvas">
|
||||
<div class="ops-card">
|
||||
<div class="ops-icon">{{ stages[currentStage].opsIcon }}</div>
|
||||
<div class="ops-title">{{ stages[currentStage].opsTitle }}</div>
|
||||
<div class="ops-title">
|
||||
{{ stages[currentStage].opsTitle }}
|
||||
</div>
|
||||
<div class="ops-desc">{{ stages[currentStage].opsDesc }}</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -152,7 +159,8 @@ const stages = [
|
||||
desc: 'In the beginning, servers were physical machines. We uploaded files via FTP. Backend logic was often simple Perl/CGI scripts executing one by one.',
|
||||
opsIcon: '🐌',
|
||||
opsTitle: 'Manual FTP Upload',
|
||||
opsDesc: 'Development was slow. "It works on my machine" was the common nightmare. Scaling meant buying a bigger physical computer.'
|
||||
opsDesc:
|
||||
'Development was slow. "It works on my machine" was the common nightmare. Scaling meant buying a bigger physical computer.'
|
||||
},
|
||||
{
|
||||
year: '2000s',
|
||||
@@ -161,7 +169,8 @@ const stages = [
|
||||
desc: 'Frameworks like Java Spring, Rails, Django appeared. All logic (User, Order, Pay) was packed into ONE giant process. Simple to develop, hard to scale.',
|
||||
opsIcon: '🐳',
|
||||
opsTitle: 'Virtual Machines (VM)',
|
||||
opsDesc: 'We started using VMs (AWS EC2). Scaling meant copying the entire giant application to multiple servers behind a Load Balancer.'
|
||||
opsDesc:
|
||||
'We started using VMs (AWS EC2). Scaling meant copying the entire giant application to multiple servers behind a Load Balancer.'
|
||||
},
|
||||
{
|
||||
year: '2014+',
|
||||
@@ -170,7 +179,8 @@ const stages = [
|
||||
desc: 'Breaking the monolith! Each function (User, Order) became a separate tiny server. Docker changed the game by packaging dependencies together.',
|
||||
opsIcon: '☸️',
|
||||
opsTitle: 'Kubernetes (K8s)',
|
||||
opsDesc: 'Orchestrating thousands of containers. Complexity exploded, but teams could work independently and scale specific parts (e.g., just the Payment service).'
|
||||
opsDesc:
|
||||
'Orchestrating thousands of containers. Complexity exploded, but teams could work independently and scale specific parts (e.g., just the Payment service).'
|
||||
},
|
||||
{
|
||||
year: '2020s+',
|
||||
@@ -179,7 +189,8 @@ const stages = [
|
||||
desc: 'No more managing servers. You just write a function (e.g., "resize image") and upload it. The cloud provider runs it only when needed (Pay-per-use).',
|
||||
opsIcon: '⚡',
|
||||
opsTitle: 'GitOps & Edge',
|
||||
opsDesc: 'Push to Git -> Auto Deploy to global Edge nodes (Vercel, Cloudflare). Backend becomes "Functions + Managed Services (BaaS)".'
|
||||
opsDesc:
|
||||
'Push to Git -> Auto Deploy to global Edge nodes (Vercel, Cloudflare). Backend becomes "Functions + Managed Services (BaaS)".'
|
||||
}
|
||||
]
|
||||
</script>
|
||||
@@ -188,11 +199,13 @@ const stages = [
|
||||
.backend-evolution-demo {
|
||||
border-radius: 16px;
|
||||
background: var(--vp-c-bg);
|
||||
box-shadow: 0 8px 30px rgba(0,0,0,0.05);
|
||||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.05);
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
overflow: hidden;
|
||||
margin: 2rem 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
font-family:
|
||||
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
|
||||
sans-serif;
|
||||
}
|
||||
|
||||
/* Timeline (Reused) */
|
||||
@@ -230,8 +243,13 @@ const stages = [
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.timeline-node:hover { opacity: 0.9; }
|
||||
.timeline-node.active, .timeline-node.passed { opacity: 1; }
|
||||
.timeline-node:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.timeline-node.active,
|
||||
.timeline-node.passed {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.node-dot {
|
||||
width: 16px;
|
||||
@@ -259,8 +277,14 @@ const stages = [
|
||||
transform: scale(1.3);
|
||||
box-shadow: 0 0 0 4px var(--vp-c-bg-soft);
|
||||
}
|
||||
.timeline-node.active .inner-dot { width: 8px; height: 8px; }
|
||||
.timeline-node.passed .node-dot { border-color: var(--vp-c-brand); background: var(--vp-c-brand); }
|
||||
.timeline-node.active .inner-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
.timeline-node.passed .node-dot {
|
||||
border-color: var(--vp-c-brand);
|
||||
background: var(--vp-c-brand);
|
||||
}
|
||||
|
||||
.node-content {
|
||||
text-align: center;
|
||||
@@ -286,7 +310,10 @@ const stages = [
|
||||
}
|
||||
|
||||
/* Content */
|
||||
.content-wrapper { padding: 2rem; min-height: 400px; }
|
||||
.content-wrapper {
|
||||
padding: 2rem;
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
.header-section {
|
||||
text-align: center;
|
||||
@@ -298,13 +325,26 @@ const stages = [
|
||||
.header-section h3 {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
background: linear-gradient(120deg, #f59e0b, #ea580c); /* Orange/Amber for Backend */
|
||||
background: linear-gradient(
|
||||
120deg,
|
||||
#f59e0b,
|
||||
#ea580c
|
||||
); /* Orange/Amber for Backend */
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
|
||||
.stage-index { color: var(--vp-c-text-3); -webkit-text-fill-color: var(--vp-c-text-3); margin-right: 0.5rem; font-weight: normal; }
|
||||
.header-section p { font-size: 1rem; color: var(--vp-c-text-2); line-height: 1.6; }
|
||||
.stage-index {
|
||||
color: var(--vp-c-text-3);
|
||||
-webkit-text-fill-color: var(--vp-c-text-3);
|
||||
margin-right: 0.5rem;
|
||||
font-weight: normal;
|
||||
}
|
||||
.header-section p {
|
||||
font-size: 1rem;
|
||||
color: var(--vp-c-text-2);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* Visualizations */
|
||||
.visualization-grid {
|
||||
@@ -314,37 +354,60 @@ const stages = [
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) { .visualization-grid { grid-template-columns: 1fr; } }
|
||||
@media (max-width: 768px) {
|
||||
.visualization-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.mac-window {
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(0,0,0,0.1);
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.05);
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: white;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
.mac-window:hover { transform: translateY(-5px); }
|
||||
.mac-window:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
.arch-window { background: #f1f5f9; }
|
||||
.ops-window { background: white; }
|
||||
.arch-window {
|
||||
background: #f1f5f9;
|
||||
}
|
||||
.ops-window {
|
||||
background: white;
|
||||
}
|
||||
|
||||
.window-bar {
|
||||
padding: 0.8rem 1rem;
|
||||
background: white;
|
||||
border-bottom: 1px solid rgba(0,0,0,0.05);
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.traffic-lights { display: flex; gap: 6px; }
|
||||
.light { width: 10px; height: 10px; border-radius: 50%; }
|
||||
.light.red { background: #ff5f56; }
|
||||
.light.yellow { background: #ffbd2e; }
|
||||
.light.green { background: #27c93f; }
|
||||
.traffic-lights {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
}
|
||||
.light {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.light.red {
|
||||
background: #ff5f56;
|
||||
}
|
||||
.light.yellow {
|
||||
background: #ffbd2e;
|
||||
}
|
||||
.light.green {
|
||||
background: #27c93f;
|
||||
}
|
||||
|
||||
.window-title {
|
||||
position: absolute;
|
||||
@@ -356,7 +419,8 @@ const stages = [
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.arch-canvas, .ops-canvas {
|
||||
.arch-canvas,
|
||||
.ops-canvas {
|
||||
padding: 2rem;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
@@ -373,32 +437,140 @@ const stages = [
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
.file-system { margin-top: 1rem; background: white; padding: 0.5rem; border-radius: 4px; font-family: monospace; font-size: 0.8rem; }
|
||||
.request-arrow { margin-top: 1rem; display: flex; flex-direction: column; align-items: center; font-size: 0.8rem; color: #64748b; }
|
||||
.file-system {
|
||||
margin-top: 1rem;
|
||||
background: white;
|
||||
padding: 0.5rem;
|
||||
border-radius: 4px;
|
||||
font-family: monospace;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.request-arrow {
|
||||
margin-top: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-size: 0.8rem;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.server-box.big { background: #dbeafe; border-color: #3b82f6; width: 100%; max-width: 250px; }
|
||||
.modules-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 1rem 0; }
|
||||
.module { background: #bfdbfe; padding: 4px; border-radius: 4px; font-size: 0.8rem; color: #1e40af; }
|
||||
.db-connection { font-size: 0.8rem; display: flex; flex-direction: column; align-items: center; }
|
||||
.server-box.big {
|
||||
background: #dbeafe;
|
||||
border-color: #3b82f6;
|
||||
width: 100%;
|
||||
max-width: 250px;
|
||||
}
|
||||
.modules-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 4px;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
.module {
|
||||
background: #bfdbfe;
|
||||
padding: 4px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.8rem;
|
||||
color: #1e40af;
|
||||
}
|
||||
.db-connection {
|
||||
font-size: 0.8rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.cloud-bg { width: 100%; }
|
||||
.service-mesh { display: flex; gap: 1rem; justify-content: center; }
|
||||
.service { background: white; border: 1px solid #e2e8f0; padding: 0.8rem; border-radius: 6px; text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.05); display: flex; flex-direction: column; }
|
||||
.service small { color: #64748b; font-size: 0.7rem; margin-top: 4px; }
|
||||
.comm-lines { margin-top: 1rem; font-size: 0.8rem; color: #94a3b8; text-align: center; border-top: 1px dashed #cbd5e1; width: 80%; padding-top: 4px; }
|
||||
.cloud-bg {
|
||||
width: 100%;
|
||||
}
|
||||
.service-mesh {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
justify-content: center;
|
||||
}
|
||||
.service {
|
||||
background: white;
|
||||
border: 1px solid #e2e8f0;
|
||||
padding: 0.8rem;
|
||||
border-radius: 6px;
|
||||
text-align: center;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.service small {
|
||||
color: #64748b;
|
||||
font-size: 0.7rem;
|
||||
margin-top: 4px;
|
||||
}
|
||||
.comm-lines {
|
||||
margin-top: 1rem;
|
||||
font-size: 0.8rem;
|
||||
color: #94a3b8;
|
||||
text-align: center;
|
||||
border-top: 1px dashed #cbd5e1;
|
||||
width: 80%;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
.function-cloud { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; margin-bottom: 1.5rem; }
|
||||
.func-node { background: #fef3c7; border: 1px solid #f59e0b; color: #b45309; padding: 6px 12px; border-radius: 20px; font-family: monospace; font-size: 0.8rem; }
|
||||
.baas-layer { width: 100%; background: #e0e7ff; padding: 0.5rem; text-align: center; border-radius: 6px; font-size: 0.8rem; color: #4338ca; font-weight: bold; }
|
||||
.function-cloud {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
justify-content: center;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
.func-node {
|
||||
background: #fef3c7;
|
||||
border: 1px solid #f59e0b;
|
||||
color: #b45309;
|
||||
padding: 6px 12px;
|
||||
border-radius: 20px;
|
||||
font-family: monospace;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.baas-layer {
|
||||
width: 100%;
|
||||
background: #e0e7ff;
|
||||
padding: 0.5rem;
|
||||
text-align: center;
|
||||
border-radius: 6px;
|
||||
font-size: 0.8rem;
|
||||
color: #4338ca;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Ops Card */
|
||||
.ops-card { text-align: center; }
|
||||
.ops-icon { font-size: 4rem; margin-bottom: 1rem; }
|
||||
.ops-title { font-size: 1.2rem; font-weight: bold; margin-bottom: 0.5rem; color: var(--vp-c-text-1); }
|
||||
.ops-desc { font-size: 0.9rem; color: var(--vp-c-text-2); line-height: 1.5; }
|
||||
.ops-card {
|
||||
text-align: center;
|
||||
}
|
||||
.ops-icon {
|
||||
font-size: 4rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.ops-title {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
margin-bottom: 0.5rem;
|
||||
color: var(--vp-c-text-1);
|
||||
}
|
||||
.ops-desc {
|
||||
font-size: 0.9rem;
|
||||
color: var(--vp-c-text-2);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* Transitions */
|
||||
.fade-slide-enter-active, .fade-slide-leave-active { transition: all 0.4s ease; }
|
||||
.fade-slide-enter-from { opacity: 0; transform: translateY(20px); }
|
||||
.fade-slide-leave-to { opacity: 0; transform: translateY(-20px); }
|
||||
</style>
|
||||
.fade-slide-enter-active,
|
||||
.fade-slide-leave-active {
|
||||
transition: all 0.4s ease;
|
||||
}
|
||||
.fade-slide-enter-from {
|
||||
opacity: 0;
|
||||
transform: translateY(20px);
|
||||
}
|
||||
.fade-slide-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(-20px);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
<!--
|
||||
CacheHitRatioDemo.vue
|
||||
缓存命中率与延迟/数据库压力演示
|
||||
-->
|
||||
<template>
|
||||
<div class="cache-demo">
|
||||
<div class="header">
|
||||
<div class="title">缓存命中率:速度与成本的杠杆</div>
|
||||
<div class="subtitle">调整命中率,观察平均延迟与数据库压力</div>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<label>
|
||||
缓存命中率:<strong>{{ hitRatio }}%</strong>
|
||||
</label>
|
||||
<input v-model="hitRatio" type="range" min="0" max="100" step="1" />
|
||||
<label class="toggle">
|
||||
<input v-model="cacheEnabled" type="checkbox" />
|
||||
启用缓存
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="metrics">
|
||||
<div class="metric-card">
|
||||
<div class="label">平均延迟</div>
|
||||
<div class="value">{{ avgLatency }} ms</div>
|
||||
<div class="meter">
|
||||
<div class="bar" :style="{ width: latencyBar + '%' }"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
<div class="label">数据库请求比例</div>
|
||||
<div class="value">{{ dbRate }}%</div>
|
||||
<div class="meter">
|
||||
<div class="bar warn" :style="{ width: dbRate + '%' }"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="legend">
|
||||
<div class="item"><span class="dot cache"></span>缓存命中</div>
|
||||
<div class="item"><span class="dot db"></span>数据库读取</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
const hitRatio = ref(60)
|
||||
const cacheEnabled = ref(true)
|
||||
|
||||
const cacheLatency = 8
|
||||
const dbLatency = 120
|
||||
|
||||
const effectiveHit = computed(() => (cacheEnabled.value ? hitRatio.value : 0))
|
||||
|
||||
const avgLatency = computed(() => {
|
||||
const hit = effectiveHit.value / 100
|
||||
return Math.round(hit * cacheLatency + (1 - hit) * dbLatency)
|
||||
})
|
||||
|
||||
const dbRate = computed(() => Math.round(100 - effectiveHit.value))
|
||||
const latencyBar = computed(() =>
|
||||
Math.min(100, Math.round(avgLatency.value / 2))
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.cache-demo {
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
background: var(--vp-c-bg-soft);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
margin: 1.5rem 0;
|
||||
font-family: var(--vp-font-family-base);
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: 700;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: var(--vp-c-text-2);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.controls label {
|
||||
display: block;
|
||||
margin-bottom: 0.4rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.controls input[type='range'] {
|
||||
width: 100%;
|
||||
margin-bottom: 0.6rem;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 1rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.metric-card {
|
||||
background: var(--vp-c-bg);
|
||||
border-radius: 10px;
|
||||
padding: 0.9rem;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 700;
|
||||
margin: 0.25rem 0 0.5rem;
|
||||
}
|
||||
|
||||
.meter {
|
||||
height: 8px;
|
||||
border-radius: 999px;
|
||||
background: var(--vp-c-bg-soft);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #22c55e, #14b8a6);
|
||||
}
|
||||
|
||||
.bar.warn {
|
||||
background: linear-gradient(90deg, #f59e0b, #ef4444);
|
||||
}
|
||||
|
||||
.legend {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-top: 0.9rem;
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.dot.cache {
|
||||
background: #22c55e;
|
||||
}
|
||||
|
||||
.dot.db {
|
||||
background: #ef4444;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,232 @@
|
||||
<!--
|
||||
CgiQueueDemo.vue
|
||||
物理服务器/CGI 时代的排队与响应时间演示
|
||||
-->
|
||||
<template>
|
||||
<div class="cgi-demo">
|
||||
<div class="panel">
|
||||
<div class="panel-header">
|
||||
<div class="title">CGI 串行处理:排队效应</div>
|
||||
<div class="subtitle">请求越多,响应越慢</div>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<label>
|
||||
并发用户:<strong>{{ concurrentUsers }}</strong>
|
||||
</label>
|
||||
<input
|
||||
v-model="concurrentUsers"
|
||||
type="range"
|
||||
min="1"
|
||||
max="200"
|
||||
step="1"
|
||||
/>
|
||||
|
||||
<div class="toggles">
|
||||
<label class="toggle">
|
||||
<input v-model="staticCache" type="checkbox" />
|
||||
启用静态缓存 (减少脚本开销)
|
||||
</label>
|
||||
<button class="burst" @click="simulateBurst">模拟秒杀</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stats">
|
||||
<div class="stat">
|
||||
<div class="label">平均响应时间</div>
|
||||
<div class="value">{{ avgResponse }} ms</div>
|
||||
<div class="meter">
|
||||
<div class="bar" :style="{ width: responseBar + '%' }"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="label">排队请求数</div>
|
||||
<div class="value">{{ queueLength }}</div>
|
||||
<div class="meter">
|
||||
<div class="bar warn" :style="{ width: queueBar + '%' }"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="note">
|
||||
<span class="dot" :class="statusClass"></span>
|
||||
<span>{{ statusText }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
const concurrentUsers = ref(24)
|
||||
const staticCache = ref(false)
|
||||
|
||||
const baseLatency = computed(() => (staticCache.value ? 40 : 80))
|
||||
const perRequestCost = computed(() => (staticCache.value ? 25 : 60))
|
||||
|
||||
const avgResponse = computed(() =>
|
||||
Math.round(
|
||||
baseLatency.value + (concurrentUsers.value - 1) * perRequestCost.value
|
||||
)
|
||||
)
|
||||
|
||||
const queueLength = computed(() => Math.max(0, concurrentUsers.value - 1))
|
||||
|
||||
const responseBar = computed(() =>
|
||||
Math.min(100, Math.round(avgResponse.value / 25))
|
||||
)
|
||||
const queueBar = computed(() =>
|
||||
Math.min(100, Math.round((queueLength.value / 200) * 100))
|
||||
)
|
||||
|
||||
const statusClass = computed(() => {
|
||||
if (avgResponse.value < 800) return 'ok'
|
||||
if (avgResponse.value < 3000) return 'warn'
|
||||
return 'danger'
|
||||
})
|
||||
|
||||
const statusText = computed(() => {
|
||||
if (avgResponse.value < 800) return '系统还扛得住,但已经在排队了'
|
||||
if (avgResponse.value < 3000) return '响应变慢,用户开始抱怨'
|
||||
return '排队爆炸,网站接近不可用'
|
||||
})
|
||||
|
||||
const simulateBurst = () => {
|
||||
const original = concurrentUsers.value
|
||||
concurrentUsers.value = 160
|
||||
setTimeout(() => {
|
||||
concurrentUsers.value = original
|
||||
}, 800)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.cgi-demo {
|
||||
margin: 1.5rem 0;
|
||||
font-family: var(--vp-font-family-base);
|
||||
}
|
||||
|
||||
.panel {
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
background: var(--vp-c-bg-soft);
|
||||
border-radius: 12px;
|
||||
padding: 1.25rem;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: 700;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 0.9rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.controls label {
|
||||
display: block;
|
||||
font-size: 0.9rem;
|
||||
margin-bottom: 0.35rem;
|
||||
}
|
||||
|
||||
.controls input[type='range'] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.toggles {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-top: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.burst {
|
||||
border: none;
|
||||
padding: 0.35rem 0.75rem;
|
||||
border-radius: 999px;
|
||||
background: var(--vp-c-brand);
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
gap: 1rem;
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
|
||||
.stat .label {
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.stat .value {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
margin: 0.25rem 0 0.5rem;
|
||||
}
|
||||
|
||||
.meter {
|
||||
height: 8px;
|
||||
border-radius: 999px;
|
||||
background: var(--vp-c-bg);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #22c55e, #14b8a6);
|
||||
}
|
||||
|
||||
.bar.warn {
|
||||
background: linear-gradient(90deg, #f59e0b, #ef4444);
|
||||
}
|
||||
|
||||
.note {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-top: 1rem;
|
||||
font-size: 0.9rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 999px;
|
||||
background: #22c55e;
|
||||
}
|
||||
|
||||
.dot.warn {
|
||||
background: #f59e0b;
|
||||
}
|
||||
|
||||
.dot.danger {
|
||||
background: #ef4444;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.toggles {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+264
@@ -0,0 +1,264 @@
|
||||
<!--
|
||||
MicroserviceLatencyDemo.vue
|
||||
微服务架构中的网络延迟累积演示
|
||||
-->
|
||||
<template>
|
||||
<div class="microservice-latency-demo">
|
||||
<div class="header">
|
||||
<div class="title">微服务延迟:网络调用的代价</div>
|
||||
<div class="subtitle">
|
||||
每次服务间调用都增加网络延迟,累积后响应时间变长
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<label
|
||||
>服务间调用次数:<strong>{{ callCount }}</strong></label
|
||||
>
|
||||
<input v-model="callCount" type="range" min="1" max="10" step="1" />
|
||||
|
||||
<label
|
||||
>网络延迟:<strong>{{ networkLatency }} ms</strong></label
|
||||
>
|
||||
<input v-model="networkLatency" type="range" min="1" max="50" step="1" />
|
||||
</div>
|
||||
|
||||
<div class="comparison">
|
||||
<div class="architecture monolith">
|
||||
<div class="arch-title">单体架构</div>
|
||||
<div class="arch-box">
|
||||
<div class="single-process">
|
||||
<div class="module">User</div>
|
||||
<div class="module">Order</div>
|
||||
<div class="module">Payment</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="latency">
|
||||
<div class="latency-value">{{ monolithLatency }} ms</div>
|
||||
<div class="latency-label">内存调用(~0ms)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="architecture microservices">
|
||||
<div class="arch-title">微服务架构</div>
|
||||
<div class="arch-box">
|
||||
<div class="services">
|
||||
<div class="service">User Svc</div>
|
||||
<div class="network-arrow" v-if="callCount > 1">
|
||||
⇄ {{ networkLatency }}ms
|
||||
</div>
|
||||
<div class="service">Order Svc</div>
|
||||
<div class="network-arrow" v-if="callCount > 2">
|
||||
⇄ {{ networkLatency }}ms
|
||||
</div>
|
||||
<div class="service">Payment Svc</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="latency">
|
||||
<div class="latency-value high">{{ microLatency }} ms</div>
|
||||
<div class="latency-label">网络调用累积</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="insight">
|
||||
<div class="insight-icon" v-html="insightIcon"></div>
|
||||
<div class="insight-text">{{ insight }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
const callCount = ref(3)
|
||||
const networkLatency = ref(15)
|
||||
|
||||
const baseLatency = 10
|
||||
const monolithLatency = computed(() => baseLatency)
|
||||
|
||||
const microLatency = computed(() =>
|
||||
Math.round(baseLatency + callCount.value * networkLatency.value * 2)
|
||||
)
|
||||
|
||||
const insight = computed(() => {
|
||||
const ratio = Math.round(microLatency.value / monolithLatency.value)
|
||||
if (ratio <= 2) return '微服务架构的延迟还可以接受,但比单体慢'
|
||||
if (ratio <= 5) return '服务拆分越多,网络延迟累积越明显'
|
||||
return '过多的服务间调用会导致性能严重下降!'
|
||||
})
|
||||
|
||||
const insightIcon = computed(() => {
|
||||
const ratio = Math.round(microLatency.value / monolithLatency.value)
|
||||
if (ratio <= 2) return '✅'
|
||||
if (ratio <= 5) return '⚠️'
|
||||
return '🚨'
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.microservice-latency-demo {
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
background: var(--vp-c-bg-soft);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
margin: 1.5rem 0;
|
||||
font-family: var(--vp-font-family-base);
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: 700;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: var(--vp-c-text-2);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.controls {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.controls label {
|
||||
display: block;
|
||||
margin-bottom: 0.4rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.controls input[type='range'] {
|
||||
width: 100%;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.comparison {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.comparison {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.architecture {
|
||||
background: var(--vp-c-bg);
|
||||
border-radius: 10px;
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
}
|
||||
|
||||
.arch-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.75rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.arch-box {
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
.single-process {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
background: #eff6ff;
|
||||
padding: 0.75rem;
|
||||
border-radius: 6px;
|
||||
border: 2px dashed #93c5fd;
|
||||
}
|
||||
|
||||
.module {
|
||||
background: #dbeafe;
|
||||
padding: 6px;
|
||||
border-radius: 3px;
|
||||
font-size: 0.85rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.services {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.service {
|
||||
background: #fef3c7;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85rem;
|
||||
text-align: center;
|
||||
border: 1px solid #fbbf24;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.network-arrow {
|
||||
text-align: center;
|
||||
font-size: 0.75rem;
|
||||
color: var(--vp-c-text-2);
|
||||
font-weight: 600;
|
||||
animation: pulse 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
opacity: 0.7;
|
||||
transform: scale(0.98);
|
||||
}
|
||||
}
|
||||
|
||||
.latency {
|
||||
margin-top: 1rem;
|
||||
text-align: center;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px solid var(--vp-c-divider);
|
||||
}
|
||||
|
||||
.latency-value {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: var(--vp-c-text-1);
|
||||
}
|
||||
|
||||
.latency-value.high {
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.latency-label {
|
||||
font-size: 0.8rem;
|
||||
color: var(--vp-c-text-2);
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.insight {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-top: 1.5rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background: var(--vp-c-bg);
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
}
|
||||
|
||||
.insight-icon {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.insight-text {
|
||||
flex: 1;
|
||||
font-size: 0.9rem;
|
||||
color: var(--vp-c-text-1);
|
||||
}
|
||||
</style>
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
<!--
|
||||
MonolithReleaseRiskDemo.vue
|
||||
单体发布的影响面与风险演示
|
||||
-->
|
||||
<template>
|
||||
<div class="release-demo">
|
||||
<div class="header">
|
||||
<div class="title">单体发布:牵一发而动全身</div>
|
||||
<div class="subtitle">选择修改范围,看看“爆炸半径”</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="modules">
|
||||
<div class="section-title">本次改动涉及</div>
|
||||
<div class="module-grid">
|
||||
<button
|
||||
v-for="module in modules"
|
||||
:key="module.key"
|
||||
class="module-btn"
|
||||
:class="{ active: module.active }"
|
||||
@click="toggleModule(module.key)"
|
||||
>
|
||||
{{ module.label }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="slider">
|
||||
<label>
|
||||
改动规模:<strong>{{ changeSizeLabel }}</strong>
|
||||
</label>
|
||||
<input v-model="changeSize" type="range" min="1" max="5" step="1" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="result">
|
||||
<div class="risk-meter">
|
||||
<div class="risk-title">故障概率</div>
|
||||
<div class="risk-value">{{ riskPercent }}%</div>
|
||||
<div class="meter">
|
||||
<div class="bar" :style="{ width: riskPercent + '%' }"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="deploy-btn" @click="deployRelease">模拟发布</button>
|
||||
<div class="status" :class="deployStatusClass">
|
||||
{{ deployStatus }}
|
||||
</div>
|
||||
|
||||
<div class="history">
|
||||
<div class="section-title">最近 3 次发布</div>
|
||||
<ul>
|
||||
<li v-for="(item, index) in deployHistory" :key="index">
|
||||
{{ item }}
|
||||
</li>
|
||||
<li v-if="deployHistory.length === 0">暂无记录</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
const modules = ref([
|
||||
{ key: 'user', label: '用户', active: true },
|
||||
{ key: 'order', label: '订单', active: true },
|
||||
{ key: 'payment', label: '支付', active: false },
|
||||
{ key: 'product', label: '商品', active: false }
|
||||
])
|
||||
|
||||
const changeSize = ref(3)
|
||||
const deployHistory = ref([])
|
||||
const deployStatus = ref('等待发布...')
|
||||
const deployStatusClass = ref('idle')
|
||||
|
||||
const activeModules = computed(
|
||||
() => modules.value.filter((m) => m.active).length
|
||||
)
|
||||
|
||||
const riskPercent = computed(() => {
|
||||
const base = 8
|
||||
const moduleRisk = activeModules.value * 12
|
||||
const changeRisk = changeSize.value * 6
|
||||
return Math.min(95, base + moduleRisk + changeRisk)
|
||||
})
|
||||
|
||||
const changeSizeLabel = computed(() => {
|
||||
const labels = ['很小', '小', '中等', '大', '特大']
|
||||
return labels[changeSize.value - 1] || '中等'
|
||||
})
|
||||
|
||||
const toggleModule = (key) => {
|
||||
const target = modules.value.find((m) => m.key === key)
|
||||
if (!target) return
|
||||
target.active = !target.active
|
||||
}
|
||||
|
||||
const deployRelease = () => {
|
||||
const roll = Math.random() * 100
|
||||
if (roll < riskPercent.value) {
|
||||
deployStatus.value = `发布失败:全站回滚,用时 ${8 + changeSize.value * 4} 分钟`
|
||||
deployStatusClass.value = 'fail'
|
||||
} else {
|
||||
deployStatus.value = '发布成功:流量切换完成'
|
||||
deployStatusClass.value = 'success'
|
||||
}
|
||||
|
||||
const summary = `${new Date().toLocaleTimeString('zh-CN', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
})} - ${deployStatus.value}`
|
||||
deployHistory.value.unshift(summary)
|
||||
deployHistory.value = deployHistory.value.slice(0, 3)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.release-demo {
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
background: var(--vp-c-bg-soft);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
margin: 1.5rem 0;
|
||||
font-family: var(--vp-font-family-base);
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: 700;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: var(--vp-c-text-2);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.content {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.module-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.module-btn {
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
border-radius: 8px;
|
||||
background: var(--vp-c-bg);
|
||||
padding: 0.5rem;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.module-btn.active {
|
||||
background: rgba(59, 130, 246, 0.15);
|
||||
border-color: #3b82f6;
|
||||
color: #1d4ed8;
|
||||
}
|
||||
|
||||
.slider label {
|
||||
display: block;
|
||||
margin: 1rem 0 0.5rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.slider input[type='range'] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.risk-meter {
|
||||
background: var(--vp-c-bg);
|
||||
border-radius: 10px;
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
}
|
||||
|
||||
.risk-title {
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.risk-value {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
margin: 0.35rem 0 0.75rem;
|
||||
}
|
||||
|
||||
.meter {
|
||||
height: 8px;
|
||||
background: var(--vp-c-bg-soft);
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #f59e0b, #ef4444);
|
||||
}
|
||||
|
||||
.deploy-btn {
|
||||
margin-top: 1rem;
|
||||
width: 100%;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 0.6rem;
|
||||
background: var(--vp-c-brand);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin-top: 0.75rem;
|
||||
font-size: 0.9rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-radius: 8px;
|
||||
background: var(--vp-c-bg);
|
||||
border: 1px dashed var(--vp-c-divider);
|
||||
}
|
||||
|
||||
.status.success {
|
||||
color: #16a34a;
|
||||
border-color: rgba(22, 163, 74, 0.4);
|
||||
}
|
||||
|
||||
.status.fail {
|
||||
color: #ef4444;
|
||||
border-color: rgba(239, 68, 68, 0.4);
|
||||
}
|
||||
|
||||
.history {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.history ul {
|
||||
padding-left: 1rem;
|
||||
margin: 0.25rem 0 0;
|
||||
color: var(--vp-c-text-2);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.module-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+61
-22
@@ -1,7 +1,9 @@
|
||||
<template>
|
||||
<div class="monolith-microservice-demo">
|
||||
<div class="controls">
|
||||
<button class="action-btn crash-btn" @click="triggerCrash">💥 Simulate Order Service Crash</button>
|
||||
<button class="action-btn crash-btn" @click="triggerCrash">
|
||||
💥 Simulate Order Service Crash
|
||||
</button>
|
||||
<button class="action-btn reset-btn" @click="reset">🔄 Reset</button>
|
||||
</div>
|
||||
|
||||
@@ -12,15 +14,19 @@
|
||||
<div class="server-container" :class="{ crashed: monolithCrashed }">
|
||||
<div class="process-box">
|
||||
<div class="module user">User</div>
|
||||
<div class="module order" :class="{ error: monolithCrashed }">Order</div>
|
||||
<div class="module order" :class="{ error: monolithCrashed }">
|
||||
Order
|
||||
</div>
|
||||
<div class="module pay">Payment</div>
|
||||
</div>
|
||||
<div class="status-indicator">
|
||||
Status: {{ monolithCrashed ? 'SYSTEM DOWN (Critical Failure)' : 'Healthy' }}
|
||||
Status:
|
||||
{{ monolithCrashed ? 'SYSTEM DOWN (Critical Failure)' : 'Healthy' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="desc">
|
||||
One process. If "Order" module has a memory leak or fatal error, <strong>the entire server crashes</strong>. Everyone is affected.
|
||||
One process. If "Order" module has a memory leak or fatal error,
|
||||
<strong>the entire server crashes</strong>. Everyone is affected.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -45,7 +51,8 @@
|
||||
Status: {{ microCrashed ? 'Partial Outage (Order Down)' : 'Healthy' }}
|
||||
</div>
|
||||
<div class="desc">
|
||||
Isolated processes. If "Order" crashes, User and Payment services <strong>keep running</strong>. The system degrades gracefully.
|
||||
Isolated processes. If "Order" crashes, User and Payment services
|
||||
<strong>keep running</strong>. The system degrades gracefully.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -98,7 +105,9 @@ const reset = () => {
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
}
|
||||
.crash-btn:hover { background: #dc2626; }
|
||||
.crash-btn:hover {
|
||||
background: #dc2626;
|
||||
}
|
||||
|
||||
.reset-btn {
|
||||
background: var(--vp-c-brand);
|
||||
@@ -112,7 +121,9 @@ const reset = () => {
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.comparison-view { grid-template-columns: 1fr; }
|
||||
.comparison-view {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.architecture-block {
|
||||
@@ -185,7 +196,7 @@ const reset = () => {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.service-box.crashed {
|
||||
@@ -198,8 +209,14 @@ const reset = () => {
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.dot.green { background: #22c55e; box-shadow: 0 0 4px #22c55e; }
|
||||
.dot.red { background: #ef4444; box-shadow: 0 0 4px #ef4444; }
|
||||
.dot.green {
|
||||
background: #22c55e;
|
||||
box-shadow: 0 0 4px #22c55e;
|
||||
}
|
||||
.dot.red {
|
||||
background: #ef4444;
|
||||
box-shadow: 0 0 4px #ef4444;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
margin-top: 1rem;
|
||||
@@ -217,16 +234,38 @@ const reset = () => {
|
||||
}
|
||||
|
||||
@keyframes shake {
|
||||
0% { transform: translate(1px, 1px) rotate(0deg); }
|
||||
10% { transform: translate(-1px, -2px) rotate(-1deg); }
|
||||
20% { transform: translate(-3px, 0px) rotate(1deg); }
|
||||
30% { transform: translate(3px, 2px) rotate(0deg); }
|
||||
40% { transform: translate(1px, -1px) rotate(1deg); }
|
||||
50% { transform: translate(-1px, 2px) rotate(-1deg); }
|
||||
60% { transform: translate(-3px, 1px) rotate(0deg); }
|
||||
70% { transform: translate(3px, 1px) rotate(-1deg); }
|
||||
80% { transform: translate(-1px, -1px) rotate(1deg); }
|
||||
90% { transform: translate(1px, 2px) rotate(0deg); }
|
||||
100% { transform: translate(1px, -2px) rotate(-1deg); }
|
||||
0% {
|
||||
transform: translate(1px, 1px) rotate(0deg);
|
||||
}
|
||||
10% {
|
||||
transform: translate(-1px, -2px) rotate(-1deg);
|
||||
}
|
||||
20% {
|
||||
transform: translate(-3px, 0px) rotate(1deg);
|
||||
}
|
||||
30% {
|
||||
transform: translate(3px, 2px) rotate(0deg);
|
||||
}
|
||||
40% {
|
||||
transform: translate(1px, -1px) rotate(1deg);
|
||||
}
|
||||
50% {
|
||||
transform: translate(-1px, 2px) rotate(-1deg);
|
||||
}
|
||||
60% {
|
||||
transform: translate(-3px, 1px) rotate(0deg);
|
||||
}
|
||||
70% {
|
||||
transform: translate(3px, 1px) rotate(-1deg);
|
||||
}
|
||||
80% {
|
||||
transform: translate(-1px, -1px) rotate(1deg);
|
||||
}
|
||||
90% {
|
||||
transform: translate(1px, 2px) rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: translate(1px, -2px) rotate(-1deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
<!--
|
||||
ServerlessCostAutoScaleDemo.vue
|
||||
Serverless 成本与弹性对比演示
|
||||
-->
|
||||
<template>
|
||||
<div class="serverless-demo">
|
||||
<div class="header">
|
||||
<div class="title">Serverless:按需付费 + 自动扩缩</div>
|
||||
<div class="subtitle">调整调用量与耗时,比较固定服务器成本</div>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<div class="control">
|
||||
<label>
|
||||
日请求量:<strong>{{ dailyRequests.toLocaleString() }}</strong>
|
||||
</label>
|
||||
<input
|
||||
v-model="dailyRequests"
|
||||
type="range"
|
||||
min="0"
|
||||
max="5000000"
|
||||
step="50000"
|
||||
/>
|
||||
</div>
|
||||
<div class="control">
|
||||
<label>
|
||||
平均耗时:<strong>{{ durationMs }} ms</strong>
|
||||
</label>
|
||||
<input v-model="durationMs" type="range" min="20" max="800" step="10" />
|
||||
</div>
|
||||
<div class="control">
|
||||
<label>
|
||||
峰值并发:<strong>{{ peakRps }}</strong> rps
|
||||
</label>
|
||||
<input v-model="peakRps" type="range" min="10" max="8000" step="50" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cards">
|
||||
<div class="card">
|
||||
<div class="card-title">Serverless 估算</div>
|
||||
<div class="card-value">${{ serverlessCost }}</div>
|
||||
<div class="card-desc">按量计费(示意)</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-title">固定服务器</div>
|
||||
<div class="card-value">${{ serverCost }}</div>
|
||||
<div class="card-desc">需预留 {{ requiredServers }} 台服务器</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="autoscale">
|
||||
<div class="label">扩缩容状态</div>
|
||||
<div class="scale-bar">
|
||||
<div class="scale" :style="{ width: scalePercent + '%' }"></div>
|
||||
</div>
|
||||
<div class="scale-text">
|
||||
{{ scaleHint }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
const dailyRequests = ref(1200000)
|
||||
const durationMs = ref(120)
|
||||
const peakRps = ref(800)
|
||||
|
||||
const serverlessCost = computed(() => {
|
||||
const perMillion = 0.25
|
||||
const requestCost = (dailyRequests.value / 1_000_000) * perMillion
|
||||
const computeCost =
|
||||
((dailyRequests.value * durationMs.value) / 1_000_000_000) * 0.9
|
||||
return (requestCost + computeCost).toFixed(2)
|
||||
})
|
||||
|
||||
const requiredServers = computed(() =>
|
||||
Math.max(1, Math.ceil(peakRps.value / 1000))
|
||||
)
|
||||
const serverCost = computed(() => (requiredServers.value * 8).toFixed(2))
|
||||
|
||||
const scalePercent = computed(() =>
|
||||
Math.min(100, Math.round((peakRps.value / 8000) * 100))
|
||||
)
|
||||
|
||||
const scaleHint = computed(() => {
|
||||
if (peakRps.value < 500) return '流量低:几乎不需要常驻资源'
|
||||
if (peakRps.value < 2500) return '流量中:自动扩缩更省钱'
|
||||
return '流量高:Serverless 仍可弹性扩展'
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.serverless-demo {
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
background: var(--vp-c-bg-soft);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
margin: 1.5rem 0;
|
||||
font-family: var(--vp-font-family-base);
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: 700;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: var(--vp-c-text-2);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.control label {
|
||||
display: block;
|
||||
margin-bottom: 0.4rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.control input[type='range'] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 1rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--vp-c-bg);
|
||||
border-radius: 12px;
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.card-value {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
margin: 0.35rem 0 0.25rem;
|
||||
}
|
||||
|
||||
.card-desc {
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.autoscale {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.autoscale .label {
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
margin-bottom: 0.4rem;
|
||||
}
|
||||
|
||||
.scale-bar {
|
||||
height: 10px;
|
||||
background: var(--vp-c-bg);
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
}
|
||||
|
||||
.scale {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #22c55e, #16a34a);
|
||||
}
|
||||
|
||||
.scale-text {
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.85rem;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user