Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

IPC 2013 - High Performance PHP with HipHop

7,302 views

Published on

A look at Facebook's HipHop for PHP library, both the first generation, HPHPc, and the new HHVM. This presentation walks through the challenges that faced Facebook and their PHP-based solution from a year after their explosive growth in 2007 to late-2013.

Published in: Technology
  • Dating direct: ❶❶❶ http://bit.ly/2u6xbL5 ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Follow the link, new dating source: ❤❤❤ http://bit.ly/2u6xbL5 ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

IPC 2013 - High Performance PHP with HipHop

  1. 1. Steve Kamerman | ScientiaMobile, Inc. Co-Founder / Software Architect High-Performance PHP with HipHop
  2. 2. 2008 - Facebook's Challenge ● Explosive growth ● Need more servers! ● Bottleneck: Page generation ● 20% of PHP time was in native code
  3. 3. Why is PHP so slow? ● Symbol table lookups ● No static binding ● Dynamic typing ● Share-Nothing-Architecture
  4. 4. 2008-2010 – HipHop for PHP is born ● 400 Billion PHP-generated pageviews per month! ● Facebook invents HipHop for PHP ● Deployed system-wide in 2010
  5. 5. HipHop for PHP Research & Development HPHPc HHVM
  6. 6. What is HipHop for PHP? • Multi-threaded web server + PHP runtime • HPHPc: PHP -> C++ translator • HHVM: PHP virtual machine with JIT compiler • Typically 2x – 5x speed increase over stock PHP + APC
  7. 7. HipHop for PHP Compiler (HPHPc) ● Translates PHP code into C++ ● Dynamic typing makes this difficult ● Function parity lacking ● Long compilation time
  8. 8. Our Experience ● Created WURFL Cloud REST API ● Evaluated HPHPc ● Improved Latency ● Stability issues
  9. 9. Architecture Internet HAProxy Load Balancer (primary) WURFL Node HPHPc Apache WURFL Node HPHPc Apache HAProxy Load Balancer (secondary) WURFL Node HPHPc Apache WURFL Node HPHPc Apache Memcached Memcached Memcached Memcached MySQL MySQL MySQL MySQL
  10. 10. Codebase Updates http://www.github.com/kamermans/HAProxyAPI
  11. 11. Next-Gen HipHop: HHVM ● Virtual Machine ● Better PHP Support ● JIT Compiler ● Bytecode Survives Restart
  12. 12. How HHVM works Internet HHV M Web Server Run Native Code Run Bytecode Generate Bytecode JIT Compile
  13. 13. HHVM vs HPHPc Performance http://www.hhvm.com/blog/875/wow-hhvm-is-fast-too-bad-it-doesnt-run-my-code https://github.com/facebook/hhvm/blob/master/hphp/doc/ir.specification
  14. 14. Optimizing PHP for HHVM ● Type Inference – PHP Gotcha: core function fail with (bool)false ● HHVM Upgrades primitives ● Use strict comparison
  15. 15. Don't care about type strict comparison? You should. Trust me. var_export("true" == true); // true   var_export("false" == true); // true   var_export("true" == (bool)"false"); // true var_export(strpos("Steve Kamerman", "Kamerman") == true); // true   var_export(strpos("Steve Kamerman", "Steve") == true); // false   $test = "31 is too old!"; var_export(31 == $test); // true var_export("31.0" == 31); // true var_export("031" == 031); // false var_export(31.0 == 31); // true var_export($test += 1); // 32
  16. 16. Avoid global scope ● ● Code in the global scope is interpreted since it is (nearly) impossible to type-track Even wrapping global code helps: class foo{public static function bar(){ $something = "test"; echo $something; }}foo::bar(); ● Better approach: don’t write crappy code!
  17. 17. Unique Classes, Functions, Constants ● HHVM supports namespaces – use them! ● MyAppBar and MyAppFooBar are not ambiguous ● ● ● Avoid “dynamic” constants: define("MY_CONST", $foo? "foo": "bar"); I can almost picture a feature request for undefine() and redefine() If they are truly constant, use const
  18. 18. Better approach: don't use define() namespace MyApp; class Config { const MY_CONST = "I'm real constant"; private static $storage = array( "PSEUDO_CONSTANT" => "What did you call me?", ); public static function get($name) { if (!array_key_exists($name, self::$storage)) { throw new Exception(__CLASS__." property [$name] does not exist"); } return self::$storage[$name]; } } echo Config::MY_CONST."n";
  19. 19. Avoid dynamic variables ● If you are using this syntax, there is a better way to solve the problem: $foo = "Wow, this hurts my brain!"; $var_name = "foo"; echo $$var_name; ● ● extract() and compact() are sometimes used more legitimately (ex: view rendering), but avoid them If you need get_defined_vars() for non-testing code, you need to rewrite it before someone sees it :)
  20. 20. Declare class properties ● They should be declared anyway $foo = new stdClass(); echo $foo->bar; // PHP Notice: Undefined property ● Getters are optimized
  21. 21. Perfomance Gain ● ● Less than 5%, but still good practice Sub-optimal functions still work, even eval() and goto! http://php.net/manual/en/control-structures.goto.php
  22. 22. Repo.Authoritative Mode ● Pre-Analyze files ● PHP files assumed unchanged ● Delete cache manually
  23. 23. Current state of HipHop ● HHVM v2.2.0 just released ● Very close to PHP 5.4 ● Dozens of extensions ● Performance nearly 5x ● Goal: Support top 20 frameworks in 2013
  24. 24. Framework Support Framework % Unit Tests Pass Framework % Unit Tests Pass Facebook PHP SDK 100 CodeIgniter 81 Paris9 100 Assetic 80 Idiorm9 100 Twig 78 Slim 99 Wordpress 76 Drupal 98 phpBB 0 Composer 97 CakePHP 0 Laravel 95 Joomla 0 yii 92 PHPMyAdmin 0 Symfony 91 zf2 0 PHPUnit2 90 Doctrine 0 Magento 0 http://www.hhvm.com/blog/875/wow-hhvm-is-fast-too-bad-it-doesnt-run-my-code
  25. 25. Why is it open source? Will it last? ● Under PHP license, hard to separate ● Public activity slowed in 2011 ● Under active public development in 2012-13 ● Dev team is active on IRC (freenode #hhvm)
  26. 26. Facebook's Commitment “In years past we've had a few examples of projects which have not been well supported, but we are now much better at growing and sustaining community projects, including, lately, in mobile. [HipHop for PHP] is absolutely a project that we stand strongly behind… stay tuned.” James Pearce, Head of Developer Advocacy at Facebook
  27. 27. References ● ● ● ● ● Special thanks to the HipHop for PHP team! https://www.facebook.com/hphp Twitter: @HipHopVM http://www.hhvm.com/ Sebastian Bergmann – Static Code Analysis with HipHop http://sebastian-bergmann.de/archives/918-Static-Analysis-with-HipHop-for-PHP.html http://www.slideshare.net/nickgsuperstar/static-analysis-for-php https://github.com/sebastianbergmann/hhvm-wrapper Haiping Zhao – HipHop Compiler for PHP? Transforming PHP into C++ http://www.youtube.com/watch?v=p5S1K60mhQU Sara Golemon – Scaling with HipHop http://www.youtube.com/watch?v=Dwek7dZDFN0 Ben Foster – Facebook Growth Data http://www.benphoster.com/facebook-user-growth-chart-2004-2010/

×