PHP UK Conference 2013

Escalando con HipHop

Sara Golemon  · 

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

so who in here is at least heard of hip-hop okay none of you know what it is I don't know some of you might I'm going to go over some of the history of hip-hop what kind of convinced Facebook that we needed to create it and use it and why what you're

thinking of is hip-hop probably isn't what it is when we introduced hip hop years ago it was a very different product it's changed a lot so we're gonna go over a little bit of that so to start with what kind of problem are we trying to solve Facebook

just recently announced that we've gone over a billion monthly active users that's like people actually interacting with a site not just accounts that's a lot of activity we have servers running that site it takes a lot of power network bandwidth

all that sort of thing it's the sort of thing that you hit a scale that you just say we literally can't keep firing servers at this problem it's going to just break the entire site eventually probably not a lot of your sites are at that scale but

they are at some scale you maybe have a few hundred or even a few thousand servers running at your site you might don't even only have a few dozen you might just have a couple of ec2 instances but you don't want to make that grow too fast why do we

need so many servers we need it because of some of the inefficiencies that are just inherent to PHP in the kind of language and runtime that it is we have to do a lot of data copy so I should mention I'm also a developer on the PHP project so when I think

of in efficiencies I think of things like we've got a system allocate a block of memory it needs to go into engine allocate or block so we needed and purposely purposelessly copy all this extra data over where it doesn't need to be so that's sort

of the gist alt of the problem there so how do you fix that problem well rebuilding your run engine in your runtime from scratch is not the first thing you should be doing the first thing you should be doing is all the easy stuff and I don't need to tell

anyone in this room what those easy things are databases are gonna be half of your bottleneck right off the bat you know how to make your code better so I'm not going to go into that eventually though you run out of those easy things and all that you're

left with is your actual language and your runtime and all of the extra work that's being done that doesn't have to be done so these are again just kind of a rehash of some of those same problems that I just mentioned you've got multiple processes

running because you don't really trust Apache to worker to work nicely with PHP I know in theory it's supposed to work but how many people are actually running PHP with Apache 2 in the worker npm 0 that's what I thought cousin of us trust it so

when PHP is a problem what's our solution our solution is we decided we were going to rewrite the entire PHP engine and runtime from the ground up and we were going to use some lessons learned from both the PHP project itself and from kind of what we know

about how we use PHP that's the official explanation the real explanation is actually something more like one of the engineers at Facebook just didn't like PHP and he wanted to convert the whole side to C++ what better way to do it than just write

an auto converter that's why the original version of hip hop was just this source transformer and I'll talk about that in a couple later slides one of the side effects of this though is that we've actually removed Apache from our configure our

stack completely this is not to say that Apache is bad Apache is a great web server I love you Apache web server I love the the community that is around the Apache web server but it is a gigantic Swiss Army knife when all you need is a Clark screw so we've

got a web server that's very thin very lean does what we need to do and does what most sites need to do obviously there's going to be a few things that it doesn't support and that's unfortunate the good news is we are actually in the process

of building out our sappy layer so that we can plug into Apache or any fast CGI web server that's coming along in the coming year we don't have an ETA for that yet what you see on the right here is an example of what a configuration for our web server

looks like the structures a lot different than Apache but fundamentally the settings are all basically the same we're telling it where to find our files we're setting up some virtual hosts not in this example but that never mind we're specifying

some log files this is all basic web server setup stuff so I promise to get into the history of hip hop a little bit this was our first version the compiler this would take your PHP source translate it just literally line for line into C++ and then toss it

off to make now this was a nice easy thing to do it's it sort of fits into the gun is better than perfect philosophy unfortunately to build all of the Facebook web codebase takes this number is kind of a fuzzy thing because it depends on how many build

machines were pushing out to you but it's on the order of 20 plus minutes spread across more than 100 machines this is completely impractical for the average developer because you're not going to assign 100 build machines per developer and it is even

then 20 minutes to do a single change to some file and just see that it works is not acceptable so how do we deal with development well it's fine we'll just let our regular developers use the Apache PHP environment which I'll refer to as ape or

the rest of this and for production we'll do h PG C and natl be fine that'll be great except it won't be because now PHP is not PHP you might write something that works perfectly fine under ape crashes fails fatals dies does unexpected things under

protection so at plus we're adding new features to the language as we're developing it since we now control our entire runtime stack we've added things like xhp and generators which granted have since reached regular PHP well generators have X

each P is actually exposed as an extension but it's still not the same language even under the best circumstances and we don't have the best circumstances because we haven't reimplemented the entire runtime so here's the fix we're gonna

take our abstract syntax tree that we're already parsing using HP HVC and we're just going to run through it line by line not worrying about you know caching or turning into byte codes or anything like that this is basically how PHP 2 ran if you know

when I here use PHP - not surprising PHP wasn't quite that popular at that point but this is slow on the best of days but he has just development so if it takes an extra thousand milliseconds no big deal trouble is it's still not quite HP HP C there's

still some minor differences in the language it still doesn't quite behave exactly right so that brings us to sort of version 2 of hip hop and that is h h vm this was built with a lot more knowledge of how do we want to be using this for development and

what can we do to actually get this to perform at the same kind of level as something that's basically c++ is being built with me now what do we do we copied PHP we compiled everything to bytecode we shove that into a cache kind of like a pcs got and we

run that bytecode through a virtual machine saying oh here's an echo statement here's ba ba ba ba ba ba ba ba and not surprising we're about on par with PHP 5 using just this approach then we throw a JIT on top of that the JIT is going to say alright

[ ... ]

Nota: se han omitido las otras 3.853 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.