Let’s leave sunny California and take off for snowy Minneapolis, Minnesota, for the MidwestPHP conference. If you’re snickering and picturing a bunch of bearded woodmen axing PHP code in frozen cabins, I’ll stop you right there.
Beards were produced, no doubt about that; and I hear that some people there are rather talented with a hockey stick. But there were speakers and attendants from literally all over the nation (and abroad!), and even though PHP is not my main trade, I picked up a lot of invaluable information during the conference.
Assuming that many of you might not be PHP programmers, here is my attempt to give you an original summary of my experience.
Joel Clermont learned us how to learn
For starters, this keynote talk is a goldmine for anyone—not only the PHP programmer. You might already know the beneficial effects of pair programming and mind maps; but did you know that being happy makes you a better learner, and that even you might have heard otherwise, working under pressure is actually bad for creativity and learning? So, no more of that “I’m waiting the latest minute to turn in that thing”—it actually hinders your productivity.
When Joel recounted his experience with the first computer he ever worked with (I think it was an Apple II), I remembered that I lived a similar story with the MO5 (but you had to be in France 25 years ago to know about that other computer), in the way that when you turn on the thing, you land at the prompt of a BASIC interpreter, and you cannot do anything but program. It makes me wonder about the educational value of a netbook which would—instantly!—boot and show up an IPython prompt…
Joel’s slides are available at https://speakerdeck.com/jclermont/learning-how-to-learn
Omni Adams got us hooked on git hooks
I already knew about git hooks (and how you can build your own simplified PAAS with them, for instance), but I also knew that I didn’t know everything about them! And I was eager to hear other people’s use cases. I won’t repeat Omni’s talk, but a couple of ideas sparked from the talk:
- If you want to share the same set of git hooks between multiple repositories, without defining those hooks as being global (i.e. in your per-user ~/.gitconfig), what about defining them in another repository, and then have $REPO/.git/hooks be a checkout of that repository?
- Sometimes, you want to change the content of a file, or maybe even just a symlink, depending on the branch you’re working on; but you don’t want to track that into your repository. For instance, you want to switch some config.yml file depending on whether you’re working on the production or development branches. Well, a post-checkout hook can do the trick, and will do whatever you need whenever you switch branches!
Omni’s slides are available at http://mordor.digitaldarkness.com/git-hooks/.
Steve Meyers taught us how to optimize MySQL databases
I really enjoyed that talk (and the conversation that ensued). Why? While I prefer to work with PostgreSQL, I also get involved with MySQL on a regular basis. I have a snarky answer to MySQL performance issues: “migrate to PostgreSQL!”; not because PostgreSQL is better (that would be a matter of personal opinion and heated debate!), but because I know how to optimize the heck out of it, while I’m generally pretty clueless in front of the decisions of MySQL’s query planner. I know how to read the innards of a 30-lines EXPLAIN query with PostgreSQL, but I can’t figure out what to conclude out of the same EXPLAIN with MySQL. Well, I didn’t magically turn into a MySQL Grand Master, but listening to Steve certainly took me closer to that!
If optimizing queries gives you headaches (don’t worry, it’s not an uncommon condition), you want to have a look at the Percona tools instead. pt-query-digest, for instance, can (among other things!) analyze the output of tcpdump, detect SQL queries and their responses, and extract some performance information from that. That’s just a little example of what this tool can do, and there are other tools in the kit!
Steve’s slides are full of healthy, good stuff and can be found at http://dl.dropbox.com/u/1564228/Database%20Optimization.pdf.
David Stokes sold us on MySQL 5.6
MySQL 5.6 comes with lots of improvements. Okay, given the choice, the fanboi in me would still want to migrate to PostgreSQL, but first, I would suggest to upgrade to MySQL 5.6! ☺
Seriously: replication is now much easier to setup and operate, thanks to scripts like mysqlfailover.
As David pointed out, virtually everyone has a home-brewed cousin of that script running in production, to fix up a slave and promote it to master (when the current master fails). Therefore, it made sense to provide and support one script upstream, and let everyone use that instead.
There are many other nifty features, but one of them caught my attention, being original and useful: time-delayed replication. You can setup a MySQL slave to apply changes after a fixed delay. With a delay of 1 day, it means that if you DELETE or UPDATE some data in your master database, the change will be applied on the slave 1 day later—in other words, the old data will still be there for 1 day, should you change your mind (or realize that you made An Awful Mistake).
Jason Rhodes proved that WordPress and its deployment weren’t necessarily evil
As the speaker acknowledged himself, WordPress has the reputation of being “for amateurs”. I worked on WordPress deployment on dotCloud, so I was curious to see what a “Tier 1” WordPress deployment looked like. Jason proved that WordPress deployment can be as slick as Rails (he uses Capistrano, by the way!).
Jason’s slides are available at http://notrobotic.com/talks/2013-03-02-wpgalaxy.html, and they also include a TON of VERY useful links covering many different aspect of WordPress deployment, development, and customization. My go-to place next time I have to deal with the beast!
Sara Golemon told us everything we wanted to know about HipHop PHP (and a bit more)
I knew that HipHop was essentially a PHP/C++ translator, implemented by Facebook to withstand their crazy load. I learned a lot more! The first incarnation of HipHop PHP is HPHPc. HPHPc was indeed a code translator. Compiling the Facebook codebase “took 20 minutes on a cluster of 100 machines”, which is kind of annoying when you compare that to the usual time it takes to see the changes after you modify a .php file (i.e. the time it takes to press Ctrl+S or your editor equivalent for “save file”).
To address that issue, Facebook implemented HHVM (HipHop Virtual Machine), a virtual machine executing a special kind of bytecode (HHBC)—like the Java Virtual Machine, if you will. Instead of producing C++ code (which gets compiled to x86 code), this new design of Hip Hop produces HHBC and runs it on HHVM. HHVM has JIT translation and optimizations (like the JVM), to provide performance as close as possible to traditional compiled languages. HHVM also comes with an interpreted mode to address the issue of compilation time.
The performance gains are tremendous (~500% if you stack together the improvements brought by HipHop and the improvements brought by recent versions of PHP), and the memory footprint is also considerably better, since HipHop doesn’t execute one process per concurrent request, but relies on threads instead, and has an API for asynchronous events (i.e. a given request can wait for an event without blocking a thread). HipHop also lets you write better code, since it brings features like static typing to PHP.
Sara wisely reminded us that before using HipHop to get better performance, you should first check if there are other low-hanging fruits. In other words, make sure that your performance bottleneck is indeed CPU and RAM usage, instead of e.g. database queries!
By a pleasant slip of the tongue, she also revealed us that the secret of HipHop compilation was “bleeding edge virgins, err, versions” ☺
Chris Hartjes convinced everyone that they should build testable applications
There is a strong emphasis on “Test Driven Development”, and why it’s so important to write tests for your apps. But Chris tells us that writing testable applications is even more important; since if your applications are hard to test, you will take every excuse to not write the tests.
One of the most important rules (in my humble opinion!) is to address dependency injection correctly. In other words, if your code uses any kind of external resource (call to databases, API, whatever), the handles used to access those resources should not be sprinkled all along the code.
Assuming that your code is object-oriented, those resources should be passed to constructors: at least, you will have a unique place to find them all, and it will be way easier to implement mocks.
You will find many other insightful information about testable applications in Chris’ slides, at https://speakerdeck.com/grumpycanuck/building-testable-php-applications-1 (and while the examples are in PHP, the design principles are good for any language).
I showed what PAAS could do for PHP developers
I delivered a talk explaining how PHP deployment had changed in ~15 years, and showing step by step how to deploy a sample application (which used Symfony2, MySQL, and MongoDB, with the Doctrine ORM) to dotCloud. Since dotCloud was sponsoring the conference, that talk even made it to a keynote—which is great since I got a larger audience, but also means that I had to tailor my talk for that audience, instead of doing a purely technical talk. I did my best to not turn that in an awful “dotCloud sales pitch roadshow”, since I know how people can be reluctant about those “second-day sponsored keynotes!”
The slides, including detailed examples showing how to run a full-blown Symfony2 app on dotCloud, are available below
…And I met awesome people
I hope that my very short summaries convinced you that the talks were great; but now I have to pay tribute to the organizers (who really went out of their way to make this an outstanding event), as well as the other speakers and participants for both on-topic and off-topic discussions. Subjects included deployment and devops, but we also tackled hockey, homebrewing, and aged rums (although unfortunately, no sample of the latter could be produced to make a point☺). I do hope that there will be a 2014 edition, and if that happens, you should be attending!
About Jérôme Petazzoni
Jérôme is a senior engineer at dotCloud, where he rotates between Ops, Support and Evangelist duties and has earned the nickname of “master Yoda”. In a previous life he built and operated large scale Xen hosting back when EC2 was just the name of a plane
, supervized the deployment of fiber interconnects through the French subway, built a specialized GIS to visualize fiber infrastructure, specialized in commando deployments of large-scale computer systems in bandwidth-constrained environments such as conference centers, and various other feats of technical wizardry. He cares for the servers powering dotCloud, helps our users feel at home on the platform, and documents the many ways to use dotCloud in articles, tutorials and sample applications. He’s also an avid dotCloud power user who has deployed just about anything on dotCloud – look for one of his many custom services on our Github repository.
Connect with Jérôme on Twitter! @jpetazzo