Symfony Live Conference, Paris 2010 (Day Two)

« Symfony Live Conference, Paris 2010 (Day One) | Green IT operations: important for your corporate sustainability strategy »

A tour de force lasting from 9am to 7:30pm, day two of Symfony Live was packed with informative sessions and, of course, the preview release of Symfony 2.0 (which will be covered in its own separate blog post very soon).  I wrote this post based on my conference notes while on the plane back from Paris on precious little sleep, so please let me know if you find any inaccuracies. For day one of Symfony Live 2010, click here.

All of the presentation slides can be viewed online on the Symfony Live Event page on Joind.in.

Okapi and Symfony

The makers of the Okapi translation framework obtained an early copy of the Dependency Injection Container (DIC) from Sensio and undertook a migration of their product to use Symfony Components. The presentation gave some clues on the architecture of Symfony 2.0. For example, arguments will be passed explicitly to the controller (instead of the controller grabbing the request object itself). Lukas Kahwe Smith warned not to simply pass around the DIC as this defeats the purpose and nullifies performance gains. We were also given a peek into how the Dependency Injection (DI) configuration will use parameter syntax like %dsn% to avoid repetition. Symfony Events, as opppsed to the filter chain in symfony 1, can now call filters only once if necessary. They claim that migrating to the Symfony Routing component took only 2 hours to complete (plus some tweaks). After the migration, Okapi now relies more on Symfony classes than custom classes which means less code to maintain.

Optimizing PHP Code

Xavier de Cock’s presentation on performance was the most low-level in nature (from a technology stack perspective). The beginning of the talk was very Zend focused, and a bit hard to follow for a more application-focused person who is not very familiar with Zend Engine (also because of a thick French accent). Essentially, De Cock is interested in profiling an application, such as SwiftMailer, and analyzing every aspect down to the opcode in order to improve performance. In general, he discourages trying to “outsmart” the underlying opcode caching mechanism, noting that you may end up actually reducing performance. He uses Vulcan Logic Dumper to see what opcode was produced by the PHP code and employed both Xdebug and Zend Debug profilers to identify sections of code that are ripe for optimization.

Suggested tips and tricks

  • Use built-in PHP functions (as opposed to your own custom functions)
  • Use opcode caching (APC, eAccelerator, etc)
  • Use data caching
  • Optimize SQL (usually the number one culprit)
  • Get your data from the 2DB in batches
  • Create a PHP extension (I doubt most of us will I’ll go this far)
  • Use other extensions like HipHop, Phc, Quercus or Roadsend PHP
  • Pre-incrementation of a counter variable inside a loop performs better
  • than post-incementation
  • While loops outperform for loops
  • Stay away from array functions like array_unique() (but they’re dang convenient)

Biggest common mistake: Creating memory leaks created by referencing objects in loops. This is only big deal in processing scripts like daemons (not typical web pages), and the cyclic garbage collection in PHP 5.3 provides vast improvement here.

Bottom line: the most interesting aspect of this talk was seeing what tools and techniques he used to identify slow code, but most developers should not worry about the majority of the techniques he demonstrated and just focus on optimizing database queries because that is where the low hanging fruit is.

Git 101

Scott Chacon is clearly a seasoned speaker, having done the Rails conference circuit, and the high quality of his presentation showed it. The graphics and animation in his slides are more than eye-candy; they genuinely help to demonstrate how Git works. Scott also gave a full-day Git training the day after Symfony Live, which I unfortunately could not attend. I reckon that this presentation was an abridged version of that training sans exercises. There were a lot of points that he did not have time to go into, but here are the high-level features:

  • Developed by Linus Torvalds
  • Used for Linux Kernel and Android
  • Fully Distributed. Each clone is a backup and is equivalent
  • No network connectivity needed to do work
  • Immutable (never removes data)
  • Based on full snapshots (not deltas)
  • Commits are hashed strings (incrementing numbers, although convenient, are not used)

Parts

There are three primary working parts to wrap your head around:

  1. Working Directory
  2. Index
  3. Repository

Workflow

In the Git workflow, there are four primary steps:

  1. Edit Files
  2. Stage your changes (git add)
  3. Review your changes (git status)
  4. Commit your changes (git commit)

Tips

If you’ve been working on a lot of different files and features simultaneously, committing a “changeset” of related edits instead of one gigantic commit is a good idea.

Random Thought by Scott

Although it is theoretically possible for two Git revision hashes to collide, it is more likely that your entire development team will be killed by wolves in separate incidents.

This presentation solidified my opinion that Git is generally better than Subversion and that it should be the SCM of choice in the future. I have been wanting to make the transition to Git as the default SCM for all of our PHP projects at SolutionSet, but existing infrastructure investments and lack of developer knowledge have been a hindrance. I hope that the use of Git for Symfony 2 will speed the adoption of Git in the PHP community and lead to SolutionSet’s transition to Git in 2010.

Writing Clean Class Interfaces with Symfony Events

Dennis Benkert, also the organizer of Symfony Day in Germany, shared his thoughts on how to reduce coupling in your classes and separate concerns. Accoring to Ted Faison, “Coupling is single greatest problem in complex system”. When different classes need to interact, a Service Layer should be used. There are two main ways to achieve decoupling (once you’ve already logically defined your classes): Depency Injection (DI) and Events. DI should be used for mandatory depencies and Events for optional dependencies. This presentation focused on Events.

Types of Event messages in Symfony

  • notify - doesn’t expect a response
  • filter - returns a value to the next filter in the chain
  • notifyUntil - similar to a filter but stops the filter chain when a certain condition is met

When Dennis put out a call on twitter for example of Event usage, he got some useful responses such as allowing someone to override the behavior of a plugin, but the most notable was a sarcastic tweet about using Events to totally obfuscate your classes so no one else can follow them.

Event Usage Pitfalls

  • Don’t use for mandatory coupling (use DI)
  • There is no order to event listeners (if you are expecting this you are doing something wrong)
  • Events make code harder to follow and debug
  • Events can be slow once you add a lot of listeners
  • Don’t use events in the model

There were a couple of memorable quotes from this talk…

A phrase that was picked up by multiple other speakers: “Every time you use sfContext, you kill a kitten”.

And my personal favorite (on the Symfony Events component mascot): “The octopus is keeping his eye on everything. Like with his arms.”

Zend Framework and Symfony

Matthew Weier O’Phinney, project lead for Zend Framework (ZF), started by saying “I am not the enemy”, and I believe him. Given the fact that Zend invited representatives of Symfony and other PHP frameworks (Cake, Agavi and CodeIgniter) to spar at the last ZendCon and the fact that Symfony 2 heavily relies on Zend Components, it appears that ZF and Symfony headed more in the direction of cooperation than competition. That being said, O’phinney still won the best tweet of the conference for saying “I enjoy the fact that Fabien is worried about spilling secrets to me”. Expect ZF to take a few pages out of Symfony 2’s playbook in the future.

Matt explained that there is really no magic to using Zend Components within Symfony; it’s as simple as adding some code for the Zend autoloader in the ProjectConfiguration class. An example of this is given in the Jobeet tutorial, but the code has been optimized to store the autoloader instance. His theory is use the best tools to do what you need to do regardless of their source, be it PEAR, EZ Components, or anywhere else.

Zend Library Standouts

  • Feed Tools
  • Remote APIs
  • Lucene Search
  • PDF generation
  • Queuing
  • Cloud computing

It was exciting to hear Matt talking about the Service Layer concept from Domain Driven Design. With the new flexibility of Doctrine 2 and Symfony 2, it should now be possible to design a richer domain layer within a Symfony project that includes Services, Entities, Data Mappers and a Data Access Layer (DAL). The Service layer is useful for validation and filtering, permissions (ACL) and interactions between Entities. For unit testing he mentioned 80% coverage as a good target (as opposed to 90-100%). Zend libraries can be used to easily expose your service layer as an API. I am looking forward to using this technique on a current project of mine.

Debugging Symfony

Alvaro Videla shared his experience debugging and optimizing a very large German dating site with 2 million members hosted on 28 production servers. He uses the vast amount of data that is stored in Symfony logs to identify slow areas of code by using a flag in APC to turn logging on in the production environment for a short period of time on each server and store the logs in CouchDB. CouchDB was able to handle storing 15 million log records in the first week!

Debugging Tools and Technologies Used

  • AWK - for extracting log data
  • avRedisLoggerPlugin - a persistent key-value database
  • Tsung - a high performance, open source benchmarking framework
  • XHProf - code profiler
  • Graphite - a powerful data visualization tool

He uses logging to detect site outages by generating an alert if say 100 DB connection error logs happen within a minute and calls this “threshold logging”. Alvaro is also the developer of the FireSymfony Firefox plugin, which is an awesome replacement for Web Debug Toolbar except for the fact that it doesn’t work with the latest version of Firefox. Well, at least it doesn’t work for me on Snow Leopard and a lot of other people if you check the support forum.

Implementing a CMS in Symfony

When Marcos Labad set about providing a Content Management System (CMS) for his client in the publising business, he looked at the major options available in early 2009 (Sympal, Diem and Apostrophe) and decided to roll his own. Key aspects to the success of his project were great people, good communication, designating stakeholders and planning backwards.

Why Choose Symfony as base?

Active development and support Some Learning curve but good documentation Big and growing community Form framework Easy maintenance and support for the final owner Based on good practices and patterns Reusable parts Easy to integrate new engineers

Why not Drupal or Joomla? Not good for specific data models Learning curve as well May be fast to implement but are hard to maintain and extend

Tips

  • Don’t forget about 301 redirects when upgrading a site
  • Use Doctrine behaviors to save time

Symfony in the Cloud

Kris Wallsmith, release manager for symfony 1.3 and 1.4, is currently working on a startup called nebul.us which allows users to passively share what they are doing online (as opposed to actively blogging or tweeting about it). It seems like a powerful idea if they can make it easy enough to control what people see without making it an active process again. He made some very good points about deploying nebul.us (or your app) to the cloud:

  1. You don’t need to know how the could works, you just need to know how to use it, and hosting providers like Rightscale, Amazon and others make it easy
  2. There is nothing difficult about deploying to the cloud. It’s essentially the same LAMP stack you are used to.

Query Splitting

Kris put a lot of thought and into query splitting and has shared his work in the sfDoctrineMasterSlavePlugin which uses database transactions by default.

File Uploads in the Cloud

Files in the cloud will need to be:

  • Uploadable to a service (like S3)
  • Retrieved from a service in the view (with a helper)
  • Disable-able (for the dev environment)

Deployment Tips

  • Use the symlink method so you site is only down during the database migration (and not the code update)
  • When using migrations during deployment, be sure to only execute once

Symfony at Yahoo!

Dustin Whittle joined Yahoo! with the assignment of migrating Yahoo! Bookmarks to symfony. Once Bookmarks was proven as a test case, Yahoo! went about migrating several more web properties, such as Yahoo! Answers, to symfony. Yahoo! Answers is the largest collection of human knowledge on the Internet (515 million answers). Clearly, a generic ORM is not going to cut it for a data store of this size, so Yahoo! only uses symfony for the presentation layer and uses web services to retrieve the data (although for smaller projects Yahoo! still uses Doctrine). Dustin makes a good point when he says, “all PHP developers use a framework, even if they don’t think so”. In other words, your non-framework based project still makes design choices that could be considered a framework. Dustin works for Rasmus Groth (the creator of PHP), who believes that you should design your application to solve your particular problem and nothing more. It was this kind of thinking that led Sensio to create Symfony 2 with much more flexibility.

Yahoo! Symfony Plugins

Yahoo! has created and shared a handful of plugins that they use to build symfony applications. They all start with a “y”, for example:

  • ysfBuildPlugin (for deploying performant apps)
  • ysfR3Plugin (for Yahoo!’s flavor of translation)
  • ysfDimensionsPllugin (adding depth to symfony’s configuration)
  • ysfYUIPlugin (for Yahoo!’s javascript library)

Tips and Observations

  • Scalability is when you can add hardware and get a proportionate increase in performance
  • Most performance comes not from the language, but from the design -Rasmus
  • Don’t spend more time managing the cache than retrieving data from it
  • Don’t use .htaccess (use regular Apache config for better performance)
  • Aggregate and minify your CSS

Dustin encouraged developers to get to know the Yahoo! Open Stack.

MOST INTERESTING MOMENT: After plugging YUI, Dustin asked the room to raise hands to show what javascript framework they use. jQuery left all other libraries in the dust. Then he tweeted “It just clicked how many jQuery users there really are…”

Symfony 2

The preview release of Symfony 2 deserves it own post, which I will post soon.

For day one of Symfony Live 2010, click here.

This entry was posted on Thursday, February 18th, 2010 at 7:46 pm and is filed under Community & Social Media, Digital Marketing, Technology, Web Development Process. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “Symfony Live Conference, Paris 2010 (Day Two)”

  1. Matthew Weier O'Phinney Says:

    One clarification on my part: we require a minimum of 80% coverage in ZF components, but encourage higher. Typically, by the time code hits trunk, it’s at > 90%.

    What is more important is good testing practices. If you are testing discrete behavior, you will typically easily achieve 100% coverage, as you are testing actual use cases for the component.

  2. Debra Baniaga Says:

    Howdy. I really like this weblog. Im positive i will get back shortly. In the meantime you’ll be able to visit my site.

Leave a Reply

* indicates required information