optimize-docker-compose-resources

在 PHP 技术栈中优化 Docker Compose 资源分配的指南与配置示例,涉及内存限制、CPU 约束和服务扩展策略以改善本地与测试环境的资源使用。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "optimize-docker-compose-resources":https://skillpi.com/zh/skills/deepskill-0aa5d3c62e1226c5918e99344ac7a5ee6720f889830685715f76f48069b20f46。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

在 PHP 技术栈中优化 Docker Compose 资源分配的指南与配置示例,涉及内存限制、CPU 约束和服务扩展策略以改善本地与测试环境的资源使用。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: optimize-docker-compose-resources
description: Optimizes Docker Compose resource allocation for PHP stacks. Configures memory limits, CPU constraints, and service scaling.

Docker Compose Resource Optimization

Configures resource allocation, constraints, and scaling for PHP application stacks.

Resource Allocation Overview

┌─────────────────────────────────────────────────────────────────┐
│            PHP STACK RESOURCE DISTRIBUTION (4GB Host)            │
├─────────────────────────────────────────────────────────────────┤
│  PHP-FPM:   ████████████████████░░░░░░░░░░  1024MB  (25%)     │
│  MySQL:     ████████████████████████░░░░░░  1536MB  (38%)     │
│  Redis:     ████████░░░░░░░░░░░░░░░░░░░░░░   512MB  (13%)    │
│  Nginx:     ████░░░░░░░░░░░░░░░░░░░░░░░░░░   256MB   (6%)    │
│  RabbitMQ:  ████████░░░░░░░░░░░░░░░░░░░░░░   512MB  (13%)    │
│  System:    ████░░░░░░░░░░░░░░░░░░░░░░░░░░   256MB   (6%)    │
└─────────────────────────────────────────────────────────────────┘

Recommended Resource Limits

Service Memory Limit Memory Reservation CPU Limit CPU Reservation
PHP-FPM 512MB-1GB 256MB 1.0 0.25
Nginx 128MB-256MB 64MB 0.5 0.1
MySQL 1GB-2GB 512MB 1.5 0.5
PostgreSQL 1GB-2GB 512MB 1.5 0.5
Redis 256MB-512MB 128MB 0.5 0.1
RabbitMQ 512MB-1GB 256MB 1.0 0.25

Service Configurations

PHP-FPM

  php-fpm:
    deploy:
      resources:
        limits: { cpus: "1.0", memory: 1024M }
        reservations: { cpus: "0.25", memory: 256M }
      replicas: 2
    tmpfs: ["/tmp:size=64M"]
    healthcheck:
      test: ["CMD", "php-fpm-healthcheck"]
      interval: 30s
      timeout: 5s
      start_period: 10s

MySQL

  mysql:
    deploy:
      resources:
        limits: { cpus: "1.5", memory: 2048M }
        reservations: { cpus: "0.5", memory: 512M }
    shm_size: "256m"
    command: >
      --innodb-buffer-pool-size=1G --innodb-log-file-size=256M
      --max-connections=200 --tmp-table-size=64M
    ulimits:
      nofile: { soft: 65536, hard: 65536 }

Redis

  redis:
    deploy:
      resources:
        limits: { cpus: "0.5", memory: 512M }
        reservations: { cpus: "0.1", memory: 128M }
    command: redis-server --maxmemory 384mb --maxmemory-policy allkeys-lru --save "" --appendonly no
    tmpfs: ["/data:size=384M"]

RabbitMQ

  rabbitmq:
    deploy:
      resources:
        limits: { cpus: "1.0", memory: 1024M }
        reservations: { cpus: "0.25", memory: 256M }
    environment:
      RABBITMQ_VM_MEMORY_HIGH_WATERMARK: 0.6
      RABBITMQ_DISK_FREE_LIMIT: 128MB

Logging Configuration

    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"
Service max-size max-file Total Disk
PHP-FPM 10m 3 30MB
Nginx 20m 5 100MB
MySQL 10m 3 30MB
Redis 5m 2 10MB

tmpfs for Ephemeral Data

    tmpfs:
      - /tmp:size=64M,mode=1777
      - /app/var/cache:size=128M
      - /app/var/log:size=32M

Benefits: faster I/O, no disk writes, auto-cleaned on restart.

shm_size for Databases

  postgres:
    shm_size: "256m"   # shared_buffers, WAL buffers, lock tables
  mysql:
    shm_size: "256m"   # InnoDB buffer pool, temp tables

ulimits Configuration

ulimit Default Recommended Purpose
nofile 1024 65536 Max open files/sockets
nproc 1024 4096 Max processes
memlock 64KB unlimited Memory locking (Redis)

Scaling with Replicas

  php-fpm:
    deploy:
      replicas: 3
      endpoint_mode: dnsrr
      resources:
        limits: { cpus: "0.5", memory: 512M }
    # Total: 1.5 CPU, 1536M memory across 3 replicas
    # Nginx resolves php-fpm to all replicas via DNS round-robin

Before/After Comparison

Metric No Limits With Limits Improvement
OOM kills Frequent Rare Predictable
Noisy neighbor Common Prevented Isolated
Memory waste 30-50% < 10% -80% waste
Log disk usage Unbounded < 200MB Controlled
Recovery time Minutes Seconds Faster restarts

Generation Instructions

  1. Inventory services: List all containers in the stack
  2. Assess host resources: Total CPU and memory available
  3. Allocate proportionally: Database > App > Cache > Proxy
  4. Set limits and reservations: Limits cap usage, reservations guarantee minimum
  5. Configure logging: Prevent unbounded disk growth
  6. Add health checks: Enable automatic recovery
  7. Test under load: Verify no OOM kills or throttling

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值78/100

亮点

  • 针对PHP技术栈的Docker Compose资源优化,解决实际部署痛点
  • 提供详细的资源配置建议和最佳实践
  • 包含内存、CPU、日志、tmpfs等多维度优化方案
触发精准85/100

亮点

  • 触发词覆盖PHP、Docker Compose、资源分配等核心关键词
  • description清晰准确,边界定义明确
  • 支持多种资源优化场景的触发
结构规范92/100

亮点

  • 文档结构清晰,分模块详细说明
  • 提供完整的配置示例和参数说明
  • 包含before/after对比和最佳实践指导
执行可靠88/100

亮点

  • 配置参数经过验证,来源可靠
  • 包含健康检查和自动恢复机制
  • 覆盖主要异常场景的处理方案
证据可验 (前四项均值)86/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。