Chris Caillouet
Dev|Ops Sensei
Rackspace University
Sept 10, 2014
So we are supporting Magento now, you say?!?!
SHORT ANSWER
ACTUAL ANSWER
We can offer expertise on the following...
Be on the lookout for the next appearance of Magneto during the day!
• Community is Free and Open Source
• Extendable - Third party plugins are big a factor for Magento popularity
• Control multiple websites and stores from one Administration Panel
• “100% search engine friendly”
• Support for localization, multiple currencies and tax rates
• Paypal, Sagepay, Google Checkout, etc.
• Lots of reporting tools
• Support for native applications on mobile devices
• API
• Really fast! (actually, it isn't so bad if we do things right)
Basic Magento Installation Steps - Part I
(unlikely our role will be to handle this)
Change to the directory you wish to serve Magento from: cd /var/www/html (for example)
DOWNLOAD: wget http://www.magentocommerce.com/downloads/assets/1.9.0.1/magento-1.9.0.1.tar.gz
EXTRACT: tar -zxvf magento-1.9.0.0.tar.gz
MOVE FILES INTO SITE LOCATION: mv magento/* magento/.htaccess .
SET PERMISSIONS: chmod -R o+w media var
MORE PERMISSIONS: chmod o+w app/etc
...
PROFIT!!!
Basic Magento Installation Steps - Part II
(unlikely our role will be to handle this)
Create a MySQL database and user with full privileges to this DB - save this information
Launch the Web based installer by visiting the IP in a browser
...
PROFIT!!!
Let's have a look around the files within the Magento file structure
Magento File Structure
ALSO:
Magento Database Tour
Let's take a look at the database and tables that Magento utilizes
Magento Database
•Mostly InnoDB, so Percona is a good fit, while MySQL is the fully supported option
•Config in local.xml – straightforward. Note: optional table prefix
•Can configure master/slave natively (but not necessary)
•DB not normally the bottleneck, depends on architecture of the deployment
•max_allowed_packet = 16M 32M [or higher] (this is almost certainly a needed tweak)
Key Tables
The Magento Webserver
• Does not matter. PHP processing is main bottleneck, not static delivery
• Use PHP-FPM where possible
– Better under load
– Use local socket, not TCP:9000
• Matters even less with Varnish and/or CDN
• We prefer Apache, purely for config experience on our floor
– Most agencies prefer Nginx with PHP-FPM, and now we fully support it
--> see the Magento site for example config, or peruse your server
– Magento officially supports NginX for later versions only
Apache or NginX?
Caching Magento
Backend Caching Options
File Based Cache Backend
- Default setting
- Better than nothing, but slow under load.
- Can mount tmpfs, but still inefficient.
- Handles Zend two-level
- On filesystem:
~/var/cache
~/var/full_page_cache (Enterprise)
NOTE: Could be in /tmp/magento/var/ if ~/var wasn’t writable
APC Based Cache Backend
- APC can also be used for key/value storage
set apc.shm_size = 1024M
- Works on all versions
- Better than File, but not shared
- Still needs a slow_backend
default : <slow_backend>File</slow_backend>
There is nothing wrong with using APC...
...but use memcache|redis instead, for future scalability.
Database Cache Backend
Memcache Cache Backend
<session_save><![CDATA[memcache]]></session_save>
<session_save_path><![CDATA[tcp://127.0.0.1:11211?persistent=0&weight=2&timeout=10&retry_interval=10]]></session_save_path>
<cache>
<backend>memcached</backend>
<memcached>
<servers>
<server>
<host><![CDATA[127.0.0.1]]></host>
<port><![CDATA[11212]]></port>
<persistent><![CDATA[1]]></persistent>
<weight><![CDATA[1]]></weight>
<timeout><![CDATA[1]]></timeout>
<retry_interval><![CDATA[15]]></retry_interval>
</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
Excerpt of configuration from app/etc/local.xml
LAB: Memcache Configuration
Redis Cache Backend
Redis is Memcache with knobs to enhance #alltehthings
Features:
- Persistence
- Replication,
- Authentication
- Internal database structure
Allows Zend to use it as a slow_backend.
Allows for multiple Magneto shops in a single instance.
BE HONEST!
WHO SAW IT?!?!
So...
...on with the show.
OKAY... Just one moment...
Redis Cache Backend
Redis is Memcache with knobs to enhance #alltehthings
Features:
- Persistence
- Replication,
- Authentication
- Internal database structure
Allows Zend to use it as a slow_backend.
Allows for multiple Magneto shops in a single instance.
Redis Cache Backend - When to use it?
Redis Cache Backend - /etc/redis.conf
Don’t forget to install phpXXX-pecl-redis
Sessions (documented on one.rackspace.com wiki)
Redis Cache Backend - app/etc/local.xml
<session_save><![CDATA[db]]></session_save>
<redis_session>
<host>10.181.99.168</host> <!-- or absolute path to unix socket -->
<port>6379</port> <!-- if unix socket just change it to 0 -->
<password>if_you_set_one</password>
<timeout>3</timeout>
<persistent></persistent>
<db>0</db>
<compression_threshold>2048</compression_threshold>
<compression_lib>gzip</compression_lib>
<log_level>1</log_level>
<max_concurrency>6</max_concurrency>
<break_after_frontend>5</break_after_frontend>
<break_after_adminhtml>30</break_after_adminhtml>
<bot_lifetime>7200</bot_lifetime>
</redis_session>
Magento Cache Backend - Which to use?!?
Need I say anymore? Redis is a natural pairing with Magento and can be a direct replacement to memcache implementations, in many cases.
1.Find the wiki article on redis installation
2.Install and configure Redis on localhost as a replacement to Memcache
… check with “redis-cli info”
3.Don’t forget to enable the sessions usage in the code
4.Configure local.xml for <sessions> and <cache>
… using different DB numbers
5.Test, then disable the Memcache instances once Redis is verified to be working
LAB: Redis Implementation
Hint
Full page caching is a must for the most performant Magento implementations, but is only available with an Enterprise Magento license. There are third party tools that provide this feature, as well.
Magento Full Page Caching
Full Page Cache Improves Time To First Byte
Full Pace Cache - Third Party Options
~ Search the one.rackspace wiki for implementation
instructions for Varnish with PageCache for Magento.
~ Implement this caching layer, as per Wiki, using
Varnish 3.x repo and ~/mage installer.
~ Poke around in Magento Dashboard config
Architecting Magento
~ Single server is OK!
– Actually good value vs Cloud
~ Old advice was before we understood effective FPC options
~ Plenty of CPU/memory
– i.e NOT a Cloud server
~ Separate RAID for DB ideal
~ Good for Enterprise licensing, and no LB complexity (next slide)
~ Better: second server for DB/cache
Dedicated
Adding a Load Balancer
Sample Dedicated Multi Server Configuration
Sample Dedicated Clustered Server Configuration
Sample Cloud Deployment
Sample Cloud Deployment
redis + ObjectRocket
Sample Hybrid Deployment
Magento Platform Troubleshooting
First Things First - Magento Logging
Magento Error Page Troubleshooting
Varnish & Web Layer Troubleshooting
chris.caillouet@rackspace.com
Dev|Ops Sensei
Rackspace University
fin