Friday, February 5, 2010

HipHop: Stop What You're Doing

So the PHP proletariat is foaming at the mouth with Facebook's announcement of  HipHop.  Now, there are certainly some great discussions of the topic -- take Terry Chay's multi-page inside look or, for a Python perspective, take a look at Alex Gaynor's observations. These guys are pretty qualified to comment.  But there's a lot of crazy talk out there.  Crazy talk?  Well, damn, I wanna talk crazy too!

Am I qualified to have an opinion about this?  Well, I certainly haven't used it yet or looked at the source (both related to the fact that the source is still not posted to github); I certainly haven't worked at Facebook and don't personally know anyone that does; it is completely irrelevant to me (as it is to most PHP developers).  ... So, I think I've got what it takes to voice an opinion that is unencumbered by fact or first-hand experience.

I felt so qualified on the topic that I joined in loudly on a discussion in the local DC PHP group.  My comments elicited quite a response on the list.  I'm sure my poorly masked distaste for PHP doesn't exactly endear me to the group.  (Why, you may ask, am I on the PHP list in the first place?  Well, I would say "for the ladies", but I'm worried my wife will find this blog!)  My comments were apparently so poignant that they were selectively quoted in a real life DC-area blog.  Not just quoted, but actually described as "puritanical" and "naive" (in the same sentence), which I consider the high-water mark of my inter-personal communications career.   Not to pick on Aaron (well, maybe a little, but that certainly seems fair), but this post has some unfortunate bits that have been a little too characteristic of the PHP community's hip-hopped-up responses:
Personally, I wish we had HipHop when [...]  We had a ton of scaling problems with PHP and we were running fully clustered Apache servers (25 deep, if I recall), sharded MySQL across 6ish database servers, and we had massive I/O bottlenecks.
Ok, look, now I haven't used HipHop either, but if we're to believe the author, then HipHop reduces CPU load.  This, by definition, isn't relevant to I/O problems.  I know; it's hard not to get swept away with the excitement.  This is, after all, the evolution of language.  I am a little disappointed to have been the spark for that post.  Now, I'm sure that this was an honest mistake and that certainly if Aaron was managing clusters of 30+ servers, he knows that I/O bottlenecks are not the same as CPU bottlenecks.  But it does tarnish the argument a little.


My favorite (so far) is the article on Sitepoint, which I thought had presumptions of being a trusted source of knowledge in the PHP world.  Check this out: Boost your PHP Performance 50% with HipHop.  That's right, not only is this article also oblivious to what makes PHP apps slow, but the author appears to be tripping up on some basic consumer mathematics.  Yes, HipHop on Facebook showed a reduction of CPU usage by 50%.  That means it used half as much CPU ... so those scripts perform twice as fast (w.r.t. CPU).  Now, bear with me.  A 50% boost means 1.5 times as fast.  2 != 1.5.  Well, since this is PHP there's always that danger that unequal things will evaluate as equal, so let me be more precise: 2 !== 1.5.

Ok, but before I went off on all this ad hominem venting.  I actually had a more constructive point I wanted to make.  It took a few forms (some more enraging than others), but the gist was this: reconsider.  If you need to compile PHP into C++ and run it on a custom-designed server platform because you've maxed out your CPU, maybe PHP wasn't the right choice.  I'm just sayin'.  

I'm not saying that changing platforms is easy.  I've been involved in migrations to Python (from PHP) for the past couple years and can certainly attest that it's hard and sometimes it takes time, but sometimes it's the right thing to do.  We sat down and looked at some of the things that we were doing and realized that we were jumping through some crazy hoops to work around deficiencies in language & platform.  After reviewing our options, we decided that Python offered the quality, community, broad applicability, extensibility, and scalability that suited our needs.  A big part of this decision was the scaling path.  We knew there were proven ways to extend Python with Java (via Jython) or C/C++.

There's was a lot of suggestion in our discussion that it didn't make sense for Facebook to ever reconsider PHP.  But as Terry Chay noted, there were several efforts to move Facebook to Python and to C++; they just never had the resources allocated to actually accomplish it.  And looking at the array of technologies Facebook employs, it's pretty obvious that they understand the basics of comparative advantage.

I am not a curator of startup history, but it does seem that there are plenty of cases to be found where applications can evolve to use new technologies successfully.  Twitter looks like an example where this worked quite successfully.  They didn't have to throw all their Rails code away, but they did start rewriting pieces in Scala (on the JVM).  The interview on Artima is a good read.  And Google recently was rumoured to be encouraging new development to use Java instead of Python.  I know I read about it in an Unladen Swallow thread, and while I obviously like Python, I think this is a mature stance.  Choose the right tool for the job.

So, at the end of the day, I'm just kinda baffled by all this HipHop hubbub.  Not only has it been done before, but for almost every application and for all new development it just seems completely irrelevant.  Why would you choose to write something in PHP?  Not for the language, right?  Not for the wealth of libraries.  Not for the culture of quality.  Not for the extensibility.  No, you'd use it because it's drop-dead easy to deploy and the PHP+Apache(+MySQL) platform is ubiquitous.  So, HipHop renders inapplicable the only reasons I would choose PHP.

Oh, but I do like the name.

No comments:

Post a Comment