DBAtlas · 데이터베이스 운영 아틀라스

JIT 컴파일이 쿼리 시간에 미치는 영향 측정

PostgreSQL성능

명령어

-- Share of JIT time in total execution time (PG15+)
SELECT queryid,
       calls,
       jit_functions,
       round((jit_generation_time + jit_inlining_time + jit_optimization_time + jit_emission_time)::numeric, 1) AS jit_ms,
       round(total_exec_time::numeric, 1) AS total_ms,
       round((100 * (jit_generation_time + jit_inlining_time + jit_optimization_time + jit_emission_time)
             / NULLIF(total_exec_time, 0))::numeric, 1) AS jit_pct,
       left(regexp_replace(query, '\s+', ' ', 'g'), 100) AS query
FROM pg_stat_statements
WHERE jit_functions > 0
ORDER BY jit_pct DESC NULLS LAST
LIMIT 20;

-- Compare on a single query: check the "JIT:" section at the end of the output and Execution Time
SET jit = on;
EXPLAIN (ANALYZE) SELECT city, sum(balance) FROM customer GROUP BY city;
SET jit = off;
EXPLAIN (ANALYZE) SELECT city, sum(balance) FROM customer GROUP BY city;
RESET jit;

하는 일

쿼리별로 실행 시간 중 JIT 컴파일 시간(generation, inlining, optimization, emission)의 비중을 보여 주고, JIT를 켜고 끈 상태로 같은 쿼리를 실행해 순 효과를 측정한다.

사용 시점

짧은 OLTP나 보고서 쿼리에 수십~수백 ms의 원인 불명 지연이 있을 때. 특히 비용 추정이 부풀어 JIT가 트리거되는 파티션이 많은 테이블에서.

주의

JIT는 계획 비용이 jit_above_cost(기본 100000)를 넘을 때만 동작한다. 비용 추정이 부풀면 짧은 쿼리에서 컴파일이 실행보다 오래 걸릴 수 있다. 전역으로 끄기보다 먼저 해당 롤/데이터베이스에 ALTER ROLE ... SET jit = off를 적용하거나 jit_above_cost를 높이는 것을 고려한다. EXPLAIN (ANALYZE, COSTS OFF)는 JIT 섹션을 출력하지 않는다. PostgreSQL이 LLVM 지원 없이 빌드되었으면 JIT는 사용되지 않는다. SELECT pg_jit_available();로 확인한다.

DBAtlas에서 열기 →

관련 항목