高级java每日一道面试题-2027年03月11日-实战篇[Docker]-如何实现容器的资源预留和限制? - section-0 line{stroke:hsl(240, 100%, 83

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力网站 👁️ 527 次阅读

容器资源预留与限制深度解析

在共享宿主机上运行多容器时,若不对资源进行管控,某个容器可能无限制地消耗 CPU、内存或磁盘 I/O,导致其他容器性能下降甚至服务中断(即 Noisy Neighbor 问题)。资源预留和资源限制是 Docker 及容器编排平台内置的两类控制机制,它们基于 Linux 内核的 cgroups,让管理员能够为每个容器划定资源使用的“下限”和“上限”。

一、预留 vs 限制:概念与差异

概念定义作用违反后果资源预留(Reservation)为容器保证的最低资源量,调度时节点必须满足此要求确保关键服务始终获得最低限度的资源,避免被过度抢占若节点资源不足,容器无法调度;运行时若无法满足预留,内核会回收(内存)资源限制(Limit)容器允许使用的最大资源量,硬性封顶防止单个容器耗尽宿主机资源,保护其他容器CPU 超限时被限流(throttle),内存超限时进程被 OOM Kill对比:

预留是“承诺”,用于调度和 QoS 保障;限制是“天花板”,用于安全隔离。在 Kubernetes 中,requests 对应预留,limits 对应限制。在 Docker 中,内存限制通过 --memory 设置,CPU 限制可通过 --cpus 设置;预留则通过 --memory-reservation 和 --cpu-shares 间接实现(CPU shares 不是硬预留,而是相对权重)。

二、底层机制:Linux cgroups

容器资源的预留和限制最终由内核的 cgroups(控制组) 实现。每个容器对应一个 cgroup 层级,Docker/containerd 通过修改 cgroup 文件来施加限制。

主要子系统:

子系统控制资源关键参数cpuCPU 时间分配cpu.cfs_period_us, cpu.cfs_quota_us(硬限制);cpu.shares(相对权重,软预留)cpusetCPU 核心绑定cpuset.cpus, cpuset.memsmemory内存使用memory.limit_in_bytes(硬限制);memory.soft_limit_in_bytes(软预留)blkio块设备 I/Oblkio.weight(相对权重);blkio.throttle.read_bps_device 等(硬限制)工作流:

#mermaid-svg-5TfwlwUGahW0F6Vn{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-5TfwlwUGahW0F6Vn .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-5TfwlwUGahW0F6Vn .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-5TfwlwUGahW0F6Vn .error-icon{fill:#552222;}#mermaid-svg-5TfwlwUGahW0F6Vn .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-5TfwlwUGahW0F6Vn .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-5TfwlwUGahW0F6Vn .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-5TfwlwUGahW0F6Vn .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-5TfwlwUGahW0F6Vn .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-5TfwlwUGahW0F6Vn .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-5TfwlwUGahW0F6Vn .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-5TfwlwUGahW0F6Vn .marker{fill:#333333;stroke:#333333;}#mermaid-svg-5TfwlwUGahW0F6Vn .marker.cross{stroke:#333333;}#mermaid-svg-5TfwlwUGahW0F6Vn svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-5TfwlwUGahW0F6Vn p{margin:0;}#mermaid-svg-5TfwlwUGahW0F6Vn .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-5TfwlwUGahW0F6Vn .cluster-label text{fill:#333;}#mermaid-svg-5TfwlwUGahW0F6Vn .cluster-label span{color:#333;}#mermaid-svg-5TfwlwUGahW0F6Vn .cluster-label span p{background-color:transparent;}#mermaid-svg-5TfwlwUGahW0F6Vn .label text,#mermaid-svg-5TfwlwUGahW0F6Vn span{fill:#333;color:#333;}#mermaid-svg-5TfwlwUGahW0F6Vn .node rect,#mermaid-svg-5TfwlwUGahW0F6Vn .node circle,#mermaid-svg-5TfwlwUGahW0F6Vn .node ellipse,#mermaid-svg-5TfwlwUGahW0F6Vn .node polygon,#mermaid-svg-5TfwlwUGahW0F6Vn .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-5TfwlwUGahW0F6Vn .rough-node .label text,#mermaid-svg-5TfwlwUGahW0F6Vn .node .label text,#mermaid-svg-5TfwlwUGahW0F6Vn .image-shape .label,#mermaid-svg-5TfwlwUGahW0F6Vn .icon-shape .label{text-anchor:middle;}#mermaid-svg-5TfwlwUGahW0F6Vn .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-5TfwlwUGahW0F6Vn .rough-node .label,#mermaid-svg-5TfwlwUGahW0F6Vn .node .label,#mermaid-svg-5TfwlwUGahW0F6Vn .image-shape .label,#mermaid-svg-5TfwlwUGahW0F6Vn .icon-shape .label{text-align:center;}#mermaid-svg-5TfwlwUGahW0F6Vn .node.clickable{cursor:pointer;}#mermaid-svg-5TfwlwUGahW0F6Vn .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-5TfwlwUGahW0F6Vn .arrowheadPath{fill:#333333;}#mermaid-svg-5TfwlwUGahW0F6Vn .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-5TfwlwUGahW0F6Vn .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-5TfwlwUGahW0F6Vn .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-5TfwlwUGahW0F6Vn .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-5TfwlwUGahW0F6Vn .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-5TfwlwUGahW0F6Vn .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-5TfwlwUGahW0F6Vn .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-5TfwlwUGahW0F6Vn .cluster text{fill:#333;}#mermaid-svg-5TfwlwUGahW0F6Vn .cluster span{color:#333;}#mermaid-svg-5TfwlwUGahW0F6Vn div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-5TfwlwUGahW0F6Vn .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-5TfwlwUGahW0F6Vn rect.text{fill:none;stroke-width:0;}#mermaid-svg-5TfwlwUGahW0F6Vn .icon-shape,#mermaid-svg-5TfwlwUGahW0F6Vn .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-5TfwlwUGahW0F6Vn .icon-shape p,#mermaid-svg-5TfwlwUGahW0F6Vn .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-5TfwlwUGahW0F6Vn .icon-shape .label rect,#mermaid-svg-5TfwlwUGahW0F6Vn .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-5TfwlwUGahW0F6Vn .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-5TfwlwUGahW0F6Vn .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-5TfwlwUGahW0F6Vn :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}设置限制写入内核强制用户/编排器Docker Daemoncgroup 文件系统容器进程

内核在调度 CPU、分配内存和 I/O 带宽时,读取对应 cgroup 的值,对进程组施加约束。

三、CPU 资源管理

CPU 是可压缩资源,容器用不完的 CPU 时间可被其他容器使用,但可通过限制避免独占。

硬限制:--cpus 或 --cpu-quota 指定容器能使用的 CPU 核数上限。如 --cpus=1.5 表示最多使用 1.5 个核,超出的时间片会被内核限流,表现为 nr_throttled 增加。相对权重(软预留):--cpu-shares 设置权重(默认 1024)。当 CPU 竞争时,权重高的容器获得更多 CPU 时间;无竞争时,单个容器可占用全部 CPU。这并不保证最小 CPU 量。CPU 集绑定:--cpuset-cpus 将容器绑定到指定核心,提高缓存命中并隔离干扰。

CPU 管理架构:

#mermaid-svg-82asaAvdtmqpcmJy{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-82asaAvdtmqpcmJy .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-82asaAvdtmqpcmJy .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-82asaAvdtmqpcmJy .error-icon{fill:#552222;}#mermaid-svg-82asaAvdtmqpcmJy .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-82asaAvdtmqpcmJy .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-82asaAvdtmqpcmJy .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-82asaAvdtmqpcmJy .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-82asaAvdtmqpcmJy .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-82asaAvdtmqpcmJy .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-82asaAvdtmqpcmJy .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-82asaAvdtmqpcmJy .marker{fill:#333333;stroke:#333333;}#mermaid-svg-82asaAvdtmqpcmJy .marker.cross{stroke:#333333;}#mermaid-svg-82asaAvdtmqpcmJy svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-82asaAvdtmqpcmJy p{margin:0;}#mermaid-svg-82asaAvdtmqpcmJy .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-82asaAvdtmqpcmJy .cluster-label text{fill:#333;}#mermaid-svg-82asaAvdtmqpcmJy .cluster-label span{color:#333;}#mermaid-svg-82asaAvdtmqpcmJy .cluster-label span p{background-color:transparent;}#mermaid-svg-82asaAvdtmqpcmJy .label text,#mermaid-svg-82asaAvdtmqpcmJy span{fill:#333;color:#333;}#mermaid-svg-82asaAvdtmqpcmJy .node rect,#mermaid-svg-82asaAvdtmqpcmJy .node circle,#mermaid-svg-82asaAvdtmqpcmJy .node ellipse,#mermaid-svg-82asaAvdtmqpcmJy .node polygon,#mermaid-svg-82asaAvdtmqpcmJy .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-82asaAvdtmqpcmJy .rough-node .label text,#mermaid-svg-82asaAvdtmqpcmJy .node .label text,#mermaid-svg-82asaAvdtmqpcmJy .image-shape .label,#mermaid-svg-82asaAvdtmqpcmJy .icon-shape .label{text-anchor:middle;}#mermaid-svg-82asaAvdtmqpcmJy .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-82asaAvdtmqpcmJy .rough-node .label,#mermaid-svg-82asaAvdtmqpcmJy .node .label,#mermaid-svg-82asaAvdtmqpcmJy .image-shape .label,#mermaid-svg-82asaAvdtmqpcmJy .icon-shape .label{text-align:center;}#mermaid-svg-82asaAvdtmqpcmJy .node.clickable{cursor:pointer;}#mermaid-svg-82asaAvdtmqpcmJy .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-82asaAvdtmqpcmJy .arrowheadPath{fill:#333333;}#mermaid-svg-82asaAvdtmqpcmJy .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-82asaAvdtmqpcmJy .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-82asaAvdtmqpcmJy .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-82asaAvdtmqpcmJy .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-82asaAvdtmqpcmJy .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-82asaAvdtmqpcmJy .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-82asaAvdtmqpcmJy .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-82asaAvdtmqpcmJy .cluster text{fill:#333;}#mermaid-svg-82asaAvdtmqpcmJy .cluster span{color:#333;}#mermaid-svg-82asaAvdtmqpcmJy div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-82asaAvdtmqpcmJy .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-82asaAvdtmqpcmJy rect.text{fill:none;stroke-width:0;}#mermaid-svg-82asaAvdtmqpcmJy .icon-shape,#mermaid-svg-82asaAvdtmqpcmJy .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-82asaAvdtmqpcmJy .icon-shape p,#mermaid-svg-82asaAvdtmqpcmJy .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-82asaAvdtmqpcmJy .icon-shape .label rect,#mermaid-svg-82asaAvdtmqpcmJy .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-82asaAvdtmqpcmJy .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-82asaAvdtmqpcmJy .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-82asaAvdtmqpcmJy :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}是否容器 CPU 请求是否设置硬限制?CFS 配额限制(cpu.cfs_quota_us)仅靠 Shares 竞争内核调度器实际 CPU 分配

四、内存资源管理

内存是不可压缩资源,分配后不能剥夺,因此必须同时设置限制和预留以防 OOM。

硬限制:--memory(如 --memory=512m)。容器内存使用超过此值,内核的 OOM Killer 会杀死容器内进程,容器退出。软预留:--memory-reservation。当宿主机内存压力大时,内核会优先回收超过软限制的内存,但不会立即杀死进程。软预留值应小于硬限制。Swap 控制:--memory-swap 设置(内存 + swap)总量。若等于 --memory,则禁止容器使用 swap,避免磁盘抖动。OOM 优先级:--oom-score-adj 调整容器被 OOM Killer 选中的概率,值越高越容易被杀。

内存 OOM 流程:

内核 OOM Killercgroup memory 控制器容器进程内核 OOM Killercgroup memory 控制器容器进程#mermaid-svg-umVPRgfv7ZIZSPtm{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-umVPRgfv7ZIZSPtm .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-umVPRgfv7ZIZSPtm .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-umVPRgfv7ZIZSPtm .error-icon{fill:#552222;}#mermaid-svg-umVPRgfv7ZIZSPtm .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-umVPRgfv7ZIZSPtm .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-umVPRgfv7ZIZSPtm .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-umVPRgfv7ZIZSPtm .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-umVPRgfv7ZIZSPtm .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-umVPRgfv7ZIZSPtm .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-umVPRgfv7ZIZSPtm .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-umVPRgfv7ZIZSPtm .marker{fill:#333333;stroke:#333333;}#mermaid-svg-umVPRgfv7ZIZSPtm .marker.cross{stroke:#333333;}#mermaid-svg-umVPRgfv7ZIZSPtm svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-umVPRgfv7ZIZSPtm p{margin:0;}#mermaid-svg-umVPRgfv7ZIZSPtm .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-umVPRgfv7ZIZSPtm text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-umVPRgfv7ZIZSPtm .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-umVPRgfv7ZIZSPtm .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-umVPRgfv7ZIZSPtm .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-umVPRgfv7ZIZSPtm .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-umVPRgfv7ZIZSPtm #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-umVPRgfv7ZIZSPtm .sequenceNumber{fill:white;}#mermaid-svg-umVPRgfv7ZIZSPtm #sequencenumber{fill:#333;}#mermaid-svg-umVPRgfv7ZIZSPtm #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-umVPRgfv7ZIZSPtm .messageText{fill:#333;stroke:none;}#mermaid-svg-umVPRgfv7ZIZSPtm .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-umVPRgfv7ZIZSPtm .labelText,#mermaid-svg-umVPRgfv7ZIZSPtm .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-umVPRgfv7ZIZSPtm .loopText,#mermaid-svg-umVPRgfv7ZIZSPtm .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-umVPRgfv7ZIZSPtm .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-umVPRgfv7ZIZSPtm .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-umVPRgfv7ZIZSPtm .noteText,#mermaid-svg-umVPRgfv7ZIZSPtm .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-umVPRgfv7ZIZSPtm .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-umVPRgfv7ZIZSPtm .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-umVPRgfv7ZIZSPtm .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-umVPRgfv7ZIZSPtm .actorPopupMenu{position:absolute;}#mermaid-svg-umVPRgfv7ZIZSPtm .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-umVPRgfv7ZIZSPtm .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-umVPRgfv7ZIZSPtm .actor-man circle,#mermaid-svg-umVPRgfv7ZIZSPtm line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-umVPRgfv7ZIZSPtm :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}alt[超出硬限制][未超出]申请内存检查 usage_in_bytes >= limit_in_bytes?触发 OOM杀死进程 (OOMKilled)允许分配

五、磁盘 I/O 资源管理

磁盘 I/O 限制通过 blkio cgroup 实现,可限制容器的读写吞吐量和 IOPS,保护存储系统。

相对权重:--blkio-weight(10-1000),在容器间竞争 I/O 时按比例分配带宽。硬限制(带宽/IOPS):--device-read-bps、--device-write-bps、--device-read-iops、--device-write-iops,针对特定块设备设置每秒字节数或操作次数上限。

使用场景:防止批处理或日志容器打满磁盘,影响数据库等关键服务。

六、编排平台中的资源管理

6.1 Docker Compose

在 Compose 文件(v2/v3)中,可通过 deploy.resources(仅 Swarm 模式生效)或 mem_limit、cpus 等旧式键指定资源。Compose 独立部署时主要支持 mem_limit、mem_reservation、cpus 等。

6.2 Docker Swarm

Swarm 服务定义中的 resources 分为 limits 和 reservations:

reservations:调度时的最低保证,节点必须满足。limits:运行时硬限制。

6.3 Kubernetes

Kubernetes 提供了最完善的资源预留与限制模型: 拼多多帮助力入口

Kubernetes 字段对应 cgroup 机制作用spec.containers[].resources.requests.cpucpu.shares调度保证,竞争时权重spec.containers[].resources.limits.cpucpu.cfs_quota_us硬限制,超用限流spec.containers[].resources.requests.memory调度保证,cgroup 软限制决定调度,运行时提供最低内存保障spec.containers[].resources.limits.memorymemory.limit_in_bytes硬限制,超用 OOMKillQoS 等级基于 requests 和 limits 的设定自动推导:

Guaranteed:requests = limits(CPU 和内存都要相等),OOM 最后被杀。Burstable:requests < limits,中等优先级。BestEffort:未设任何 requests/limits,最先被 OOM Kill。

决策流程图:

#mermaid-svg-TjY8HdslAfapHcWR{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-TjY8HdslAfapHcWR .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-TjY8HdslAfapHcWR .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-TjY8HdslAfapHcWR .error-icon{fill:#552222;}#mermaid-svg-TjY8HdslAfapHcWR .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-TjY8HdslAfapHcWR .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-TjY8HdslAfapHcWR .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-TjY8HdslAfapHcWR .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-TjY8HdslAfapHcWR .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-TjY8HdslAfapHcWR .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-TjY8HdslAfapHcWR .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-TjY8HdslAfapHcWR .marker{fill:#333333;stroke:#333333;}#mermaid-svg-TjY8HdslAfapHcWR .marker.cross{stroke:#333333;}#mermaid-svg-TjY8HdslAfapHcWR svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-TjY8HdslAfapHcWR p{margin:0;}#mermaid-svg-TjY8HdslAfapHcWR .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-TjY8HdslAfapHcWR .cluster-label text{fill:#333;}#mermaid-svg-TjY8HdslAfapHcWR .cluster-label span{color:#333;}#mermaid-svg-TjY8HdslAfapHcWR .cluster-label span p{background-color:transparent;}#mermaid-svg-TjY8HdslAfapHcWR .label text,#mermaid-svg-TjY8HdslAfapHcWR span{fill:#333;color:#333;}#mermaid-svg-TjY8HdslAfapHcWR .node rect,#mermaid-svg-TjY8HdslAfapHcWR .node circle,#mermaid-svg-TjY8HdslAfapHcWR .node ellipse,#mermaid-svg-TjY8HdslAfapHcWR .node polygon,#mermaid-svg-TjY8HdslAfapHcWR .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-TjY8HdslAfapHcWR .rough-node .label text,#mermaid-svg-TjY8HdslAfapHcWR .node .label text,#mermaid-svg-TjY8HdslAfapHcWR .image-shape .label,#mermaid-svg-TjY8HdslAfapHcWR .icon-shape .label{text-anchor:middle;}#mermaid-svg-TjY8HdslAfapHcWR .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-TjY8HdslAfapHcWR .rough-node .label,#mermaid-svg-TjY8HdslAfapHcWR .node .label,#mermaid-svg-TjY8HdslAfapHcWR .image-shape .label,#mermaid-svg-TjY8HdslAfapHcWR .icon-shape .label{text-align:center;}#mermaid-svg-TjY8HdslAfapHcWR .node.clickable{cursor:pointer;}#mermaid-svg-TjY8HdslAfapHcWR .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-TjY8HdslAfapHcWR .arrowheadPath{fill:#333333;}#mermaid-svg-TjY8HdslAfapHcWR .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-TjY8HdslAfapHcWR .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-TjY8HdslAfapHcWR .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-TjY8HdslAfapHcWR .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-TjY8HdslAfapHcWR .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-TjY8HdslAfapHcWR .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-TjY8HdslAfapHcWR .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-TjY8HdslAfapHcWR .cluster text{fill:#333;}#mermaid-svg-TjY8HdslAfapHcWR .cluster span{color:#333;}#mermaid-svg-TjY8HdslAfapHcWR div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-TjY8HdslAfapHcWR .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-TjY8HdslAfapHcWR rect.text{fill:none;stroke-width:0;}#mermaid-svg-TjY8HdslAfapHcWR .icon-shape,#mermaid-svg-TjY8HdslAfapHcWR .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-TjY8HdslAfapHcWR .icon-shape p,#mermaid-svg-TjY8HdslAfapHcWR .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-TjY8HdslAfapHcWR .icon-shape .label rect,#mermaid-svg-TjY8HdslAfapHcWR .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-TjY8HdslAfapHcWR .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-TjY8HdslAfapHcWR .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-TjY8HdslAfapHcWR :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}是否CPU 超限内存超限Pod 调度节点剩余资源 >= 所有容器 requests 之和?调度成功Pending,调度失败容器运行实际使用 > limits?CPU 限流OOM Kill

七、最佳实践

实践说明总是设置内存限制避免失控进程耗尽宿主机内存为 Java 应用预留足够堆外内存limits.memory ≥ Xmx + Metaspace + 线程栈 + 直接内存 + 系统预留CPU 使用硬限制保护关键服务防止一个服务吃掉所有 CPU使用 Guaranteed QoS 为关键服务保障稳定的 CPU 和内存,降低被 OOM 风险监控限流和 OOM 事件通过 cpu.stat 的 nr_throttled 和 OOMKilled 容器指标,及时调整配置避免过度预留预留过多会导致资源利用率低,合理压测后设定

八、思维导图总结

#mermaid-svg-foatUNfdarpWCgF9{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-foatUNfdarpWCgF9 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-foatUNfdarpWCgF9 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-foatUNfdarpWCgF9 .error-icon{fill:#552222;}#mermaid-svg-foatUNfdarpWCgF9 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-foatUNfdarpWCgF9 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-foatUNfdarpWCgF9 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-foatUNfdarpWCgF9 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-foatUNfdarpWCgF9 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-foatUNfdarpWCgF9 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-foatUNfdarpWCgF9 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-foatUNfdarpWCgF9 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-foatUNfdarpWCgF9 .marker.cross{stroke:#333333;}#mermaid-svg-foatUNfdarpWCgF9 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-foatUNfdarpWCgF9 p{margin:0;}#mermaid-svg-foatUNfdarpWCgF9 .edge{stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .section--1 rect,#mermaid-svg-foatUNfdarpWCgF9 .section--1 path,#mermaid-svg-foatUNfdarpWCgF9 .section--1 circle,#mermaid-svg-foatUNfdarpWCgF9 .section--1 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section--1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section--1 text{fill:#ffffff;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon--1{font-size:40px;color:#ffffff;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge--1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth--1{stroke-width:17;}#mermaid-svg-foatUNfdarpWCgF9 .section--1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-0 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-0 path,#mermaid-svg-foatUNfdarpWCgF9 .section-0 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-0 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-foatUNfdarpWCgF9 .section-0 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-0{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-0{stroke-width:14;}#mermaid-svg-foatUNfdarpWCgF9 .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-1 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-1 path,#mermaid-svg-foatUNfdarpWCgF9 .section-1 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-1 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-1 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-1{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-1{stroke-width:11;}#mermaid-svg-foatUNfdarpWCgF9 .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-2 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-2 path,#mermaid-svg-foatUNfdarpWCgF9 .section-2 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-2 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-2 text{fill:#ffffff;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-2{stroke-width:8;}#mermaid-svg-foatUNfdarpWCgF9 .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-3 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-3 path,#mermaid-svg-foatUNfdarpWCgF9 .section-3 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-3 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-3 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-3{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-3{stroke-width:5;}#mermaid-svg-foatUNfdarpWCgF9 .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-4 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-4 path,#mermaid-svg-foatUNfdarpWCgF9 .section-4 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-4 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-4 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-4{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-4{stroke-width:2;}#mermaid-svg-foatUNfdarpWCgF9 .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-5 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-5 path,#mermaid-svg-foatUNfdarpWCgF9 .section-5 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-5 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-5 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-5{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-5{stroke-width:-1;}#mermaid-svg-foatUNfdarpWCgF9 .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-6 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-6 path,#mermaid-svg-foatUNfdarpWCgF9 .section-6 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-6 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-6 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-6{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-6{stroke-width:-4;}#mermaid-svg-foatUNfdarpWCgF9 .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-7 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-7 path,#mermaid-svg-foatUNfdarpWCgF9 .section-7 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-7 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-7 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-7{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-7{stroke-width:-7;}#mermaid-svg-foatUNfdarpWCgF9 .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-8 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-8 path,#mermaid-svg-foatUNfdarpWCgF9 .section-8 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-8 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-8 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-8{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-8{stroke-width:-10;}#mermaid-svg-foatUNfdarpWCgF9 .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-9 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-9 path,#mermaid-svg-foatUNfdarpWCgF9 .section-9 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-9 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-9 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-9{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-9{stroke-width:-13;}#mermaid-svg-foatUNfdarpWCgF9 .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-10 rect,#mermaid-svg-foatUNfdarpWCgF9 .section-10 path,#mermaid-svg-foatUNfdarpWCgF9 .section-10 circle,#mermaid-svg-foatUNfdarpWCgF9 .section-10 polygon,#mermaid-svg-foatUNfdarpWCgF9 .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-10 text{fill:black;}#mermaid-svg-foatUNfdarpWCgF9 .node-icon-10{font-size:40px;color:black;}#mermaid-svg-foatUNfdarpWCgF9 .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .edge-depth-10{stroke-width:-16;}#mermaid-svg-foatUNfdarpWCgF9 .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-foatUNfdarpWCgF9 .disabled,#mermaid-svg-foatUNfdarpWCgF9 .disabled circle,#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:lightgray;}#mermaid-svg-foatUNfdarpWCgF9 .disabled text{fill:#efefef;}#mermaid-svg-foatUNfdarpWCgF9 .section-root rect,#mermaid-svg-foatUNfdarpWCgF9 .section-root path,#mermaid-svg-foatUNfdarpWCgF9 .section-root circle,#mermaid-svg-foatUNfdarpWCgF9 .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-foatUNfdarpWCgF9 .section-root text{fill:#ffffff;}#mermaid-svg-foatUNfdarpWCgF9 .section-root span{color:#ffffff;}#mermaid-svg-foatUNfdarpWCgF9 .section-2 span{color:#ffffff;}#mermaid-svg-foatUNfdarpWCgF9 .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-foatUNfdarpWCgF9 .edge{fill:none;}#mermaid-svg-foatUNfdarpWCgF9 .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-foatUNfdarpWCgF9 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}容器资源预留与限制核心概念预留 = 保证最低量限制 = 设定最大量底层机制cgroups 子系统cpu: quota/sharesmemory: limit_in_bytes/soft_limitblkio: weight/throttleCPU 管理-cpus-cpu-sharescpuset 绑定内存管理-memory-memory-reservationOOM 控制磁盘 I/O-blkio-weight带宽/IOPS 硬限制编排平台Docker Compose/SwarmKubernetes requests/limitsGuaranteed/Burstable/BestEffort最佳实践内存限制必备Java 需预留堆外监控限流与 OOM

通过掌握上述理论,您可以系统性地阐述如何为容器化 Java 应用进行资源规划与管理,保证服务稳定性并最大化资源利用率。

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧