Skip to content

Memory creep in production: WordPress containers steadily consume more memory (AWS ECS / EC2) - investigation required (--prod) - #80

Description

@MartinPaulEve

Summary

Production WordPress deployment is showing a steady increase in memory usage over time (memory creep), which appears to grow until the container is at risk of crashing. We are running on AWS ECS using EC2-backed containers.

Environment

  • Repository: MESH-Research/knowledge-commons-wordpress
  • Deployment: production (ECS, EC2 launch type)
  • Service: wordpress-prod (multiple color instances: wp-green / wp-blue)

Observed behavior

  • One of the WordPress production containers (wp-green) exhibits a gradual upward trend in memory utilization over multiple days.
  • Periodic spikes are visible, but the baseline memory usage slowly increases over time (see evidence below).
  • This behaviour suggests a memory leak or accumulation of in-memory state that is not released, ultimately increasing the risk of container OOM and crash.

Evidence

  • CloudWatch/monitoring graph showing memory utilization for production containers (one-week window):
WP memory utilization
  • The green series (wordpress-prod-3 wp-green) shows a clear upward trend from ~20% to ~40% (and higher on spikes) across the captured timeframe.
  • The orange series (wp-cron) shows frequent short spikes (cron activity) but does not explain the persistent baseline increase.

Impact

  • Production stability risk: containers may reach memory limits and be terminated / restarted by ECS, causing degraded performance or downtime for end users.
  • Potential data-loss risk is low (stateless containers with persistent storage elsewhere) but restarts increase error rates and user-visible errors.

Suspected causes

  • Long-running PHP processes (PHP-FPM) or a plugin/theme causing memory to be retained between requests.
  • Improper object caching configuration (in-memory caches persisting beyond intended lifecycle).
  • Background jobs or cron tasks (wp-cron) accumulating state or leaking memory on repeated execution.
  • Native extension or third-party library (e.g., image processing, search indexing) leaking memory.

Immediate mitigation suggestions

  • Temporarily reduce container memory reservation/limit or add an automated restart policy to recycle containers before they hit OOM (short-term stopgap).
  • Scale out additional ECS tasks to reduce pressure on individual containers while investigating.
  • Disable or roll back recent plugin/theme changes deployed shortly before the trend began (if applicable).

Recommended investigation steps

  1. Collect more detailed runtime diagnostics from an affected container:
    • PHP-FPM status and process list (top/ps) over time.
    • per-process memory usage (e.g., ps aux --sort=-rss, pmap, smem) and heap snapshots where feasible.
    • PHP error logs and slow logs around spike times.
    • List of active plugins and recent changes/deploys.
  2. Reproduce in a staging environment with high-traffic/certain cron schedules to see whether memory grows similarly.
  3. Run memory-profiler on PHP (e.g., Xdebug/profiler, Blackfire, or other tools) for longer-running worker processes.
  4. Check object-cache (Redis/Memcached) configuration and any in-memory object retention code paths.
  5. Inspect background jobs / WP-Cron tasks for accumulating data or failing to free resources.
  6. Correlate memory spikes with deployment events and cron spikes shown in the monitoring graph.

Priority

  • High: production stability is affected and the issue can lead to container restarts and user-visible errors.

Attachments

  • Monitoring graph included above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions