简体   繁体   English

简单的Facebook HipHop性能问题

[英]Simple Facebook HipHop Performance Question

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. 如果我使用PHP Web框架(如CodeIgniter)编写一个hello world应用程序,然后我编译它并使用HipHop运行它。 Will it run faster than if I write the same hello world app in django or rails? 它会比我在django或rails中编写相同的hello world应用程序运行得更快吗?

HIPHOP converts php code into C++ code, which needs to be compiled to run. HIPHOP将PHP代码转换为C ++代码,需要编译才能运行。 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. 由于预编译的代码运行速度更快,使用的内存更少,因此像python / php这样的脚本语言可能会在您给出的示例中运行得更快。

However, HIPHOP does not convert all code. 但是,HIPHOP不会转换所有代码。 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. php中的很多代码都是动态的,无法更改为c ++,这意味着您必须记住这些代码。 If codeigniter can even be compiled using HIPHOP is another question. 如果codeigniter甚至可以使用HIPHOP编译是另一个问题。

Terry Chay wrote a big article about HIPHOP, covering when to use it, it's limitations and future. Terry Chay撰写了一篇关于HIPHOP的大文章,介绍何时使用它,它的局限性和未来。 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 http://terrychay.com/article/hiphop-for-faster-php.shtml

At that point the run time is inconsequential. 在那时,运行时间是无关紧要的。 HipHop was designed for scaling... meaning billions of requests. HipHop专为扩展而设计......意味着数十亿的请求。 There's absolutely no need to use something like HipHop for even a medium size website. 即使是中等规模的网站,也绝对不需要使用像HipHop这样的东西。

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. 但更多的问题是......我不认为我们可以看到比较图表,但我怀疑在这个级别上运行时间会更快。

i don't know about django or rails, so this is a bit off-topic. 我不知道django或rails,所以这有点偏离主题。

  • with plain php, the request goes to apache, then to mod_php. 用普通的php,请求转到apache,然后转到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. mod_php从磁盘加载helloworld.php脚本,解析并标记它,将其编译为字节码,然后解释字节码,将输出传递回apache,apache将其提供给用户。

  • 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. 使用php和优化器,第一次运行与普通php大致相同,但编译后的源代码存储在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. 然后,对于第二个请求:转到apache,apache转到mod_php,apc从ram加载字节码,解释它,将其传递回apache,返回给用户。

  • 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. 与hiphop没有apache,但hiphop本身并没有解释器,因此请求直接转到hiphop并返回给用户。 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)的质量和静态编译器的质量(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. 与手写的c代码相比,hiphop翻译的代码并不快,因为由于类型处理等原因会产生一些开销。
  • with node.js, there's also no apache. 与node.js一样,也没有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). 脚本启动并直接编译为机器代码(因为V8编译器会这样做),所以它是AOT(提前)编译(或者它仍称为JIT?我真的不知道)。 every request is then directly handled by the already compiled machine code; 然后,每个请求都由已编译的机器代码直接处理; so node.js is actually very comparable to hiphop. 所以node.js实际上与hiphop非常相似。 i assume hiphop to be multithreaded or something like this, while node does evented IO. 我假设hiphop是多线程的或类似的东西,而节点确实使用IO。

facebook claims a 50% speed gain, which is not really that much; facebook声称速度提升了50%,实际上并没有那么多; 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 . 如果你比较语言枪战的结果,你会看到各种算法的执行速度, php慢5到250倍

so why only 50%? 那么为什么只有50%呢? because ... 因为......

  • web apps depend on much more than just execution speed, eg IO Web应用程序不仅仅依赖于执行速度,例如IO
  • php's type system prevents hiphop to make the best use of c++'s static types php的类型系统可以防止hiphop充分利用c ++的静态类型
  • in practice, a lot of php is already C, because most of the functionality is either built in or comes from extensions. 在实践中,很多php已经是C,因为大多数功能都是内置的或来自扩展。 extensions are programmed in C and statically compiled. 扩展名用C编程并静态编译。

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). 我不确定hello world是否有巨大的性能提升,因为即使有一个好的框架,hello world仍然是如此之小,与所有其他开销(网络延迟和内容)相比,执行速度可以忽略不计。

imo: if you want speed and ease of use, go for node.js :) imo:如果你想要速度易用性,请转到node.js :)

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. 当它变得像facebook一样复杂时,你将面临许多问题。 PHP slowness will be show it's face. PHP缓慢将显示它的面貌。 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. 这就是为什么facebook开发人员决定保留旧代码,并使PHP更快。 That's the reason they create their own PHP compiler, called HipHop. 这就是他们创建自己的PHP编译器的原因,称为HipHop。

Read this story from the perspective one of Facebook developer, so you know the history of HipHop. 从Facebook开发人员的角度阅读这个故事 ,让您了解HipHop的历史。

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在apache后面运行
  • Django rendering an HTML template to say hello world (no caching) Django呈现一个HTML模板来表示hello world(没有缓存)

AND

  • HPHP running behind apache HPHP在apache后面运行
  • HPHP rendring an HTML template to say hello world (again, no caching) HPHP渲染HTML模板以表示问候世界(同样,没有缓存)

There is no database, almost no file I/O, and no caching. 没有数据库,几乎没有文件I / O,也没有缓存。 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. 如果你使用不同并发级别的负载生成器点击页面10,000次,你可能会发现HPHP将胜过Django或rails - 也就是说它可以每秒渲染更多页面并且更好地跟上你的流量。

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). HPHP听起来很酷,但恕我直言,没有理由再跳船(除非你获得了大量的流量,在这种情况下检查它可能是有意义的)。

Will it run faster than if I write the same hello world app in django or rails? 它会比我在django或rails中编写相同的hello world应用程序运行得更快吗?

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 ;) 如果我们谈论未发布项目的未来速度改进,Pythonistas有pypy-jitunladen -swallow期待;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM