Magento 2 성능 회귀 테스트: CI에서 속도 저하 포착

작성자

카테고리:

← 피드로
DEV Community · Magevanta · 2026-08-25 개발(SW)

Magevanta

You’ve spent weeks tuning Magento 2. Redis is warm, Varnish is humming, your slow SQL is gone, and the storefront scores in the green. Then a two-line change to a tax observer ships on a Friday, and on Monday your TTFB is up 400ms and the checkout queue is backing up.

Performance is not a one-time project. It’s a property you have to protect, and the only way to protect it inside a busy codebase is to make slowdowns fail the build. This is what performance regression testing is about: automated, repeatable checks wired into your CI pipeline that tell you before a deployment — not after — that something got slower.

In this post I’ll walk through a practical, layered approach to Magento 2 performance regression testing that works whether you’re a two-person agency or a large merchant platform: define budgets, measure in CI, gate your merges, and make the numbers trustworthy enough that your team actually believes them.

1. Start with a performance budget, not a dashboard

The most common mistake is building a monitoring dashboard first and a decision rule second. Dashboards don’t block anything. A budget is a hard, written threshold that a pull request must respect: “the home page must render in under 2.0s on a mid-tier test instance” or “the product listing endpoint must complete 95% of requests in under 300ms.”

Define budgets for the few metrics that actually matter to your business, not fifty vanity numbers:

  • Time to First Byte (TTFB) — catches backend/HTTP-cache regressions instantly.
  • Largest Contentful Paint (LCP) — the SEO/Core Web Vitals metric that tracks the real render experience.
  • Cumulative Layout Shift (CLS) and Total Blocking Time (TBT) — frontend regressions (image dimensions, unoptimized JS).
  • A “catalog math” budget like cost per price-reindex or query time for your heaviest listing — catches the slow SQL that a browser test would never see.

Write these budgets down in a file in your repo. The moment a budget is only in someone’s head is the moment it stops being enforced.

2. Layer 1: Lighthouse in CI for real storefront metrics

Lighthouse CI is the cheapest, highest-leverage tool you can add. It runs a headless Chrome pass against a dedicated test environment and compares the result against a budget file.

A minimal lighthouserc.cjs:

module.exports = {
  ci: {
    collect: {
      url: [
        'https://staging.example.com/',
        'https://staging.example.com/checkout/cart'
      ],
      numberOfRuns: 3,
      settings: { preset: 'desktop' }
    },
    assert: {
      assertions: {
        'categories:performance': ['error', { minScore: 0.9 }],
        'largest-contentful-paint': ['error', { maxNumericValue: 2500 }],
        'total-blocking-time': ['error', { maxNumericValue: 200 }],
        'cumulative-layout-shift': ['error', { maxNumericValue: 0.1 }]
      }
    },
    upload: {
      target: 'filesystem',
      outputDir: 'lhci-reports'
    }
  }
};

Enter fullscreen mode Exit fullscreen mode

Wire it into your pipeline with a small job that deploys to staging, waits for cache warm, then runs lhci autorun. The assert block is your gate: if any assertion fails, the pipeline fails and the PR is blocked.

Critical detail: never run Lighthouse against production during a deploy race, and never run it against a cold cache. Always point it at a stable staging environment with Varnish/Redis warmed the same way every time, or the numbers will be noise and your team will learn to ignore the gate.

3. Layer 2: Backend micro-benchmarks with curl and Blackfire

Browser metrics catch the frontend, but the worst Magento regressions live deep in the backend: an injected plugin, a rewritten repository method, an N+1 that only appears under a specific customer context. For those you need two more layers.

HTTP-level budget checks. Use curl against your staging storefront. A CI step can hit a few canonical routes (home, a category listing, a product page, the GraphQL products query) and emit TTFB and transfer times. Keep those as a historical series and assert against a threshold. This catches the “the whole storefront got slower” class of bug cheaply.

Profiling gates with Blackfire. Blackfire is among the most Magento-aware profilers available, and it has a dedicated CI mode. You define a set of “scenarios” (URLs or CLI commands), and Blackfire runs them and compares wall time and memory against a baseline config file:

scenarios:
  home:
    url: "https://staging.example.com/"
    assertions:
      - "main.wall_time < 5s"
      - "main.peak_memory < 256MB"
  product_listing:
    url: "https://staging.example.com/bestsellers.html"
    assertions:
      - "main.wall_time < 8s"

Enter fullscreen mode Exit fullscreen mode

Backend assertions are the only way to enforce things like total SQL queries or provider calls per request. If you know a listing should touch the database fewer than 80 times, encode it as a budget and let the profiler enforce it.

4. Layer 3: Synthetic “catalog math” budgets

Not everything is a live HTTP request. Magento has operations — reindexing, cache flushing, product imports, cron runs — that are more expensive to measure in flight but frequent enough that a regression in them becomes a production incident.

Budget these with simple timed commands in CI:

# Fail if a full price reindex slips past a threshold
time php bin/magento indexer:reindex catalog_product_price

Enter fullscreen mode Exit fullscreen mode

Wrap them with a threshold check. A cleaner approach is a tiny custom console command that measures and compares against a stored baseline, so the comparison lives in code:

$threshold = 120; // seconds — your budget
$start = microtime(true);
$this->reindexer->reindexAll('catalog_product_price');
if (microtime(true) - $start > $threshold) {
    throw new RuntimeException('Price reindex exceeded budget');
}

Enter fullscreen mode Exit fullscreen mode

These backend/perf-ops budgets are the ones that catch the dangerous, non-obvious regressions — like the mview or dimension-multiplication changes that silently double a reindex — before they cause a weekend incident.

5. Make the numbers trustworthy

None of this works if your team treats the performance gate as a formality to be bypassed. Three things make budgets credible:

  1. A stable, reproducible environment. The CI performance instance must be dedicated, same spec, same cache state, same data volume every run. If staging is shared with manual testers, spin up an isolated environment for the perf job.
  2. Sane tolerance, not flakiness. Network and CPU vary. Give TTFB/LCP a tolerance band (for example, assert against the median of 3 runs, not a single shot) and allow an explicit, time-boxed budget-bump process rather than an “ignore forever” flag.
  3. Trend, not just pass/fail. Ship your numbers to a store (a CSV, a lightweight metrics file, or a monitoring tool). Pass/fail alone is blind to slow drift; seeing TTFB creep from 1.8s to 1.95s over two weeks warns you long before it crosses the 2.0s line.

6. The minimum viable setup

If you’re starting from zero, here’s the smallest thing that provides real protection on day one:

  1. Add a performance-budget file with three budgets: LCP ≤ 2.5s, home TTFB ≤ 500ms, price-reindex ≤ 120s.
  2. Get Lighthouse CI running against your staging on every pull request to master.
  3. Add one curl-based TTFB check and one timed reindex check to the same pipeline.
  4. Enforce the gate: failing budget blocks the merge. Optionally allow a merge exception with an explicit ticket and a 7-day deadline.

That’s it. From there, layer in Blackfire scenarios and synthetic catalog-math budgets as your maturity grows.

Conclusion

Performance regression testing turns “we’ll keep an eye on it” into “the build will catch it.” It’s not about impressive dashboards — it’s about a handful of honest budgets, a stable test environment, and a CI gate your team respects. Magento 2 is fast when you defend it; automated regression testing is how you defend it without hoping everyone remembers.

Start small: three budgets, one stable environment, one enforced gate. The slowdown you catch before Friday’s deploy is the one your customers never see.

원문에서 계속 ↗