
We had the willing to play with Blackfire since the first release when Fabien
Potencier
presented this new Profiling System during the Symfony Live New York and later at
the Symfony Live in San Francisco.
Here is the result of 3 hours talking and playing with Nicolas Grekas the CTO of Blackfire and
me Sébastien Morel General Manager of Novactive San Francisco.
I was a real beginner with Blackfire, I used it in the past directly in a production environment to find a bug
hard to reproduce. It took us 10 minutes to find out the method that was calling a
webservice and that was reaching a timeout. We knew it was something like a timeout but it was
hard to find it in the messy source code(not ours of course), then it was our first use of Blackfire!
I’ve met Nicolas and Christophe Dujarric (the Product Manager) and we decided to plan an
afternoon to play with Blackfire and eZ Publish a CMS that we love at Novactive!
Here is what I have learnt and what we did during this nice session.
We wanted to profile a fresh eZ Platform installation to see how eZ would react to the
profiling, is everything good? is there a big heavy method somewhere?
Well as I knew, nothing big because the guys of the eZ Crew don’t joke with performances.
The interesting is not what we have found, but what was our methodology of playing, trying to find
out an optimization somewhere as a Blackfire beginner.
1/ Installations
I used my Ubuntu 14.04 Trusty VM with PHP5 FPM and Nginx.
1.1/ eZ Platform
Nothing particular to say, I followed the documentation:
https://github.com/ezsystems/ezplatform/blob/master/INSTALL.md
Try it! That is simple and you got a preview of the new Administration Interface:
Platform UI.
1.2/ Blackfire
As easy as eZ! Just follow the different steps described here: https://blackfire.io/getting-started
On my Ubuntu I had to create the blackfire.ini myself
; /etc/php5/mods-available/blackfire.ini
extension=blackfire.so
Run : php5enmod blackfire to create the good symlinks. Note that on Debian it seems that you don’t have to do that. Do not forget to restart your php5-fpm service.
2/ Profiling
2.1/ Standard installation in ‘dev’ environment
Context:
Nginx configuration:
fastcgi_param ENVIRONMENT dev;
We didn't profile cache empty, we did profile after at least the second request.
Result:

Explanation:
We did not dive on this profile as we were in the ‘dev’ environment.
But you will notice that the precision of Blackfire is better than
the Symfony
profiler webtoolbar. That
can be easily explain: Blackfire wraps your whole application rather than
the Symfony
Profiler
which cannot profile its own initialization process ( autoloads etc..)
2.2/ Standard installation in ‘prod’ environment
Context:
Nginx configuration:
fastcgi_param ENVIRONMENT prod;
We didn't profile cache empty, we did profile after at least the second request.
Result:

Explanation:
Here that is clear we are better everywhere!
Thanks to Symfony and to eZ Publish everything is ready to go in production.
But can we do better? What about the dumping the Autoload via composer -o?
2.3/ Installation in ‘prod’ environment + composer dump
Context:
Nginx configuration:
fastcgi_param ENVIRONMENT prod;
We didn't profile cache empty, we did profile after at least the second request.
And we dumped the autoload:
php composer.phar install -o --no-dev
php ezpublish/console cache:clear --env=prod
Result:

Explanation:
The difference is huge! You should notice the difference in the RAM usage
from ~1MB vs 8MB!
If you look back to the graph you can see a new red bloc.
And if you click on it, then we understand clearly that the composer dump is not a good solution here as it will use more RAM than the standard eZ Publish production mode.
Let's compare!
As this time you can use a great feature of Blackfire, the comparison.

Then you can see the difference, pretty cool!
Then Why? As the feature name describes itself, it dumps an autoload array to try to improve the performances during the loading. But with eZ and it might be the case for other big project, there is a lot of classes and then it doesn't help, it's the opposite because it has to load the big array of key/value.
3/ Conclusion
I hope it was a good introduction for you on Blackfire!
Nothing amazing but some information about how to profile your application
with Blackfire on an eZ Publish/Platform application.
Do not use the composer dump autoload in this case, it doesn't bring anything good.
I hope you see the power of this tool. This example is done on a empty project but imagine using it during your development!
DO NOT FIX PERFORMANCE ISSUES ANYMORE!
ANTICIPATE THEM!
And if you do not know that much this amazing
CMS/CMF/CXM: eZ Platform or the even
better eZ Studio,
give us a call!
4/ Tips and Tricks
For those 2 next points I switched back on a eZ Publish 5.4.x to have more contents and stuffs to present.
4.1/ Profile a POST request
Ok and what about the back office(Administration Inferface)? What about a POST request when a contributor publishs a new content?
How to profile a POST request with Blackfire? To do that you need to know what is cURL and you need to know this Firefox feature:
"Copy as cURL" is supposed to copy your request with your cookies, the content of
the POST etc..: Actually the complete HTTP POST request but in the cURL format.
If you want to analyse that, that’s really easy ( https://blackfire.io/doc/web-services
)
Nothing more than :
$ blackfire curl CTRL+V
Let the command line guides you, select your slot, wait and then profile on Blackfire.io! That’s it!
4.2/ Profile a Command
In eZ Publish with have also some command that we called “Cronjob” (it is now Command like in Symfony2), you can of course profile them as easily as a request. Let’s have a look on our old friend, the “frequent” cronjob:
ezpublish/console --env=prod ezpublish:legacy:script runcronjobs.php frequent
If you want to profile it, just add “blackfire run” before your command:
blackfire run php ezpublish/console --env=prod ezpublish:legacy:script runcronjobs.php frequent
Here is the result, interesting but outdated because eZ Platform gets rid of the Legacy Kernel of eZ Publish ;-)