성능 최적화를 위한 L2 캐시 구성
L2(2단계) 캐싱은 각 웹 노드에 로컬 캐시 계층을 추가하여 원격 캐시 스토리지(Redis 또는 Valkey)와 Commerce 애플리케이션 간의 네트워크 트래픽을 줄입니다. 표준 Commerce 인스턴스는 요청당 약 300KB를 전송하며, 트래픽은 일부 상황에서 1000개 이상의 요청으로 빠르게 증가할 수 있습니다.
L2 캐싱을 사용하면 각 웹 노드는 자주 액세스하는 데이터를 로컬에 저장하고 원격 캐시를 두 가지 용도로 사용합니다.
- 최신 캐시가 로컬에 저장되었는지 확인하기 위해 캐시 데이터 버전 확인
- 업데이트된 캐시 데이터를 원격 저장소에서 로컬 시스템으로 전송 중
Commerce은 해시된 데이터 버전을 원격 캐시에 저장하고, 일반 키에 접미사 :hash을(를) 추가합니다. 로컬 캐시가 오래된 경우 캐시 어댑터를 통해 원격 컴퓨터에서 데이터를 가져옵니다.
두 가지 L2 캐시 구현을 사용할 수 있습니다.
기존 L2 캐시 구성(RemoteSynchronizedCache)
다음 예제를 사용하여 app/etc/env.php 파일의 기존 캐시 섹션을 수정하거나 바꾸십시오.
'cache' => [
'frontend' => [
'default' => [
'backend' => '\\Magento\\Framework\\Cache\\Backend\\RemoteSynchronizedCache',
'backend_options' => [
'remote_backend' => '\\Magento\\Framework\\Cache\\Backend\\Redis',
'remote_backend_options' => [
'persistent' => 0,
'server' => 'localhost',
'database' => '0',
'port' => '6379',
'password' => '',
'compress_data' => '1',
],
'local_backend' => 'Cm_Cache_Backend_File',
'local_backend_options' => [
'cache_dir' => '/dev/shm/'
]
],
'frontend_options' => [
'write_control' => false,
],
]
],
'type' => [
'default' => ['frontend' => 'default'],
],
],
위치:
-
backend은(는) L2 캐시 구현입니다. -
backend_options은(는) L2 캐시 구성입니다.remote_backend은(는) 원격 캐시 구현인 Redis 또는 MySQL입니다.remote_backend_options은(는) 원격 캐시 구성입니다.local_backend은(는) 로컬 캐시 구현입니다.Cm_Cache_Backend_Filelocal_backend_options은(는) 로컬 캐시 구성입니다.cache_dir은(는) 로컬 캐시가 저장된 디렉터리에 대한 파일 캐시 관련 옵션입니다.
Adobe에서는 다음을 사용하여 원격 캐싱(\Magento\Framework\Cache\Backend\Redis)에 Redis를 사용하고 공유 메모리에 있는 데이터의 로컬 캐싱에 Cm_Cache_Backend_File을(를) 사용하는 것이 좋습니다. 'local_backend_options' => ['cache_dir' => '/dev/shm/']
Adobe은 Redis에 대한 압력을 크게 낮추기 때문에 cache preload 기능을 사용할 것을 권장합니다. 미리 로드 키에 접미사 ':hash’을(를) 추가하는 것을 잊지 마십시오.
부실 캐시 옵션
Commerce 2.4부터 use_stale_cache 옵션을 사용하면 새 캐시 데이터가 병렬 프로세스에서 생성되는 동안 이전에 캐시된 데이터를 제공함으로써 특정 경우에 대한 성능을 향상시킬 수 있습니다.
일반적으로, 잠금 대기를 갖는 상계는 성능 관점에서 받아들여질 수 있다. 그러나 블록 또는 캐시 항목의 수가 증가하면 잠금 대기에 더 많은 시간이 걸립니다. 일부 시나리오에서 대기 시간은 프로세스에 대해 최대 키 수 x 조회 시간 초과일 수 있습니다. 드문 경우이지만 판매자는 Block/Config 캐시에 수백 개의 키를 보유할 수 있으므로 잠금에 대한 작은 조회 시간 제한도 초 단위로 소요될 수 있습니다.
'use_stale_cache' => true을(를) 추가하십시오.Adobe에서는 다음을 포함하여 가장 많은 혜택을 받는 캐시 유형에 대해서만 use_stale_cache 옵션을 사용하도록 권장합니다.
block_htmlconfig_integration_apiconfig_integrationfull_pagelayoutreflectiontranslate
Adobe에서는 default 캐시 유형에 대해 use_stale_cache 옵션을 활성화하지 않는 것이 좋습니다.
다음 코드는 구성의 예를 보여 줍니다.
'cache' => [
'frontend' => [
'default' => [
'backend' => '\\Magento\\Framework\\Cache\\Backend\\RemoteSynchronizedCache',
'backend_options' => [
'remote_backend' => '\\Magento\\Framework\\Cache\\Backend\\Redis',
'remote_backend_options' => [
'persistent' => 0,
'server' => 'localhost',
'database' => '0',
'port' => '6379',
'password' => '',
'compress_data' => '1',
],
'local_backend' => 'Cm_Cache_Backend_File',
'local_backend_options' => [
'cache_dir' => '/dev/shm/'
]
],
'frontend_options' => [
'write_control' => false,
],
],
'stale_cache_enabled' => [
'backend' => '\\Magento\\Framework\\Cache\\Backend\\RemoteSynchronizedCache',
'backend_options' => [
'remote_backend' => '\\Magento\\Framework\\Cache\\Backend\\Redis',
'remote_backend_options' => [
'persistent' => 0,
'server' => 'localhost',
'database' => '0',
'port' => '6379',
'password' => '',
'compress_data' => '1',
],
'local_backend' => 'Cm_Cache_Backend_File',
'local_backend_options' => [
'cache_dir' => '/dev/shm/'
],
'use_stale_cache' => true,
],
'frontend_options' => [
'write_control' => false,
],
]
],
'type' => [
'default' => ['frontend' => 'default'],
'layout' => ['frontend' => 'stale_cache_enabled'],
'block_html' => ['frontend' => 'stale_cache_enabled'],
'reflection' => ['frontend' => 'stale_cache_enabled'],
'config_integration' => ['frontend' => 'stale_cache_enabled'],
'config_integration_api' => ['frontend' => 'stale_cache_enabled'],
'full_page' => ['frontend' => 'stale_cache_enabled'],
'translate' => ['frontend' => 'stale_cache_enabled']
],
],
최신 Sympony L2 캐시 구현
[2.4.9-베타]{class="badge negative" title="2.4.9 베타 버전에서만 사용할 수 있습니다."}
Commerce 2.4.9부터 Symfony 캐시 기반 L2 캐시 구현(symfony_l2 백엔드)을 사용할 수 있습니다. 이 구현은 최신 PSR-6 호환 캐싱 구현을 제공하며 기존 RemoteSynchronizedCache에 비해 상당한 성능 향상을 제공합니다.
Symfony L2 캐시의 이점
- 최신 아키텍처: Symfony 캐시 구성 요소를 기반으로 구축(PSR-6 준수)
- 향상된 성능: Igbinary serialization, gzip 압축 및 Lua 스크립트에 대한 기본 지원
- 영구 연결: 연결 풀링을 통해 Redis 또는 Valkey 연결 오버헤드를 줄입니다.
- 키 미리 로드: 중요한 데이터에 대한 캐시 키 미리 로드를 지원합니다.
- 오래된 캐시 지원:
use_stale_cache옵션과의 완전한 호환성 - 간소화된 구성: 더 이상 사용되지 않는 백엔드 형식 이름(
redis,valkey,file)
Sympony L2 캐시를 사용한 구성 예
L2 캐시에 대해 간소화된 symfony_l2 백 엔드 유형 사용:
'cache' => [
'frontend' => [
'default' => [
'backend' => 'symfony_l2',
'backend_options' => [
// L2 (Remote): Redis with Symfony Cache
'remote_backend' => 'redis',
'remote_backend_options' => [
'server' => 'localhost',
'database' => '0',
'port' => '6379',
'password' => '',
'serializer' => 'igbinary',
'compression_lib' => 'gzip',
'persistent_id' => 'magento_l2_default',
'timeout' => '2.5',
'read_timeout' => '2.0',
'use_lua' => '1',
'preload_keys' => [
'prefix_EAV_ENTITY_TYPES:hash',
'prefix_GLOBAL_PLUGIN_LIST:hash',
'prefix_DB_IS_UP_TO_DATE:hash',
'prefix_SYSTEM_DEFAULT:hash',
],
],
// L1 (Local): File cache
'local_backend' => 'file',
'local_backend_options' => [
'cache_dir' => '/dev/shm/magento_l1'
],
'cleanup_percentage' => 90,
],
]
],
'type' => [
'default' => ['frontend' => 'default'],
],
],
부실 캐시가 있는 교감 L2 캐시
오래된 캐시 지원을 위한 별도의 프론트엔드를 구성합니다.
'cache' => [
'frontend' => [
// Default frontend: NO stale cache
'default' => [
'backend' => 'symfony_l2',
'backend_options' => [
'remote_backend' => 'redis',
'remote_backend_options' => [
'server' => 'localhost',
'database' => '0',
'port' => '6379',
'serializer' => 'igbinary',
'compression_lib' => 'gzip',
'persistent_id' => 'magento_l2_default',
],
'local_backend' => 'file',
'local_backend_options' => [
'cache_dir' => '/dev/shm/magento_l1'
],
],
],
// Stale cache enabled frontend
'stale_cache_enabled' => [
'backend' => 'symfony_l2',
'backend_options' => [
'remote_backend' => 'redis',
'remote_backend_options' => [
'server' => 'localhost',
'database' => '0',
'port' => '6379',
'serializer' => 'igbinary',
'compression_lib' => 'gzip',
'persistent_id' => 'magento_l2_stale',
],
'local_backend' => 'file',
'local_backend_options' => [
'cache_dir' => '/dev/shm/magento_l1_stale'
],
'use_stale_cache' => true,
],
]
],
'type' => [
'default' => ['frontend' => 'default'],
'layout' => ['frontend' => 'stale_cache_enabled'],
'block_html' => ['frontend' => 'stale_cache_enabled'],
'reflection' => ['frontend' => 'stale_cache_enabled'],
'config_integration' => ['frontend' => 'stale_cache_enabled'],
'config_integration_api' => ['frontend' => 'stale_cache_enabled'],
'full_page' => ['frontend' => 'stale_cache_enabled'],
'translate' => ['frontend' => 'stale_cache_enabled'],
],
],
Symfony L2 캐시를 위한 백엔드 옵션
remote_backend'redis'redis, valkey 또는 fileremote_backend_options[]local_backend'file'file 또는 apculocal_backend_options[]cleanup_percentage90use_stale_cachefalseValkey 지원
symfony_l2 백엔드는 Valkey도 원격 백엔드로 지원합니다.
'backend_options' => [
'remote_backend' => 'valkey', // Use Valkey instead of Redis
'remote_backend_options' => [
'server' => 'localhost',
'database' => '0',
'port' => '6379',
'serializer' => 'igbinary',
'compression_lib' => 'gzip',
],
// ... rest of configuration
]
자세한 구성 옵션은 다음을 참조하십시오.