Blackfire performance profiling

Now nearly a year ago I was put on new task:

Optimize the performance of an application I did not know before.
This was not a really a new tasks for me, but I was a little worried about the available tools outside. They work, but it is mostly hard to find the performance issue.
During this time Blackfire was already in beta and in the end of November a colleague and me got access. So I tried the same also with Blackfire. In the end I could not find anything for this project. But I really liked Blackfire.

Some month later I started to profile the performance of the homepage of a different project. Here I could very quickly find some issues and within one day I was able to double the performance of the homepage. To bad that I don’t have those profiles anymore.

On my current project we are mostly serving an API for mobile devices. So I took one day to profile every API endpoint. First I could not find any specific, but after I added 20.000 test items (and also over 6000 items are related to my test user) the performance of one Endpoint dropped to around 3.x seconds.

Here is to bad profile for the endpoint:
bad
(note: screenshot say 18s but during this time the importer was still running)

Spot (what you can see in the screenshot) is the small ORM we use in our project. I quickly realized that there where 6426 entities created – which is definitely wrong :).

The issue was quickly found. All related items where fetched and counted (picardpalm) instead of using a real count query. So the fix for this issue was also very quick:
source

The result with the next profiling:
good

208ms instead of 3.x seconds.

The direct comparison:
compared

Without Blackfire and the testdata we would not have found this problem until someone hits the amount of items which could took some month.

If you did not worked with Blackfire: Try it out. Its really worth the time you invest. And it offers much more I just described here.

Developer Humor

Here are some of my alltime favorite comics for developers.

Symfony Links: Symfony2 Service Config Converter & Create your own framework & Symfony2cheatsheet

Symfony2 Service Config Converter

I just found on twitter  a nice Symfony service config converter: http://converter.rosstuck.com/

Also usable as a symfony command.
https://github.com/rosstuck/TuckConverterBundle

I think this is great to convert examples into your desired format.

And a simple link is pretty boring! So there are two more links…

Create your own framework… on top of the Symfony2 Components

http://fabien.potencier.org/article/50/create-your-own-framework-on-top-of-the-symfony2-components-part-1

A very nice tutorial from Fabien Potencier. And it is also a good start to get an overview over some symfony components.

Symfony2cheatsheet

An – for me – older link is the cheatsheet:
http://www.symfony2cheatsheet.com/

Just noticed that I did not used it so far… damn you… google search box!

From MySQL-Workbench to Sonata-Admin

Goal:

Design your Database inside MySQL-Workbench and get a nearly completely auto generated Sonata Admin from your MySQL-Workbench schemata.

Preface:

Working as a web-developer I was mostly confronted to create a unique and custom data model for the customer. I started to use MySQL-Workbench to design my data structure and followed on that I looked for a way to get my created structure directly into PHP models and an auto generated database.

Years ago for the bmw motorcyle community (Zend Framework) I started with a simple macro to just create to create the database structure. After that I used Doctrine to generate my models. So I used it only as a project start.

With an auction platform for the “Österreichische Bundesforste AG” (Agavi) I found a nice schema exporter for the MySQL-Workbench. After some testing I could make some steps further. With the yaml export and the doctrine “generate-migrations-diff” I could also auto generate migrations after changing my data model inside MySQL-Workbench.

Now with Symfony I am still using the schema exporter from johmue. I created a fork to fit my needs for my Symfony projects and it fits perfectly to get an easy and quick way from the MySQL-Workbench to a Sonata-Admin. And I created a Bundle the integrate the exporter into Symfony.

Prerequisites:

Steps:

Install Symfony:

http://symfony.com/doc/current/book/installation.html

Install the MySQLWorkbench-Exporter and the Exporter-Bundle:

Configure Exporter Bundle:

See https://github.com/HydraxSkarrag/mwbs-exporter-symfony-bundle#configuration

schema_name here refers to name of the Workbench file without the extension (mwb). Workbench files are saved in the Resources/workbench/ directory as *.mwb inside your bundle.

 Create your schema with MySQL-Workbench:

I think the MySQL Workbench is pretty much self explaining. Create your tables and relations and than save your file to your Bundle /Ressources/workbench/schema_name.mwb

Export your schema and create your database tables:

Export the schema:

Check the changes to your database:

Update your database:

Install Sonata Admin:

See the offical dokumentation: http://sonata-project.org/bundles/admin/master/doc/reference/installation.html

I am using the SonataDoctrineORMAdminBundle.

Follow to Step 2.1 http://sonata-project.org/bundles/admin/master/doc/reference/getting_started.html and stop after this step (2.1). You can use the sonata generator for the following steps.

Create Admin classes with the generator:

I suggest to create an extra bundle for you admin generator.
e.g. YourProjectAdminBundle.

To create the admin classes you can use this command:

Run your Sonata Admin and get lucky:

Browse to your site with /admin.

As you can see, the admin generator does not auto include your references. You have to add in on your own. And the ID for the edit mask should be removed.

How to change your Sonata Admin?

  1. Make your changes inside the MySQL-Workbench
  2. Export your entities
  3. Update your database
  4. Recreate your Sonata Admin or manually add your new fields (or remove.. or whatever)
  5. get lucky (again)

Questions? Errors?

Please use the comments!

Symfony2 on MAC using MacPorts

There are several good articles on installing MacPorts.

You can simply follow the instructions in the articles above. To get the basic extensions for symfony you can use one of the following port installs. Depending on the PHP version you want to use. I like the side by side version.

standard PHP:

side by side: