理解magento的Two-Level Caching
magento默认使用zend framework的二层缓存存储方式。就是说它使用两层结构对cache进行配合管理,一个快的,但大小有限制的结构是一层比如APC或者Memcached ,一个比较慢的结构作为第二层比如file system.每一种存储结构各有利弊,要不同情况不同分析使用,APC 和 Memcached 是使用 key/value来存储cache,他们都不支持tag。File system 和Redis 支持tag.magento二级缓存结构工作流程图示 (Thanks to Fabrizio Branca):
magento自带的各种后端缓存介绍:
File system (var/cache)
默认情况下,Magento 将它的缓存条目存储在file系统中,在var/cache/下可查看。这种情况很适合小型的,数据量不大的站点。但是对于大型的站点,随着浏览量的不断增多,对file的读写操作也将越来越多,站点也会越来越慢。magento是由tags来对cache进行组织管理的,这意味着可以对某一个cache组(相同的tag为一个group)进行操作。
优点:这是默认的,不需要装额外的软件
缺点:清除cache依赖于tag,通常修改某个product或处理某个order完之后,对应的前台页面都需要更新缓存。每次更新缓存时,都需要根据tag进行所有条目即file进行查找,试想如果站点有多于1000个product,整个cache的大小将会大于50MB,大约有3500个file,你能想象到每次更新cache都要对3500个file进行查找有多慢吗。
小提示
1:使用 SSD 替代普通硬盘
2:把var/cache接入 tmpfs
----------------------------------------------------------------------------------------------------------------------------------
APC – Alternative PHP Cache (Key/Value)
APC是一个免费,开源且强健的框架用来缓存和优化 PHP 的中间代码。
优点:相对于file cache system是很快了
缺点:不支持tag,所以依然需要file system作为slow level cache。服务器需要安装PHP APC 模块
小提示:确保有足够的内存给APC ,可在 php.ini 中修改参数apc.shm_size
Configuration (app/etc/local.xml)
<global> ... <cache> <backend>apc</backend> <prefix>mgt_</prefix> </cache> ... </global>Settings for php.ini
apc.enabled = 1
apc.optimization = 0
apc.shm_segments = 1
apc.shm_size = 768M
apc.ttl = 48000
apc.user_ttl = 48000
apc.num_files_hint = 8096
apc.user_entries_hint = 8096
apc.mmap_file_mask = /tmp/apc.XXXXXX
apc.enable_cli = 1
apc.cache_by_default = 1
apc.max_file_size = 10M
apc.include_once_override = 0
---------------------------------------------------------------------------------------------------------------------------
Memcached (Key/Value)
Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。简单的说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。
优点:更快的存取速度
缺点:不支持tag,所以依然需要file system作为slow level cache
需求:1:Memcached server 2: PHP extension for memcached
Configuration (app/etc/local.xml)
<global> ... <cache> <backend>memcached</backend><!-- apc / memcached / empty=file --> <memcached><!-- memcached cache backend related config --> <servers><!-- any number of server nodes can be included --> <server> <host><![CDATA[127.0.0.1]]></host> <port><![CDATA[11211]]></port> <persistent><![CDATA[1]]></persistent> </server> </servers> <compression><![CDATA[0]]></compression> <cache_dir><![CDATA[]]></cache_dir> <hashed_directory_level><![CDATA[]]></hashed_directory_level> <hashed_directory_umask><![CDATA[]]></hashed_directory_umask> <file_name_prefix><![CDATA[]]></file_name_prefix> </memcached> </cache> ... </global>
---------------------------------------------------------------------------------------------------------------------
Redis – Advanced key-value store with full cache tag support
magento允许我们使用redis server作为中央存储仓库,它支持tag的使用,所以不再需要file system作为slow level cache。在多服务器多站点环境中,强烈推荐使用redis
,用一个中央缓存仓库,对所有server cache进行管理。
优点:快;支持tag;已在一个日均ip为500000的站点做过测试,性能极好且稳定。
需求:1:服务器上需要装Redis 2:PHP 扩展 phpredis 需要安装 3:Magento扩展“Cm_Cache_Backend_Redis”需要安装
Installation
1. Install redis (2.4+ required)
2. Install phpredis
3. Install the magento extension “Cm_Cache_Backend_Redis”
4. Edit your app/etc/local.xml
<global> ... <cache> <backend>Cm_Cache_Backend_Redis</backend> <backend_options> <server>127.0.0.1</server> <!-- or absolute path to unix socket --> <port>6379</port> <persistent></persistent> <database>0</database> <password></password> <force_standalone>0</force_standalone> <connect_retries>1</connect_retries> <automatic_cleaning_factor>0</automatic_cleaning_factor> <compress_data>1</compress_data> <compress_tags>1</compress_tags> <compress_threshold>20480</compress_threshold> <compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy --> </backend_options> </cache> ... </global>
Useful tool for redis
phpRedisAdmin 是一个简单操作界面对 Redis databases进行操作
Demo: http://dubbelboer.com/phpRedisAdmin/?overview
总结
小型站点使用APC + file system(作为slow level cache)即可,此外推荐使用SSD和把var/cache/放入tmpfs。
对于大型站点推荐使用redis, 即便cache file达到 500 MB,它依然很快,在多服务器环境中,Redis 也是很完美的选择。
转载
理解magento的Two-Level Caching
magento默认使用zend framework的二层缓存存储方式。就是说它使用两层结构对cache进行配合管理,一个快的,但大小有限制的结构是一层比如APC或者Memcached ,一个比较慢的结构作为第二层比如file system.每一种存储结构各有利弊,要不同情况不同分析使用,APC 和 Memcached 是使用 key/value来存储cache,他们都不支持tag。File system 和Redis 支持tag.magento二级缓存结构工作流程图示 (Thanks to Fabrizio Branca):
magento自带的各种后端缓存介绍:
File system (var/cache)
默认情况下,Magento 将它的缓存条目存储在file系统中,在var/cache/下可查看。这种情况很适合小型的,数据量不大的站点。但是对于大型的站点,随着浏览量的不断增多,对file的读写操作也将越来越多,站点也会越来越慢。magento是由tags来对cache进行组织管理的,这意味着可以对某一个cache组(相同的tag为一个group)进行操作。
优点:这是默认的,不需要装额外的软件
缺点:清除cache依赖于tag,通常修改某个product或处理某个order完之后,对应的前台页面都需要更新缓存。每次更新缓存时,都需要根据tag进行所有条目即file进行查找,试想如果站点有多于1000个product,整个cache的大小将会大于50MB,大约有3500个file,你能想象到每次更新cache都要对3500个file进行查找有多慢吗。
小提示
1:使用 SSD 替代普通硬盘
2:把var/cache接入 tmpfs
----------------------------------------------------------------------------------------------------------------------------------
APC – Alternative PHP Cache (Key/Value)
APC是一个免费,开源且强健的框架用来缓存和优化 PHP 的中间代码。
优点:相对于file cache system是很快了
缺点:不支持tag,所以依然需要file system作为slow level cache。服务器需要安装PHP APC 模块
小提示:确保有足够的内存给APC ,可在 php.ini 中修改参数apc.shm_size
Configuration (app/etc/local.xml)
<global> ... <cache> <backend>apc</backend> <prefix>mgt_</prefix> </cache> ... </global>Settings for php.ini
apc.enabled = 1
apc.optimization = 0
apc.shm_segments = 1
apc.shm_size = 768M
apc.ttl = 48000
apc.user_ttl = 48000
apc.num_files_hint = 8096
apc.user_entries_hint = 8096
apc.mmap_file_mask = /tmp/apc.XXXXXX
apc.enable_cli = 1
apc.cache_by_default = 1
apc.max_file_size = 10M
apc.include_once_override = 0
---------------------------------------------------------------------------------------------------------------------------
Memcached (Key/Value)
Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。简单的说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。
优点:更快的存取速度
缺点:不支持tag,所以依然需要file system作为slow level cache
需求:1:Memcached server 2: PHP extension for memcached
Configuration (app/etc/local.xml)
<global> ... <cache> <backend>memcached</backend><!-- apc / memcached / empty=file --> <memcached><!-- memcached cache backend related config --> <servers><!-- any number of server nodes can be included --> <server> <host><![CDATA[127.0.0.1]]></host> <port><![CDATA[11211]]></port> <persistent><![CDATA[1]]></persistent> </server> </servers> <compression><![CDATA[0]]></compression> <cache_dir><![CDATA[]]></cache_dir> <hashed_directory_level><![CDATA[]]></hashed_directory_level> <hashed_directory_umask><![CDATA[]]></hashed_directory_umask> <file_name_prefix><![CDATA[]]></file_name_prefix> </memcached> </cache> ... </global>
---------------------------------------------------------------------------------------------------------------------
Redis – Advanced key-value store with full cache tag support
magento允许我们使用redis server作为中央存储仓库,它支持tag的使用,所以不再需要file system作为slow level cache。在多服务器多站点环境中,强烈推荐使用redis
,用一个中央缓存仓库,对所有server cache进行管理。
优点:快;支持tag;已在一个日均ip为500000的站点做过测试,性能极好且稳定。
需求:1:服务器上需要装Redis 2:PHP 扩展 phpredis 需要安装 3:Magento扩展“Cm_Cache_Backend_Redis”需要安装
Installation
1. Install redis (2.4+ required)
2. Install phpredis
3. Install the magento extension “Cm_Cache_Backend_Redis”
4. Edit your app/etc/local.xml
<global> ... <cache> <backend>Cm_Cache_Backend_Redis</backend> <backend_options> <server>127.0.0.1</server> <!-- or absolute path to unix socket --> <port>6379</port> <persistent></persistent> <database>0</database> <password></password> <force_standalone>0</force_standalone> <connect_retries>1</connect_retries> <automatic_cleaning_factor>0</automatic_cleaning_factor> <compress_data>1</compress_data> <compress_tags>1</compress_tags> <compress_threshold>20480</compress_threshold> <compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy --> </backend_options> </cache> ... </global>
Useful tool for redis
phpRedisAdmin 是一个简单操作界面对 Redis databases进行操作
Demo: http://dubbelboer.com/phpRedisAdmin/?overview
总结
小型站点使用APC + file system(作为slow level cache)即可,此外推荐使用SSD和把var/cache/放入tmpfs。
对于大型站点推荐使用redis, 即便cache file达到 500 MB,它依然很快,在多服务器环境中,Redis 也是很完美的选择。
http://www.tuicool.com/articles/Ef6Jru
理解magento的Two-Level Caching
magento默认使用zend framework的二层缓存存储方式。就是说它使用两层结构对cache进行配合管理,一个快的,但大小有限制的结构是一层比如APC或者Memcached ,一个比较慢的结构作为第二层比如file system.每一种存储结构各有利弊,要不同情况不同分析使用,APC 和 Memcached 是使用 key/value来存储cache,他们都不支持tag。File system 和Redis 支持tag.magento二级缓存结构工作流程图示 (Thanks to Fabrizio Branca):
magento自带的各种后端缓存介绍:
File system (var/cache)
默认情况下,Magento 将它的缓存条目存储在file系统中,在var/cache/下可查看。这种情况很适合小型的,数据量不大的站点。但是对于大型的站点,随着浏览量的不断增多,对file的读写操作也将越来越多,站点也会越来越慢。magento是由tags来对cache进行组织管理的,这意味着可以对某一个cache组(相同的tag为一个group)进行操作。
优点:这是默认的,不需要装额外的软件
缺点:清除cache依赖于tag,通常修改某个product或处理某个order完之后,对应的前台页面都需要更新缓存。每次更新缓存时,都需要根据tag进行所有条目即file进行查找,试想如果站点有多于1000个product,整个cache的大小将会大于50MB,大约有3500个file,你能想象到每次更新cache都要对3500个file进行查找有多慢吗。
小提示
1:使用 SSD 替代普通硬盘
2:把var/cache接入 tmpfs
----------------------------------------------------------------------------------------------------------------------------------
APC – Alternative PHP Cache (Key/Value)
APC是一个免费,开源且强健的框架用来缓存和优化 PHP 的中间代码。
优点:相对于file cache system是很快了
缺点:不支持tag,所以依然需要file system作为slow level cache。服务器需要安装PHP APC 模块
小提示:确保有足够的内存给APC ,可在 php.ini 中修改参数apc.shm_size
Configuration (app/etc/local.xml)
<global> ... <cache> <backend>apc</backend> <prefix>mgt_</prefix> </cache> ... </global>Settings for php.ini
apc.enabled = 1
apc.optimization = 0
apc.shm_segments = 1
apc.shm_size = 768M
apc.ttl = 48000
apc.user_ttl = 48000
apc.num_files_hint = 8096
apc.user_entries_hint = 8096
apc.mmap_file_mask = /tmp/apc.XXXXXX
apc.enable_cli = 1
apc.cache_by_default = 1
apc.max_file_size = 10M
apc.include_once_override = 0
---------------------------------------------------------------------------------------------------------------------------
Memcached (Key/Value)
Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。简单的说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。
优点:更快的存取速度
缺点:不支持tag,所以依然需要file system作为slow level cache
需求:1:Memcached server 2: PHP extension for memcached
Configuration (app/etc/local.xml)
<global> ... <cache> <backend>memcached</backend><!-- apc / memcached / empty=file --> <memcached><!-- memcached cache backend related config --> <servers><!-- any number of server nodes can be included --> <server> <host><![CDATA[127.0.0.1]]></host> <port><![CDATA[11211]]></port> <persistent><![CDATA[1]]></persistent> </server> </servers> <compression><![CDATA[0]]></compression> <cache_dir><![CDATA[]]></cache_dir> <hashed_directory_level><![CDATA[]]></hashed_directory_level> <hashed_directory_umask><![CDATA[]]></hashed_directory_umask> <file_name_prefix><![CDATA[]]></file_name_prefix> </memcached> </cache> ... </global>
---------------------------------------------------------------------------------------------------------------------
Redis – Advanced key-value store with full cache tag support
magento允许我们使用redis server作为中央存储仓库,它支持tag的使用,所以不再需要file system作为slow level cache。在多服务器多站点环境中,强烈推荐使用redis
,用一个中央缓存仓库,对所有server cache进行管理。
优点:快;支持tag;已在一个日均ip为500000的站点做过测试,性能极好且稳定。
需求:1:服务器上需要装Redis 2:PHP 扩展 phpredis 需要安装 3:Magento扩展“Cm_Cache_Backend_Redis”需要安装
Installation
1. Install redis (2.4+ required)
2. Install phpredis
3. Install the magento extension “Cm_Cache_Backend_Redis”
4. Edit your app/etc/local.xml
<global> ... <cache> <backend>Cm_Cache_Backend_Redis</backend> <backend_options> <server>127.0.0.1</server> <!-- or absolute path to unix socket --> <port>6379</port> <persistent></persistent> <database>0</database> <password></password> <force_standalone>0</force_standalone> <connect_retries>1</connect_retries> <automatic_cleaning_factor>0</automatic_cleaning_factor> <compress_data>1</compress_data> <compress_tags>1</compress_tags> <compress_threshold>20480</compress_threshold> <compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy --> </backend_options> </cache> ... </global>
Useful tool for redis
phpRedisAdmin 是一个简单操作界面对 Redis databases进行操作
Demo: http://dubbelboer.com/phpRedisAdmin/?overview
总结
小型站点使用APC + file system(作为slow level cache)即可,此外推荐使用SSD和把var/cache/放入tmpfs。
对于大型站点推荐使用redis, 即便cache file达到 500 MB,它依然很快,在多服务器环境中,Redis 也是很完美的选择。