Some thoughts on green programming, PHP, Midgard and simplicity

Rasmus Lerdorf's excellent talk on PHP and simplicity in FrOSCon introduced me to concept of green programming. To quote the Green Programming blog:

Just like we should aspire to use renewable energy sources to help the health of the planet, we should also use reusable software elements to create robust, healthy code for our customers. Eco-friendly practices might be thought of as applicable to software devlopment. Just as we are concerned with the various biota and climate of the planet, we should be concerned with the over-all health of the software eco-system.

How does Midgard sit in with these ideas? Well, the current version of it does not. MidCOM 2 is a heavy, enterprise-oriented CMS framework that requires big machines, or even clusters to run.

But things are quite different in Midgard 2 land. We have rewritten the MidCOM framework from scratch, removing the need to have abstractions on top of abstractions to support the shift from classic Midgard APIs to the new ones, and from PHP4 to more object-oriented PHP versions. We have also focused on simplicity and adaptability, to make MidCOM an easier environment to work with for site developers.

While MidCOM3 is not due to be out before next March, Tero Heikkinen, an early adopter has been building some production sites with it already. And his experiences state that not only the performance is much better, but also it requires much less work from programmers.

I know Rasmus' argument is that frameworks are evil by requiring developers to adopt to their own concepts, and by introducing unnecessary overhead. But we should look beyond mere server-level productivity, and take programmer productivity into account. A framework makes things much easier for agile teams, enabling people with different competences to work in their isolated environments. Programmers can work on the code, and designers on the templates for instance.

While this makes the actual development and deployment process more efficient, how much performance is lost due to the framework?

Lies, damn lies and benchmarks

Like Rasmus, I used an APC-cached simple PHP "hello world" file as the baseline for my benchmarks. On my dog slow MacBook Air, the simple PHP file was able to serve 32.91 requests per second.

MidCOM3, when run on Midgard 8.09 with APC and memcached was able to serve 8.90 request per second, or in other words performed at 27% of the plain PHP file. Not too good, but considered that much SQL is run to serve a Midgard page, there are good explanations at this.

But compared to Drupal, which I did not install but instead calculated the performance based on the difference between my baseline (32.91 r/s) and Rasmus' (611.78 r/s), MidCOM3 was doing quite fine. Drupal would only be serving about 2.5 requests per second on my box. Zend Framework, again calculated from Rasmus' data would provide 6.5 request per second.

And this is not all. Piotr Pokora has done a stellar work with Midgard2, which will come out in spring numbered 9.03. With it, MidCOM's numbers were quite a lot better: 25.37 requests per second, or 77% of the simple PHP file's performance. This is actually faster than the same simple PHP file on my box without APC (24.84 r/s).

I believe the MidCOM3 performance story does not end here. Piotras has been doing experiments with caching Midgard's initial request data to reduce database queries, and MidCOM3 still misses the extensive caching infrastructure provided by MidCOM2. When these are in place, we may get pretty damn close to the plain PHP numbers.

So, with these numbers, I think we can say that Midgard2 will be quite a good framework for doing green programming while still retaining agile team efficiency.

Towards a greener future

This matters quite a lot, as then Midgard can be run with much smaller virtual machines consuming much less electricity to serve interesting information-rich applications.

When Ragnaroek gets out in end of September we will start focusing our efforts to the new platform that already is showing so much promise. A brighter, greener, more efficient future lies ahead!

Read more Midgard posts.