views:

247

answers:

6

If I write a hello world app using a PHP web framework such as CodeIgniter and then I compile it and run it using HipHop. Will it run faster than if I write the same hello world app in django or rails?

+5  A: 

At that point the run time is inconsequential. HipHop was designed for scaling... meaning billions of requests. There's absolutely no need to use something like HipHop for even a medium size website.

But more to the point of your question... I don't think there have been comparison charts available for us to see, but I doubt the run time would be faster at that level.

kylex
but... if I'm able to get 100 req/s using django in a dynamic page would I be able to get a higher number of req/s using HipHop and a PHP web framework?
Peter_o
maybe. Read the article in my answers to know the history of HipHop and what it do.
Donny Kurnia
hmm, i don't know for sure. i think convention holds that well written python will scale better than PHP (you can look at Eve Online for some evidence of this). I don't know how HipHop is made to scale. It converts PHP to a compiled language and spits it back out. I would assume it was written to scale on multiple servers, and thus, if you're writing for one machine you're def. going to be better off with python.
kylex
A: 

Running a simple application is always faster in any language. When it's become as complex as facebook, then you will face numerous of problems. PHP slowness will be show it's face. In same times, converting existing code to another language is not an options, since all logic and code is not so easy to translated to other language's syntax. That's why facebook developer decide to keep the old code, and make PHP faster. That's the reason they create their own PHP compiler, called HipHop.

Read this story from the perspective one of Facebook developer, so you know the history of HipHop.

Donny Kurnia
A: 

That is not really an apple to apples comparison. In the most level playing field you might have something like:

  • Django running behind apache
  • Django rendering an HTML template to say hello world (no caching)

AND

  • HPHP running behind apache
  • HPHP rendring an HTML template to say hello world (again, no caching)

There is no database, almost no file I/O, and no caching. If you hit the page 10,000 times with a load generator at varying concurrency levels you will probably find that HPHP will outperform Django or rails - that is to say it can serve render more pages per second and keep up with your traffic a bit better.

The question is, will you ever have this many concurrent users? If you will, will they likely be hitting a database or a cached page?

HPHP sounds cool, but IMHO there is no reason to jump ship just yet (unless you are getting lots of traffic, in which case it might make sense to check it out).

jckdnk111
+4  A: 

HIPHOP converts php code into C++ code, which needs to be compiled to run. Since pre-compiled code runs faster and uses less memory then scriping languages like python/php it will probably run faster in the example you have given.

However, HIPHOP does not convert all code. A lot of code in php is dynamic and can not be changed to c++, this means you will have to write your code with this in mind. If codeigniter can even be compiled using HIPHOP is another question.

Terry Chay wrote a big article about HIPHOP, covering when to use it, it's limitations and future. I would recomment reading this, as it will most likely answer most of your questions and give you some insight into how it works :)

http://terrychay.com/article/hiphop-for-faster-php.shtml

Thomas Winsnes
A: 

Will it run faster than if I write the same hello world app in django or rails?

It probably will, but don't fret. If we're talking prospective speed improvements from yet unreleased projects, Pythonistas have pypy-jit and unladen-swallow to look forward to ;)

Koobz
+1  A: 

i don't know about django or rails, so this is a bit off-topic.

  • with plain php, the request goes to apache, then to mod_php. mod_php loads the helloworld.php script from disk, parses & tokenizes it, compiles it to bytecode, then interprets the bytecode, passes the output back to apache, apache serves it to the user.

  • with php and an optimizer the first run is about the same as with plain php, but the compiled source code is stored in ram. then, for the second request: goes to apache, apache to mod_php, apc loads bytecode from ram, interprets it, passes it back to apache, back to the user.

  • with hiphop there is no apache, but hiphop itself and there's no interpreter, so request goes directly to hiphop and back to the user. so yes, it's faster, because of several reasons:

    • faster startup because there's no bytecode compilation needed - the program is already in machine-readable code. so no per-request compilation and no source file reading.
    • no interpreter. machine code is not necessarily faster - that depends on the quality of source translation (hiphop) and the quality of the static compiler (g++). hiphop translated code is not fast compared to hand-written c code, because there's a bit of overhead because of type handling and such.
  • with node.js, there's also no apache. the script is started and directly compiled to machine code (because the V8 compiler does that), so it's kind of AOT (ahead of time) compiling (or is it still called JIT? i don't really know). every request is then directly handled by the already compiled machine code; so node.js is actually very comparable to hiphop. i assume hiphop to be multithreaded or something like this, while node does evented IO.

facebook claims a 50% speed gain, which is not really that much; if you compare the results of the language shootout, you'll see for the execution speed of assorted algorithms, php is 5 to 250 times slower.

so why only 50%? because ...

  • web apps depend on much more than just execution speed, e.g. IO
  • php's type system prevents hiphop to make the best use of c++'s static types
  • in practice, a lot of php is already C, because most of the functionality is either built in or comes from extensions. extensions are programmed in C and statically compiled.

i'm not sure if there was a huge performance gain for hello world, because hello world, even with a good framework, is still so small execution speed could be negligible in comparison to all the other overhead (network latency and stuff).

imo: if you want speed and ease of use, go for node.js :)

Schnalle