Update 系统设计基础.md
调整配图:用图标表示服务、数据库、请求等元素,并在图中标出具体的数据。
|
Before Width: | Height: | Size: 135 KiB After Width: | Height: | Size: 141 KiB |
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 138 KiB |
@@ -1,4 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="300" viewBox="0 0 720 300">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="312" viewBox="0 0 720 312">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
@@ -31,54 +31,84 @@
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="360" y="28" class="title">100 GB 日志中出现次数最多的 10 个 URL(内存 4 GB)</text>
|
||||
<rect x="22" y="112" width="110" height="70" rx="6" class="shadow"/>
|
||||
<rect x="20" y="110" width="110" height="70" rx="6" fill="#E6E6E6"/>
|
||||
<text x="75" y="143" class="b c">100 GB 日志</text>
|
||||
<text x="75" y="158" class="sub c">每行一个 URL</text>
|
||||
<text x="75" y="204" class="c sub mono">hash(url) % 100</text>
|
||||
<rect x="197" y="58" width="80" height="34" rx="6" class="shadow"/>
|
||||
<rect x="195" y="56" width="80" height="34" rx="6" fill="#B1DDF0"/>
|
||||
<text x="235" y="77.5" class="b c">文件 0</text>
|
||||
<line x1="133" y1="145" x2="191" y2="73" class="arrow "/>
|
||||
<rect x="320" y="56" width="150" height="34" rx="4" fill="#FFFFFF" stroke="#C8C8C8"/>
|
||||
<text x="395" y="77.5" class="c sub">HashMap 计数</text>
|
||||
<line x1="278" y1="73" x2="316" y2="73" class="arrow "/>
|
||||
<rect x="507" y="58" width="70" height="34" rx="6" class="shadow"/>
|
||||
<rect x="505" y="56" width="70" height="34" rx="6" fill="#DDD7F6"/>
|
||||
<text x="540" y="77.5" class="b c">前 10</text>
|
||||
<line x1="473" y1="73" x2="501" y2="73" class="arrow "/>
|
||||
<line x1="578" y1="73" x2="618" y2="145" class="arrow "/>
|
||||
<rect x="197" y="110" width="80" height="34" rx="6" class="shadow"/>
|
||||
<rect x="195" y="108" width="80" height="34" rx="6" fill="#B1DDF0"/>
|
||||
<text x="235" y="129.5" class="b c">文件 1</text>
|
||||
<line x1="133" y1="145" x2="191" y2="125" class="arrow "/>
|
||||
<rect x="320" y="108" width="150" height="34" rx="4" fill="#FFFFFF" stroke="#C8C8C8"/>
|
||||
<text x="395" y="129.5" class="c sub">HashMap 计数</text>
|
||||
<line x1="278" y1="125" x2="316" y2="125" class="arrow "/>
|
||||
<rect x="507" y="110" width="70" height="34" rx="6" class="shadow"/>
|
||||
<rect x="505" y="108" width="70" height="34" rx="6" fill="#DDD7F6"/>
|
||||
<text x="540" y="129.5" class="b c">前 10</text>
|
||||
<line x1="473" y1="125" x2="501" y2="125" class="arrow "/>
|
||||
<line x1="578" y1="125" x2="618" y2="145" class="arrow "/>
|
||||
<text x="235" y="182" class="c b">⋮</text>
|
||||
<rect x="197" y="214" width="80" height="34" rx="6" class="shadow"/>
|
||||
<rect x="195" y="212" width="80" height="34" rx="6" fill="#B1DDF0"/>
|
||||
<text x="235" y="233.5" class="b c">文件 99</text>
|
||||
<line x1="133" y1="145" x2="191" y2="229" class="arrow "/>
|
||||
<rect x="320" y="212" width="150" height="34" rx="4" fill="#FFFFFF" stroke="#C8C8C8"/>
|
||||
<text x="395" y="233.5" class="c sub">HashMap 计数</text>
|
||||
<line x1="278" y1="229" x2="316" y2="229" class="arrow "/>
|
||||
<rect x="507" y="214" width="70" height="34" rx="6" class="shadow"/>
|
||||
<rect x="505" y="212" width="70" height="34" rx="6" fill="#DDD7F6"/>
|
||||
<text x="540" y="233.5" class="b c">前 10</text>
|
||||
<line x1="473" y1="229" x2="501" y2="229" class="arrow "/>
|
||||
<line x1="578" y1="229" x2="618" y2="145" class="arrow "/>
|
||||
<rect x="624" y="118" width="80" height="58" rx="6" class="shadow"/>
|
||||
<rect x="622" y="116" width="80" height="58" rx="6" fill="#B0E3E6"/>
|
||||
<text x="662" y="143" class="b c">小顶堆</text>
|
||||
<text x="662" y="158" class="sub c">全局前 10</text>
|
||||
<text x="235" y="262" class="c sub">① 约 1 GB / 份</text>
|
||||
<text x="395" y="262" class="c sub">② 每次只把一份读入内存</text>
|
||||
<text x="560" y="262" class="c sub">③ 合并 100 × 10 个候选</text>
|
||||
<text x="360" y="288" class="c note">相同的 URL 一定落在同一份中,所以每份单独统计的次数就是它的总次数</text>
|
||||
<path d="M30,110 h49 l9,9 v65 h-58 z" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<path d="M79,110 v9 h9" fill="none" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="36" y1="127" x2="81" y2="127" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="36" y1="134" x2="81" y2="134" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="36" y1="141" x2="81" y2="141" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="59" y="202" class="c b">100 GB 日志</text>
|
||||
<text x="59" y="218" class="c sub">每行一个 URL</text>
|
||||
<text x="20" y="240" class="sub mono">按 hash(url) % 100</text>
|
||||
<text x="20" y="256" class="sub">切成 100 份</text>
|
||||
<path d="M190,60 h19 l9,9 v25 h-28 z" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<path d="M209,60 v9 h9" fill="none" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="196" y1="77" x2="211" y2="77" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="196" y1="84" x2="211" y2="84" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="196" y1="91" x2="211" y2="91" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="226" y="82" class="sub">文件 0</text>
|
||||
<line x1="92" y1="147" x2="186" y2="77" class="arrow "/>
|
||||
<rect x="320" y="62" width="44" height="30" rx="2" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<line x1="320" y1="72" x2="364" y2="72" stroke="#BBB" stroke-width="0.8"/>
|
||||
<line x1="320" y1="82" x2="364" y2="82" stroke="#BBB" stroke-width="0.8"/>
|
||||
<line x1="342" y1="62" x2="342" y2="92" stroke="#BBB" stroke-width="0.8"/>
|
||||
<text x="368" y="80" class="sub">HashMap 计数</text>
|
||||
<line x1="272" y1="77" x2="316" y2="77" class="arrow "/>
|
||||
<rect x="470" y="66" width="48" height="22" rx="4" fill="#DDD7F6" stroke="#A99FD8" stroke-width="1.2"/>
|
||||
<text x="494" y="81" class="c sub">前 10</text>
|
||||
<line x1="452" y1="77" x2="466" y2="77" class="arrow "/>
|
||||
<line x1="520" y1="77" x2="586" y2="150" class="arrow "/>
|
||||
<path d="M190,130 h19 l9,9 v25 h-28 z" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<path d="M209,130 v9 h9" fill="none" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="196" y1="147" x2="211" y2="147" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="196" y1="154" x2="211" y2="154" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="196" y1="161" x2="211" y2="161" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="226" y="152" class="sub">文件 1</text>
|
||||
<line x1="92" y1="147" x2="186" y2="147" class="arrow "/>
|
||||
<rect x="320" y="132" width="44" height="30" rx="2" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<line x1="320" y1="142" x2="364" y2="142" stroke="#BBB" stroke-width="0.8"/>
|
||||
<line x1="320" y1="152" x2="364" y2="152" stroke="#BBB" stroke-width="0.8"/>
|
||||
<line x1="342" y1="132" x2="342" y2="162" stroke="#BBB" stroke-width="0.8"/>
|
||||
<text x="368" y="150" class="sub">HashMap 计数</text>
|
||||
<line x1="272" y1="147" x2="316" y2="147" class="arrow "/>
|
||||
<rect x="470" y="136" width="48" height="22" rx="4" fill="#DDD7F6" stroke="#A99FD8" stroke-width="1.2"/>
|
||||
<text x="494" y="151" class="c sub">前 10</text>
|
||||
<line x1="452" y1="147" x2="466" y2="147" class="arrow "/>
|
||||
<line x1="520" y1="147" x2="586" y2="150" class="arrow "/>
|
||||
<path d="M190,220 h19 l9,9 v25 h-28 z" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<path d="M209,220 v9 h9" fill="none" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="196" y1="237" x2="211" y2="237" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="196" y1="244" x2="211" y2="244" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<line x1="196" y1="251" x2="211" y2="251" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="226" y="242" class="sub">文件 99</text>
|
||||
<line x1="92" y1="147" x2="186" y2="237" class="arrow "/>
|
||||
<rect x="320" y="222" width="44" height="30" rx="2" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<line x1="320" y1="232" x2="364" y2="232" stroke="#BBB" stroke-width="0.8"/>
|
||||
<line x1="320" y1="242" x2="364" y2="242" stroke="#BBB" stroke-width="0.8"/>
|
||||
<line x1="342" y1="222" x2="342" y2="252" stroke="#BBB" stroke-width="0.8"/>
|
||||
<text x="368" y="240" class="sub">HashMap 计数</text>
|
||||
<line x1="272" y1="237" x2="316" y2="237" class="arrow "/>
|
||||
<rect x="470" y="226" width="48" height="22" rx="4" fill="#DDD7F6" stroke="#A99FD8" stroke-width="1.2"/>
|
||||
<text x="494" y="241" class="c sub">前 10</text>
|
||||
<line x1="452" y1="237" x2="466" y2="237" class="arrow "/>
|
||||
<line x1="520" y1="237" x2="586" y2="150" class="arrow "/>
|
||||
<text x="204" y="196" class="c b">⋮</text>
|
||||
<line x1="630" y1="126" x2="608" y2="148" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<line x1="630" y1="126" x2="652" y2="148" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<line x1="608" y1="148" x2="597" y2="170" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<line x1="608" y1="148" x2="619" y2="170" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<line x1="652" y1="148" x2="641" y2="170" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<line x1="652" y1="148" x2="663" y2="170" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<circle cx="630" cy="126" r="8" fill="#DDD7F6" stroke="#A99FD8" stroke-width="1.2"/>
|
||||
<circle cx="608" cy="148" r="7" fill="#B0E3E6" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<circle cx="652" cy="148" r="7" fill="#B0E3E6" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<circle cx="597" cy="170" r="7" fill="#B0E3E6" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<circle cx="619" cy="170" r="7" fill="#B0E3E6" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<circle cx="641" cy="170" r="7" fill="#B0E3E6" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<circle cx="663" cy="170" r="7" fill="#B0E3E6" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<text x="630" y="196" class="c b">小顶堆</text>
|
||||
<text x="630" y="212" class="c sub">全局前 10</text>
|
||||
<text x="204" y="278" class="c sub">① 约 1 GB / 份</text>
|
||||
<text x="370" y="278" class="c sub">② 每次只把一份读入内存</text>
|
||||
<text x="560" y="278" class="c sub">③ 合并 100 × 10 个候选</text>
|
||||
<text x="360" y="304" class="c note">相同的 URL 一定落在同一份中,所以每份单独统计的次数就是它的总次数</text>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 7.6 KiB |
@@ -1,4 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="250" viewBox="0 0 720 250">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="300" viewBox="0 0 720 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
@@ -31,42 +31,48 @@
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="360" y="28" class="title">秒杀:层层过滤请求</text>
|
||||
<rect x="22" y="70" width="96" height="56" rx="6" class="shadow"/>
|
||||
<rect x="20" y="68" width="96" height="56" rx="6" fill="#DDD7F6"/>
|
||||
<text x="68" y="94" class="b c">10 万个请求</text>
|
||||
<text x="68" y="109" class="sub c">同时到达</text>
|
||||
<rect x="152" y="62" width="120" height="72" rx="6" class="shadow"/>
|
||||
<rect x="150" y="60" width="120" height="72" rx="6" fill="#B1DDF0"/>
|
||||
<text x="210" y="86" class="c b">前端与网关</text>
|
||||
<text x="210" y="106" class="c sub">按钮防重复提交</text>
|
||||
<text x="210" y="122" class="c sub">按用户限流</text>
|
||||
<rect x="306" y="62" width="140" height="72" rx="6" class="shadow"/>
|
||||
<rect x="304" y="60" width="140" height="72" rx="6" fill="#B0E3E6"/>
|
||||
<text x="374" y="86" class="c b">Redis + Lua</text>
|
||||
<text x="374" y="106" class="c sub">判断库存和是否已购</text>
|
||||
<text x="374" y="122" class="c sub">原子扣减,库存 100 → 0</text>
|
||||
<rect x="482" y="70" width="90" height="56" rx="6" class="shadow"/>
|
||||
<rect x="480" y="68" width="90" height="56" rx="6" fill="#E6E6E6"/>
|
||||
<text x="525" y="94" class="b c">消息队列</text>
|
||||
<text x="525" y="109" class="sub c">100 条</text>
|
||||
<rect x="606" y="62" width="100" height="72" rx="6" class="shadow"/>
|
||||
<rect x="604" y="60" width="100" height="72" rx="6" fill="#B1DDF0"/>
|
||||
<text x="654" y="86" class="c b">订单服务</text>
|
||||
<text x="654" y="106" class="c sub">扣数据库库存</text>
|
||||
<text x="654" y="122" class="c sub">创建订单</text>
|
||||
<line x1="119" y1="96" x2="146" y2="96" class="arrow "/>
|
||||
<line x1="273" y1="96" x2="300" y2="96" class="arrow "/>
|
||||
<line x1="447" y1="96" x2="476" y2="96" class="arrow green"/>
|
||||
<text x="461" y="88" class="c ok">成功</text>
|
||||
<line x1="573" y1="96" x2="600" y2="96" class="arrow "/>
|
||||
<line x1="374" y1="136" x2="374" y2="172" class="arrow red"/>
|
||||
<text x="382" y="160" class="note">其余请求</text>
|
||||
<rect x="310" y="176" width="128" height="34" rx="6" fill="#F3C6C2"/>
|
||||
<text x="374" y="197.5" class="c sub">直接返回“已抢完”</text>
|
||||
<line x1="210" y1="136" x2="210" y2="172" class="arrow red"/>
|
||||
<rect x="150" y="176" width="120" height="34" rx="6" fill="#F3C6C2"/>
|
||||
<text x="210" y="197.5" class="c sub">拦截重复和超限请求</text>
|
||||
<text x="654" y="156" class="c sub">库存大于 0 才扣减</text>
|
||||
<text x="654" y="174" class="c sub">唯一索引保证一人一单</text>
|
||||
<text x="20" y="236" class="sub">到达数据库的请求接近库存数量;订单最终创建失败时,要把 Redis 中的库存和购买记录恢复。</text>
|
||||
<path d="M20,70 L250,92 L330,120 L700,124 L700,140 L330,144 L250,172 L20,194 Z" fill="#B1DDF0" opacity="0.35"/>
|
||||
<text x="30" y="128" class="b">10 万个请求</text>
|
||||
<text x="30" y="144" class="sub">同时到达</text>
|
||||
<path d="M170,104 L189,113 V124.7 C189,139.88 176,147 170,150 C164,147 151,139.88 151,124.7 V113 Z" fill="#B1DDF0" stroke="#7FB4D0" stroke-width="1.2"/>
|
||||
<path d="M161,126.08 l6,6 l12,-13" fill="none" stroke="#7FB4D0" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<text x="170" y="90" class="c b">前端与网关</text>
|
||||
<text x="170" y="74" class="c sub">防重复提交、按用户限流</text>
|
||||
<path d="M307,112 v34 a23,6 0 0 0 46,0 v-34" fill="#B0E3E6" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<ellipse cx="330" cy="112" rx="23" ry="6" fill="#B0E3E6" stroke="#78BFC4" stroke-width="1.2"/>
|
||||
<path d="M307,129 a23,6 0 0 0 46,0" fill="none" stroke="#78BFC4" stroke-width="1"/>
|
||||
<text x="330" y="90" class="c b">Redis + Lua</text>
|
||||
<text x="330" y="58" class="c sub">判断库存和是否已购,</text>
|
||||
<text x="330" y="74" class="c sub">原子扣减 100 → 0</text>
|
||||
<rect x="430" y="119" width="90" height="26" rx="13" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<rect x="440" y="123" width="20.6667" height="18" rx="3" fill="#DDD7F6" stroke="#A99FD8" stroke-width="1.2"/>
|
||||
<text x="450.333" y="136" class="c sub"></text>
|
||||
<rect x="464.667" y="123" width="20.6667" height="18" rx="3" fill="#DDD7F6" stroke="#A99FD8" stroke-width="1.2"/>
|
||||
<text x="475" y="136" class="c sub"></text>
|
||||
<rect x="489.333" y="123" width="20.6667" height="18" rx="3" fill="#DDD7F6" stroke="#A99FD8" stroke-width="1.2"/>
|
||||
<text x="499.667" y="136" class="c sub"></text>
|
||||
<text x="475" y="108" class="c sub">消息队列 100 条</text>
|
||||
<rect x="570" y="108" width="40" height="13" rx="3" fill="#B1DDF0" stroke="#7FB4D0" stroke-width="1.2"/>
|
||||
<circle cx="577" cy="114.5" r="2" fill="#7FB4D0"/>
|
||||
<line x1="584" y1="114.5" x2="603" y2="114.5" stroke="#7FB4D0" stroke-width="1"/>
|
||||
<rect x="570" y="124" width="40" height="13" rx="3" fill="#B1DDF0" stroke="#7FB4D0" stroke-width="1.2"/>
|
||||
<circle cx="577" cy="130.5" r="2" fill="#7FB4D0"/>
|
||||
<line x1="584" y1="130.5" x2="603" y2="130.5" stroke="#7FB4D0" stroke-width="1"/>
|
||||
<rect x="570" y="140" width="40" height="13" rx="3" fill="#B1DDF0" stroke="#7FB4D0" stroke-width="1.2"/>
|
||||
<circle cx="577" cy="146.5" r="2" fill="#7FB4D0"/>
|
||||
<line x1="584" y1="146.5" x2="603" y2="146.5" stroke="#7FB4D0" stroke-width="1"/>
|
||||
<text x="590" y="172" class="c b">订单服务</text>
|
||||
<path d="M650,114 v30 a20,6 0 0 0 40,0 v-30" fill="#B1DDF0" stroke="#7FB4D0" stroke-width="1.2"/>
|
||||
<ellipse cx="670" cy="114" rx="20" ry="6" fill="#B1DDF0" stroke="#7FB4D0" stroke-width="1.2"/>
|
||||
<path d="M650,129 a20,6 0 0 0 40,0" fill="none" stroke="#7FB4D0" stroke-width="1"/>
|
||||
<text x="670" y="172" class="c b">MySQL</text>
|
||||
<line x1="522" y1="132" x2="568" y2="132" class="arrow "/>
|
||||
<line x1="612" y1="132" x2="648" y2="132" class="arrow "/>
|
||||
<text x="630" y="192" class="c sub">库存大于 0 才扣减</text>
|
||||
<text x="630" y="208" class="c sub">唯一索引保证一人一单</text>
|
||||
<line x1="330" y1="158" x2="330" y2="214" class="arrow red"/>
|
||||
<text x="330" y="232" class="c note">其余请求直接返回“已抢完”</text>
|
||||
<line x1="170" y1="156" x2="170" y2="214" class="arrow red"/>
|
||||
<text x="170" y="232" class="c note">拦截重复和超限请求</text>
|
||||
<text x="360" y="280" class="c sub">到达数据库的请求接近库存数量;订单最终创建失败时,要把 Redis 中的库存和购买记录恢复。</text>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 5.3 KiB |