效能

You are here:
< All Topics
[row][col_third]安裝 APC OpCache[/col_third][col_third]安裝 Zend OpCache[/col_third][col_third]Ramdisk Cache(File)[/col_third][/row]
Magento 目前有四種快取層級
File Cache:將檔案系統快取
Session Stores:將 Session 快取
OpCode Cache:將程式碼置入記憶體
Reverse Proxy Cache:使用反向代理進行加速
File Cache(只能選用一種)

Files (Core) Default
Memcache (Core)
APC (Core)
Redis (<1.9 module courtesy Colin Mollenhour)
MongoDB (module courtesy Colin Mollenhour)
Rubic (module courtesy Daniel Sloof)

Contrary to popular belief, using a memory based cache will not improve performance. But it will overcome some fatal flaws in Magento’s default file based caching.

As of writing this message, Redis is my recommendation.

Session Stores(只能選用一種)

Files (Core) Default
Memcache (Core)
Redis (<1.9 module courtesy Colin Mollenhour)
MongoDB (module courtesy Colin Mollenhour)

Contrary to popular belief, using a memory based session store will not improve performance.

As of writing this message, Redis is my recommendation.

OpCode Cache(能同時使用多種,但不建議)

APC
XCache
Eaccelerator (PHP <5.4)
Zend OPCache (PHP >5.4)

Reverse Proxy Cache

Varnish
Nginx
Apache
… and many more
You can use multiple reverse proxies, and whilst doing so is complex and prone to cache elongation, it can have merits (ie. To prevent stampeding during a cache flush).

Use one when necessary (ie. Not to speed up a slow site, but to reduce resource usage on a fast site).

To leverage a reverse proxy, it needs both enabling server side and needs a module for Magento.

The reason for the module is to help control caching logic (ie. To tell the cache what it should and shouldn’t cache) and also to manage cache contents (ie. To trigger purges of the cache).

I don’t recommend any unless you have a total understanding of what you are doing. Badly set up reverse proxies can break header information, can cause session loss, session sharing, stale content, apply additional limits to load time/buffers, consume additional resources etc.

Full Page Cache

EE FPC
… lots of others (via modules)

安裝 APC OPcache

不採用,雖然回應速度有改善,但修改 Magento local.xml 後會無法結帳

yum -y install php-devel pcre-devel gcc
pecl install apc
pecl uninstall apc
echo "extension=apc.so" >> /etc/php.ini
設定檔內容
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 512M
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.max_file_size = 10M
安裝 Zend OPCache
yum -y install php-devel pcre-devel gcc
yum -y install php-pecl-zendopcache
echo "zend_extension=/usr/lib64/php/modules/opcache.so" >> /etc/php.ini
or 手動新增 /etc/php.d/opcache.ini
設定檔內容(原始版)
zend_extension=/usr/lib64/php/modules/opcache.so

[opcache]
opcache.memory_consumption=64
opcache.interned_strings_buffer=4
opcache.max_accelerated_files=2000
opcache.revalidate_freq=2
opcache.fast_shutdown=0
opcache.enable_cli=0
設定檔內容(優化版)
zend_extension=/usr/lib64/php/modules/opcache.so

[opcache]
opcache.memory_consumption=256
opcache.interned_strings_buffer=12
opcache.max_accelerated_files=16000
opcache.validate_timestamps=0
opcache.save_comments=0
opcache.load_comments=0
opcache.fast_shutdown=1
opcache.enable_file_override=1
參考文獻

https://gist.github.com/tegansnyder/608185c9aeb11c10d8ae
http://fideloper.com/install-zend-opcache

File Cache / Ramdisk 存放 Cache Session 檔案
vi /etc/fstab
tmpfs /path/to/var/cache tmpfs rw,uid=503,gid=503,size=2048M,nr_inodes=10k,mode=0755 0 0

mount -t tmpfs -o size=128m tmpfs /usr/share/nginx/html/var/cache
mount -t tmpfs -o size=128m tmpfs /usr/share/nginx/html/var/session
Previous 已安裝模組及檔案結構
Next 效能優化 – PHP
Table of Contents