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:
(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:

The result with the next profiling:

208ms instead of 3.x seconds.

The direct comparison:

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.

From MySQL-Workbench to Sonata-Admin


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


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.



Install Symfony:

Install the MySQLWorkbench-Exporter and the Exporter-Bundle:

Configure Exporter Bundle:


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:

I am using the SonataDoctrineORMAdminBundle.

Follow to Step 2.1 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!