feat(core,board,ecommerce,page): 성능 계측 인프라 4축 확장 및 계측 대상 선언 지점 신설

계측 축이 "목록 SELECT" 하나였고 프로파일 12종이 커맨드 파일에 하드코딩돼
있어 확장이 자기 대상을 추가할 수 없었다. 확장이 설치·제거되는 설치본마다
"실제로 존재하는 대상"이 달라지므로, 대상을 소유자가 선언하고 코어가 수집하도록
뒤집었다.

- 선언 지점 두 곳, 스키마 하나: 코어 config/benchmark.php,
 확장 getBenchmarkProfiles (모듈/플러그인). 수집은 method_exists 기반이라
 인터페이스를 직접 구현한 서드파티 확장이 깨지지 않는다.
- 축 4종(목록/화면/쓰기/배치)을 실행기로 분리하고 컨테이너 태그로 주입 —
 축이 늘 때 커맨드를 고치지 않는다.
- 화면 축은 HTTP 커널로 내부 요청을 처리한다. 라우트만 dispatch 하면 전역
 미들웨어를 건너뛰어 화면과 다른 것을 재게 된다. 인증은 프로파일이 선언한
 권한만 가진 임시 계정이 기본이며 --as 로 기존 계정을 지목할 수 있다.
- 화면/쓰기 축은 계측 계정 생성부터 처리까지 롤백되는 트랜잭션 안에서 실행해
 운영 DB 에도 잔여 데이터를 남기지 않는다. 배치 축은 내부 커밋·락 보유 때문에
 감싸지 않고 --allow-write 로만 통제한다.
- 잘못된 선언은 조용히 버리지 않고 사유를 경고로 남긴다. 버려진 선언이 곧
 계측 사각이 되기 때문이다. 전부 건너뛴 실행은 종료 코드 1 로 끝난다.
- 리포트는 환경 정보를 함께 적어 저장소 밖(storage/app/benchmarks)에 남긴다.
 측정값이 실행 머신에 종속되므로 저장소에 축적하면 비교 불가능한 수치가 섞인다.

작업 중 발견해 함께 고친 것:

- 이관 프로파일 3종의 soft_delete 선언이 실제 스키마와 어긋나 있었다
 (users/product_inquiries/pages 에 deleted_at 없음).
- 주문 목록이 상태 미지정 시 임시 주문 상태를 NOT IN 으로 제외하는데 선언에
 빠져 있었다. filters 가 등가 비교만 지원한 것이 근본 원인이라 연산자 형태를
 받도록 넓히고, 미허용 연산자는 측정 전에 거부한다.
- 댓글 프로파일은 지배적 술어가 상관 서브쿼리라 선언형으로 재현할 수 없어
 제거했다. 맨 테이블 스캔은 어느 화면도 내지 않는 수치가 된다.

g7:bench:pagination → g7:bench 로 개명(4축을 재므로). 이전 이름은 별칭으로 남겼다.

테스트 61건 통과, 라이브 18종 전건 측정.
This commit is contained in:
HeuJung committed 2026-08-02 14:44:33 +09:00
1 parent be9befe023
commit 5f4a733b3b
40 files changed
+5266 -567

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
<?php
namespace App\Benchmark\DTO;
use App\Enums\BenchmarkAxis;
/**
* 계측 프로파일 — 코어 config / 확장 선언에서 수집된 계측 대상 1건 (Value Object)
*
* 레지스트리가 선언 배열을 검증해 이 객체로 정규화하고, 축 실행기가 그대로 받아 씁니다.
* 축별 옵션 스키마가 서로 다르므로 공통 필드(키·축·출처·라벨)만 프로퍼티로 승격하고
* 축 고유 옵션은 `options` 에 남깁니다 — 축이 늘 때 VO 를 고치지 않아도 되게 합니다.
*/
final readonly class BenchmarkProfile
{
/**
* @param string $key 선언된 프로파일 키 (확장 내부에서만 고유)
* @param BenchmarkAxis $axis 계측 축
* @param string $sourceKind 출처 종류 (core|module|plugin)
* @param string $sourceIdentifier 출처 식별자 (코어는 'core')
* @param array<string, mixed> $options 축 고유 옵션
* @param string|null $label 표시용 설명
*/
public function __construct(
public string $key,
public BenchmarkAxis $axis,
public string $sourceKind,
public string $sourceIdentifier,
public array $options = [],
public ?string $label = null,
) {}
/**
* 출처를 포함한 전역 고유 키를 반환합니다.
*
* 서로 다른 확장이 같은 키(`orders` 등)를 선언할 수 있으므로 충돌 시에는 이 키로
* 지목합니다. 커맨드는 짧은 키가 유일할 때만 짧은 키를 허용합니다.
*
* @return string `{출처}/{키}` 형태의 정규화 키
*/
public function qualifiedKey(): string
{
return $this->sourceIdentifier.'/'.$this->key;
}
/**
* 축 고유 옵션 값을 읽습니다.
*
* @param string $name 옵션 키
* @param mixed $default 미선언 시 기본값
* @return mixed 옵션 값
*/
public function option(string $name, mixed $default = null): mixed
{
return $this->options[$name] ?? $default;
}
/**
* 이 프로파일 실행이 데이터를 변경하는지 판정합니다.
*
* 축 기본값을 쓰되, 프로파일이 `mutating` 을 명시하면 그 선언을 따릅니다.
* `screen` 축은 GET 이 아니면 변경으로 봅니다.
*
* @return bool 데이터 변경 여부
*/
public function mutates(): bool
{
$declared = $this->options['mutating'] ?? null;
if (is_bool($declared)) {
return $declared;
}
if ($this->axis === BenchmarkAxis::Screen) {
return strtoupper((string) $this->option('method', 'GET')) !== 'GET';
}
return $this->axis->mutatesByDefault();
}
/**
* 배열로 직렬화합니다. (`--json` / 리포트 출력용)
*
* @return array<string, mixed> 직렬화 결과
*/
public function toArray(): array
{
return [
'key' => $this->key,
'qualified_key' => $this->qualifiedKey(),
'axis' => $this->axis->value,
'source' => ['kind' => $this->sourceKind, 'identifier' => $this->sourceIdentifier],
'label' => $this->label,
'options' => $this->options,
];
}
}
+68
View File
@@ -0,0 +1,68 @@
<?php
namespace App\Benchmark\DTO;
/**
* 계측 결과 1건 — 축 실행기의 산출물 (Value Object)
*
* 출력기(`BenchmarkReporter`)가 축을 몰라도 표/JSON/마크다운을 만들 수 있도록,
* 표시용 표(`headers`/`rows`)와 기계 판독용 수치(`metrics`)를 함께 담습니다.
* 축이 늘어날 때 출력기를 고치지 않아도 되는 지점이 여기입니다.
*/
final readonly class BenchmarkResult
{
/**
* @param BenchmarkProfile $profile 계측 대상 프로파일
* @param array<int, string> $headers 표 헤더
* @param array<int, array<int, string>> $rows 표 행 (표시용 문자열)
* @param array<string, mixed> $metrics 기계 판독용 원시 수치
* @param array<int, string> $notes 부가 설명 줄 (실행 계획, N+1 후보 등)
* @param bool $skipped 실행하지 않았는지 여부
* @param string|null $skipReason 실행하지 않은 사유
*/
public function __construct(
public BenchmarkProfile $profile,
public array $headers = [],
public array $rows = [],
public array $metrics = [],
public array $notes = [],
public bool $skipped = false,
public ?string $skipReason = null,
) {}
/**
* 실행하지 않은 결과를 만듭니다.
*
* 실패/건너뜀을 결과 목록에서 빼면 리포트가 "전부 측정됨"으로 읽히므로, 사유를 담은
* 결과로 남겨 표와 JSON 양쪽에 드러냅니다.
*
* @param BenchmarkProfile $profile 대상 프로파일
* @param string $reason 건너뛴 사유
* @return self 건너뜀 결과
*/
public static function skipped(BenchmarkProfile $profile, string $reason): self
{
return new self(profile: $profile, skipped: true, skipReason: $reason);
}
/**
* 배열로 직렬화합니다.
*
* @return array<string, mixed> 직렬화 결과
*/
public function toArray(): array
{
return [
'profile' => $this->profile->qualifiedKey(),
'axis' => $this->profile->axis->value,
'label' => $this->profile->label,
'source' => ['kind' => $this->profile->sourceKind, 'identifier' => $this->profile->sourceIdentifier],
'skipped' => $this->skipped,
'skip_reason' => $this->skipReason,
'headers' => $this->headers,
'rows' => $this->rows,
'metrics' => $this->metrics,
'notes' => $this->notes,
];
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace App\Benchmark\DTO;
/**
* 계측 실행 옵션 — 커맨드 옵션을 축 실행기로 한 번 전달하는 값 묶음 (Value Object)
*
* 축마다 쓰는 옵션이 다르지만(offsets 는 list 축만, allowWrite 는 write/batch 축만)
* 실행기 시그니처를 하나로 두기 위해 한 객체로 모읍니다.
*/
final readonly class BenchmarkRunOptions
{
/**
* @param array<int, int> $offsets 측정할 OFFSET 목록 (list 축)
* @param int $runs 측정 횟수 (첫 회는 버림)
* @param int $seed 계측 전 합성 행 시딩 건수 (0 = 시딩 안 함, list 축)
* @param bool $fresh 시딩 전 대상 테이블 비움 (list 축)
* @param bool $explain 실행 계획 수집 (list 축)
* @param bool $allowWrite 데이터 변경 축 실행 허용
* @param string|null $asUser 계측에 사용할 기존 계정 (ID 또는 이메일, screen 축)
* @param int $perPage 목록/화면 1페이지 건수
*/
public function __construct(
public array $offsets = [0],
public int $runs = 3,
public int $seed = 0,
public bool $fresh = false,
public bool $explain = false,
public bool $allowWrite = false,
public ?string $asUser = null,
public int $perPage = 20,
) {}
/**
* 배열로 직렬화합니다. (리포트의 실행 조건 기재용)
*
* @return array<string, mixed> 직렬화 결과
*/
public function toArray(): array
{
return [
'offsets' => $this->offsets,
'runs' => $this->runs,
'seed' => $this->seed,
'fresh' => $this->fresh,
'explain' => $this->explain,
'allow_write' => $this->allowWrite,
'as_user' => $this->asUser,
'per_page' => $this->perPage,
];
}
}