Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
HTTP/2 & PHP 7.0:
New Infrastructure Technologies’
Impact on Magento Performance
Co-Founder & CTO, Shoppimon
@shevron
Shahar Evron
Intro:
Why Does Performance Matter?“Premature optimization is the root of all evil.”
-- Knuth (?)
Slow is the New Down
• Research shows that store performance directly impacts
a store’s bottom line:
– Example: A store making $15,000,000 / year, is losing approx.
$600,000 to slowdowns
• Speed impacts scalability and operational costs:
– Less time per request more requests per process / minute
– Less memory per process more processes per hardware
PHP 7.x“7 is perceived as a lucky number in both the Western world
and Chinese culture. A little bit of luck never hurt anybody.”
-- PHP RFC: Name of Next Release of PHP
What’s PHP 7?
• PHP 7 is the current major version of PHP
– PHP 5.6 support ends on Dec. 2017
• PHP 7 introduces substantial memory footprint
reduction and speed improvements
• There are also some cool new language features
PHP 7.x Magento Support
• Support for Magento 1.x: Unofficial but “known to work”
– Many 3rd party extensions may not work
– There are extensions that can help with compatibility
• Support for Magento 2.x: Official for 7.0
– 7.1 not officially supported just yet, but it probably works™
PHP Version Adoption
PHP Version Adoption
Benchmark Time!
Some Backwards Compatibility Pitfalls
• Extensions and custom code may not support PHP 7.x
• New reserved keywords
• Uniform Variable Syntax introduces changes to order of precedence
of complex variable variable dereferencing, e.g.
Expression Old Meaning New Meaning
$$foo['bar']['baz'] ${$foo['bar']['baz']} ($$foo)['bar']['baz']
$foo->$bar['baz'] $foo->{$bar['baz']} ($foo->$bar)['baz']
Switching a Magento site to PHP 7.1
• TEST, TEST, TEST. Then TEST again
• If possible: install a new server, roll over to production
– If you must replace PHP on your old node, expect downtime
• Monitor your store before and after switching to ensure a
smooth transition </plug>
HTTP/2Or: why I can no longer use telnet to browse the Web?
What is HTTP/2?
• May 2015: Published as RFC
• Does not change HTTP’s semantics
• Binary protocol, most implementations are HTTPS only
• Currently supported by all major browsers, many servers and CDNs
• Main new capabilities include:
– Multiplexing
– Header Compression
– Server Push
HTTP/2 Adoption
What is Multiplexing?
Browser
GET / img1.png
TCP Connection 1
/ img1.png OK
GET / img2.png
TCP Connection 2
/ img2.png OK
GET / img3.png
GET / img4.png
HTTP Server
HTTP/1.x: Messages are sequential and unidirectional
What is Multiplexing?
• In HTTP/1.1: Single TCP connection *can* do multiple requests, but
must do them in sequence
• HTTP/2 is multiplexing - multiple “dialogues” can happen on a single
connection concurrently
• This can have a massive performance boost, especially for static, IO
bound content
What is Multiplexing?
HTTP/2: Messages are interleaved in a bidirectional protocol
HTTP ServerBrowser
TCP Connection 1
More Benchmarks!
• 70% of tested stores showed improvement in full load time (avg.
improvement 12%)
• 45% also became interactive faster (avg. improvement 14.5%)
• Some sites (15%) actually showed a marginal decrease in
performance
All tests done on real Magento 2.x sites running PHP 7.x and
HTTP/2
Cranking it Up To 11: Server Push
// Push style.css along with this response
header("Link: </static/style.css>;rel=preload", false);
Browser
TCP Connection 1
HTTP Server
Converting a Magento Site to HTTP/2
• HTTP/2 is generally compatible with any Web platform or application
• You must have HTTPS support with a recent TLS
– yeah, you should have that anyway
• Supported by Apache 2.4 and Nginx 1.10
– You may need to use a custom package if not provided by your distro
• ALPN requires OpenSSL 1.0.2 or newer
• You can disable static file inlining from the Magento Admin
Setting Up HTTP/2
Apache 2.4
LoadModule http2_module
modules/mod_http2.so
<VirtualHost ...>
ServerName test.example.org
Protocols h2 http/1.1
</VirtualHost>
Nginx 1.10
server {
server_name
test.example.com;
listen 443 ssl http2;
}
TakeawaysThe tl;dr version
Takeaways
• Performance matters!
• HTTP/2
– Offers a significant speed boost to static content loading
– Will allow you to get rid of some outdated optimization techniques
– Switch to it, especially if you’re not using a CDN
• PHP 7.x
– Is much much (much) faster than PHP 5.6
– Is the future of PHP. Security fixes for PHP 5.6 end by the end of 2017
– Migration is not always trivial, make sure you plan ahead
– Expect some breakage especially in 3rd party extensions. Test heavily
– All new sites should be built with 7.x. Seriously