
PHP 7 at Tumblr - llambda
https://engineering.tumblr.com/post/152998126990/php-7-at-tumblr
======
orware
Another piece to this (for those using MySQL as their backend) is that updates
to MySQL can improve things quite significantly as well.

In my work environment I"m the main MySQL user so I had setup a dedicated
MySQL 5.5 server a few years ago that I hadn't upgraded to any newer versions
since then (hey it wasn't broke right?). But recently I had been looking into
upgrading just because it felt like it was time, but earlier this week I was
checking out some performance degradation on one of our sites and noticed in
my local copy it was actually running quite a bit faster.

Investigating further, it seems that in the newer versions of MySQL (in my
case, my local XAMPP was running MariaDB 10.1.x) the performance has improved
quite a bit, particularly for the types of queries I was running on this site
(which used a number of subqueries and GROUP BY clauses).

Without any sort of application level caching making this single switch from
MySQL 5.5 to MariaDB 10.1.19 improved load times from about 3.0 seconds to 1.0
seconds and I'm going to add some application level caching as well to improve
things further.

This was all without switching PHP versions on this particular site (which is
still using PHP 5.4.45)...just thought I'd share since sometimes the slowness
isn't always improved as much just by upgrading PHP (which is something I'd
like to do too for this site, but at the moment the framework I'm using on the
site isn't ready for PHP 7 so it'd be quite a bit of work to switch it out).

~~~
0xmohit
Complete list of new features in MySQL 5.7 [0] (in bullet form) would show
scores of performance improvements. The performance improvements from 5.5 to
5.6 were significant and 5.7 is much much better.

[0]
[http://www.thecompletelistoffeatures.com/](http://www.thecompletelistoffeatures.com/)

~~~
dijit
On the flip side there were severe performance degradations for certain types
of queries. Notably Zabbix[0] was affected.

[0]:
[https://m.reddit.com/r/zabbix/comments/3txgov/poor_performan...](https://m.reddit.com/r/zabbix/comments/3txgov/poor_performances_with_mysql_57/)

~~~
morgo
It's important to distinguish between cases where it is slower, and cases
where query plans change.

MySQL 5.7 changed the cost-model significantly, so while it will be better on
most queries, there are cases where two-wrongs-made-a-right; and edge case
queries may be slower. To mitigate this (as it was somewhat expected), MySQL
5.7 also introduced new query hints and server-side query rewrite.

(In the case of the link you provided, OP responded later saying 5.7.10
improved performance again.)

------
angry-hacker
Despite all the negativity about PHP, I sincerely thank all the team behind
it. Thanks to PHP and its easy way of start building stuff, I started learning
programming.

While I have moved on, not because it's hip to do so, I hope the community
keeps rocking. Thank you again and congratulations.

------
0xmohit
A recent post about PHP 7 deployment at DailyMotion [0].

Another one, Taking PHP Seriously [1].

[0]
[https://news.ycombinator.com/item?id=12704511](https://news.ycombinator.com/item?id=12704511)

[1]
[https://news.ycombinator.com/item?id=12703751](https://news.ycombinator.com/item?id=12703751)

------
tiffanyh
Is there anymore major performance improvements left to make to PHP or is
everything else just dimishing returns?

No disrespect to the huge amount of work the PHP team has already completed,
they should be praised.

Just curious to know if we can expect anymore major performance improvements
like we saw from v5 to v7.

EDIT: After further searching, appears PHP 8 will have some sort of JIT (with
the hope that it'll continue to bring significant perf improvements. More info
at
[http://news.php.net/php.internals/95531](http://news.php.net/php.internals/95531)

~~~
progforlyfe
Yes, the next major performance improvements will come from a JIT style
machine, similar to what HHVM does.

~~~
otto_ortega
I'm also confused. Php 7 has Opcache, which according to the documentation:

"OPcache improves PHP performance by storing precompiled script bytecode in
shared memory, thereby removing the need for PHP to load and parse scripts on
each request."

How would JIT features come into play with it?

~~~
TazeTSchnitzel
Precompiled here means bytecode, not machine code. OPcache is similar to, say,
Python's .pyc files.

------
overcast
That's quite a performance improvement. I'm curious if this was directly
related to just switching to PHP7, or something under the Tumblr hood, that
they improved upon as well. While reviewing their own code.

~~~
tyingq
Significant improvement in response times, TPS, and memory usage are pretty
universally observed when switching from PHP5.x to PHP7...

[https://www.symfony.fi/entry/symfony-benchmarks-
php-56-hhvm-...](https://www.symfony.fi/entry/symfony-benchmarks-php-56-hhvm-
and-php-7)

[http://www.zend.com/en/resources/php7_infographic](http://www.zend.com/en/resources/php7_infographic)

[https://techblog.badoo.com/blog/2016/03/14/how-badoo-
saved-o...](https://techblog.badoo.com/blog/2016/03/14/how-badoo-saved-one-
million-dollars-switching-to-php7/#launch-into-battle-and-the-results)

Edit: A slide deck with some detail on why it's so much better:
[http://www.slideshare.net/nikita_ppv/php-7-what-changed-
inte...](http://www.slideshare.net/nikita_ppv/php-7-what-changed-internally-
php-barcelona-2015)

~~~
TazeTSchnitzel
A fun thing about that slide deck: the memory use reduction is actually even
better, because allocation overhead isn't counted there.

------
uses
We use the Rackspace Cloud Sites PAAS. They recently released a PHP 7 beta.

For our sites running Bolt - a PHP CMS which makes heavy use of autoloaded
classes - we saw a performance improvement between 45 and 55 percent. For
Wordpress, it was around 30-40%.

~~~
matart
Were there major improvements to autoloading in PHP7?

~~~
bkanber
It's possible that when switching to PHP7 opcache was enabled by default,
whereas it may not have been beforehand. Most likely opcache is responsible
for the autoloading improvement.

That said, a faster parser and intepreter would do autoloading faster as well,
so it may not be opcache at all and just by virtue that the autoloaded classes
are interpreted faster.

------
Judson
In addition to latency and cpu usage improvements, we also saw a substantial
drop in memory usage for code that allocated a large number of objects. After
the initial migration, PHP7 has been very solid in production.

------
sigi45
I like the performance of php 7 very much. It has/will have an impact on
global warming.

The only frustrating thing about it is, that there was so much potential
unused for so long. Manh k/mwatts of power for nothing.

------
return0
Wow good for the environment :)

------
piotrjurkiewicz
I wonder if Wikipedia regrets its switch to HHVM, having in mind that PHP7 is
quite the same fast as HHVM is real apps and switching to it would require
much less work than to HHVM.

------
stefs
> As you can see, the latency dropped to less than half, and the load average
> at peak is now lower than it’s previous lowest point!

the graph they're referencing shows the peak at higher than the previously
lowest load. i guess "peak average" is the key to this.

------
rawoke083600
We at www.pricecheck.co.za switched early this year. We were supersized how
easy the transition was. We definitely saw a decrease in cpu usage about 20%.
Also most of our php-extension(nothing exotic) was also supported already...

------
elcct
Sorry for being a bit ignorant, but is there a point to use PHP 7 if you have
HHVM?

------
libraryatnight
Unrelated question: I couldn't find any HN discussions on, what's Tumblr's
future since the Verizon purchase? Yahoo let it be, it seems, has Verizon
mentioned it?

------
rampage101
PHP 7 is the next upgrade from PHP 5? I am very new to PHP and learning from a
book which is PHP 5.

~~~
oneweekwonder
Try `print false;` and see if you get the result you expect[0]. Because it
differs compared to node, perl, python(Yes Yes first char uppercase) and other
languages I can not think of.

Also good luck with the param ordering of `array_map` compared to
`array_filter` and `array_reduce`. Actually get use to the word array. Because
in 2009 the PHP developers did not think array is a important data type that
needs a short hand array() vs [], and all their function names `array_` shows
this ugliness.

I would advice rather spend your time learning python or javascript. But I
acknowledge PHP became a de facto standard with MediaWiki, WordPress,
Facebook, dragging the broken language into the 21st century.

[0]: [http://pastebin.com/raw/P6BTmceL](http://pastebin.com/raw/P6BTmceL)

~~~
oneweekwonder
For the down voters please see [Petty Issues I have with PHP!](petty); and
please reply.

I would really like to talk about this constructively.

[petty]:
[https://gist.github.com/Morabaraba/3e93d7d21e16b6eb8266ee1cc...](https://gist.github.com/Morabaraba/3e93d7d21e16b6eb8266ee1ccbdf77f8)

ps. can you not edit your comment anymore... could you ever edit your comment?

~~~
grzm
Once the comment gets to a certain age (an hour?), it's no longer editable.

------
otto_ortega
Php 7 for the win!

