SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Agenda
 Introduction
 What is HipHop VM ?
 History and why it exists
 Architecture and Features
 General Architecture
 Code cache
 JIT
 Garbage Collector
 AdminServer
 FastCGI
 Extensions
 HHVM-friendly PHP code
 Parity
What is HipHop VM ?
 High-Level Stack-Based virtual machine that executes

PHP code
 Created by Facebook in a (successful) attempt to reduce
load on their servers
 New versions are released every 8 weeks on Thursday. 10
days before a release, the branch is cut and heavily tested.
History of HHVM (I)
 Summer 2007: Facebook started developing

HPHPc, an PHP to C++ translator.
 It worked by:
 Building an AST based on the PHP code
 Based on that AST, equivalent C++ code was generated

 The C++ code was compiled to binary using g++
 The binary was uploaded to the webservers where it

was executed

 This resulted in significant performance

improvements, up to 500% in some cases compared
to PHP 5.2
History of HHVM (II)
 The succes of HPHPc was so great, that the engineers decided

to give it a developer-friendly brother: HPHPi
 HPHPi was just like HPHPc but it ran in interpreted mode only
(a.k.a. much slower)
 However, it provided a lot of utilities for developers:
 Debugger (known as HPHPd)
 Setting watches, breakpoints
 Static code analysis
 Performance profiling

 It also didn’t require the compilation step to run the code
 HPHPc ran over 90 % of FB production code by the end of 2009
 HPHPc was open-sourced on February 2010
History of HHVM (III)
 But good performance came at a cost:
 Static compilation was very cumbersome
 The binary had 1 GB which was a problem since production code had
to be pushed to the servers DAILY
 Maintaining compatibility between HPHPc and HPHPi was getting
more and more difficult (they used different formats for their ASTs)
 So, at the beginning of 2010, FB started developing HHVM, which

was a better, longer-term solution
 At first, HHVM replaced only HPHPi, while HPHPc remained in
production
 But now, all FBs production servers are run by HHVM
 FB claims a 3x to 10x speed boost and 0.5x – 5x memory reduction
compared to PHP + APC. This, of course, is on their own
code, most applications will have a more modest improvement
General Architecture (I)
 General architecture is made up of:
 2 webservers
 A translator
 A JIT compiler
 A Garbage Collector
 HHVM doesn’t support any OS:
 It supports most flavours of Linux
 It has some support for Mac OS X (only runs with JIT turned off )
 There is no Windows support
 The OS must have a 64-bit architecture in order for HHVM to
work
General Architecture (II)
 The HHVM will follow the following steps to execute a PHP

script:
 Based on PHP code, build an AST (implementation for this was






reused from HPHPc)
Based on the AST, build Hip Hop Bytecode (HHBC), similar to
Java’s or CLR’s bytecode
Cache the HHBC
At runtime, pass the HHBC through the JIT compliler (if
enabled) which will transform it to machine code
Execute the machine code or, if JIT is disabled, execute the
HHBC in interpreted mode (not as fast, but still faster than Zend
PHP)
Code Cache (I)
 When request comes in, HHVM determines which file to

serve up, then checks if the file’s HHBC is in SQLite-based
cache
 If yes, it’s executed
 If no, HHVM compiles it, optimizes it and stores it in cache

 This is very similar to APC
 There’s a warm-up period when new server is

created, because cache is empty
 However, HHVM’s cache lives on disk, so it survives server
restarts and there will be no more warm-up periods for that
file
Code Cache (II)
 But warm-up period can be bypassed by doing pre-analysis

 Pre-analysis means the cache can be generated before

HHVM starts-up
 Pre-analyser will actually work a little harder and will do a
better job at optimizing code
Code Cache (III)
 There is a mode called RepoAuthoritative mode

 HHVM will check at each request if the PHP file changed in

order to know if cache must be updated
 RepoAuthoritative mode means this check is not
performed anymore.
 But be careful because, if the file is not in cache, you’ll get a
HTTP 404 error, even though the PHP file is right there
 RepoAuthoritative is recommended for production because
it avoides a lot of disk IO and files change rarely anyway
JIT Compiler
 Just-in-Time compilation is done during execution, not

before
 It translates an intermediate form of code (in this case
HHBC) to machine code
 A JIT compiler will constantly check to see which paths of
code are executed more frequently and try to optimize
those as best as possible
 Since a JIT compiler will compile to machine code at
runtime, the resulting machine code will be optimized for
that platform or CPU, which will sometimes make it faster
than even static compilation
JIT Compiler (II)
 HHVM uses so called tracelets as basic unit block of JIT
 A tracelet is usually a loop because most programs spend

most of their time in some “hot loops” and subsequent
iterations of those loops take similar paths
 A tracelet has 3 parts:
 Type guard(s): prevents execution for incompatible types
 Body
 Link to subsequent tracelet(s)

 Each tracelet has great freedom, but it is required to restore

the VM to a consistent state any time execution escapes
 Tracelets have only ONE execution path, which means no
control flow, which they’re easy to optimize
Garbage Collector
 Most modern languages have automatic memory

management
 In the case of VMs, this is called Garbage Collector
 There are 2 major types of GCs:
 Refcounting: for each object, there is a count that constantly

keeps track of how many references point to it
 Tracing: periodically, during execution, the GC scans each
object and determines if it’s reachable. If not, it deletes it

 Tracing is easier to implement and more efficient, but PHP

requires refcounting, so HHVM uses refcounting
 FB engineers want to move to a tracing approach and they
might get it done someday
AdminServer
 HHVM will actually start 2 webservers:
 Regular one on port 80
 AdminServer on the port you specify
 It can be accessed at an URI like

http://localhost:9191/check-health?auth=mypasshaha
 The AdminServer can turn JIT on/off, show statistics about
traffic, queries, memcache, CPU load, number of active
threads and many more
FastCGI
 HHVM supports FastCGI starting with version 2.3.0

(released in December 2013)
 FastCGI is a communication protocol used by webservers to
communicate with other applications
 The support for FastCGI means we don’t have to use
HHVM’s poor webserver, but instead use something like
Apache or nginx and let HHVM do what it does best:
execute PHP code at lightning speed
 Supporting FastCGI will make HHVM enter even more
production systems and increase its popularity
Extensions
 HHVM supports extensions just like PHP does

 They can be written in PHP, C++ or a combination of the 2
 Extensions will be loaded at each request, you don’t have to

keep loading an extension all over your applications
 To use custom extensions, you add it to the extensions and
then recompile HHVM. The resulting binary will contain
your extension and you can then use it
 By default, HHVM already contains the most popular
extensions, like
MySQL, PDO, DOM, cURL, PHAR, SimpleXML, JSON, me
mcache and many others
 Though, it doesn’t include MySQLi at this time
HHVM-friendly Code (I)
 Write code that HHVM can understand without

running, code that contains as much static detail as
possible
 Avoid things like:
 Dynamic function call: $function_name()
 Dynamic variable name: $a = $$x + 1;
 Functions like compact(), get_defined_vars(), extract() etc
 Don't access dynamic properties of an object. If you want to

access it, declare it. Accessing dynamic properties must use
hashtable lookups, which are much slower.

 Where possible, provide:
 Type hinting in function parameters
 Return type of functions should be as obvious as possible:
HHVM-friendly Code (II)
 Code that runs in global scope is never JIT-ed.
 Any code anywhere can mutate the variables in the global scope.

So, since PHP is weak-typed, it makes it impossible for the JIT
compiler to predict a variable’s type
 Example:
 class B {

public function __toString() {

$GLOBALS['a'] = 'Hello, world !';
 }
 }
 $a = 5;
 $b = new B;
 echo $b;

Parity (I)
 All this is great, but can HHVM actually run real-world code ? Well, in

December 2013, it looked like this (taken from HHVM blog):
Parity (II)
 HHVM’s engineers main goal is to be able to run all PHP

frameworks by Q4 2014 or Q1 2015.
Q&A
HipHop Virtual Machine

Weitere ähnliche Inhalte

Was ist angesagt?

2021.laravelconf.tw.slides5
2021.laravelconf.tw.slides52021.laravelconf.tw.slides5
2021.laravelconf.tw.slides5LiviaLiaoFontech
 
Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011leo lapworth
 
Agile\scrum: все что необходимо знать
Agile\scrum: все что необходимо знатьAgile\scrum: все что необходимо знать
Agile\scrum: все что необходимо знатьYuri Navruzov
 
From Generator to Fiber the Road to Coroutine in PHP
From Generator to Fiber the Road to Coroutine in PHPFrom Generator to Fiber the Road to Coroutine in PHP
From Generator to Fiber the Road to Coroutine in PHPAlbert Chen
 
Apache Airflow Introduction
Apache Airflow IntroductionApache Airflow Introduction
Apache Airflow IntroductionLiangjun Jiang
 
Improved alerting with Prometheus and Alertmanager
Improved alerting with Prometheus and AlertmanagerImproved alerting with Prometheus and Alertmanager
Improved alerting with Prometheus and AlertmanagerJulien Pivotto
 
Streaming with Spring Cloud Stream and Apache Kafka - Soby Chacko
Streaming with Spring Cloud Stream and Apache Kafka - Soby ChackoStreaming with Spring Cloud Stream and Apache Kafka - Soby Chacko
Streaming with Spring Cloud Stream and Apache Kafka - Soby ChackoVMware Tanzu
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기JeongHun Byeon
 
Cassandra Backups and Restorations Using Ansible (Joshua Wickman, Knewton) | ...
Cassandra Backups and Restorations Using Ansible (Joshua Wickman, Knewton) | ...Cassandra Backups and Restorations Using Ansible (Joshua Wickman, Knewton) | ...
Cassandra Backups and Restorations Using Ansible (Joshua Wickman, Knewton) | ...DataStax
 
Oracle WebLogic Server: Remote Monitoring and Management
Oracle WebLogic Server: Remote Monitoring and ManagementOracle WebLogic Server: Remote Monitoring and Management
Oracle WebLogic Server: Remote Monitoring and ManagementRevelation Technologies
 
OpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-SideOpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-SideTim Burks
 
FIWARE Real-Time Media Stream processing using Kurento
FIWARE Real-Time Media Stream processing using KurentoFIWARE Real-Time Media Stream processing using Kurento
FIWARE Real-Time Media Stream processing using Kurentofisuda
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Mario Cardinal
 
What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0
What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0
What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0NGINX, Inc.
 
Understanding Apache Kafka® Latency at Scale
Understanding Apache Kafka® Latency at ScaleUnderstanding Apache Kafka® Latency at Scale
Understanding Apache Kafka® Latency at Scaleconfluent
 
Low latency microservices in java QCon New York 2016
Low latency microservices in java   QCon New York 2016Low latency microservices in java   QCon New York 2016
Low latency microservices in java QCon New York 2016Peter Lawrey
 

Was ist angesagt? (16)

2021.laravelconf.tw.slides5
2021.laravelconf.tw.slides52021.laravelconf.tw.slides5
2021.laravelconf.tw.slides5
 
Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011
 
Agile\scrum: все что необходимо знать
Agile\scrum: все что необходимо знатьAgile\scrum: все что необходимо знать
Agile\scrum: все что необходимо знать
 
From Generator to Fiber the Road to Coroutine in PHP
From Generator to Fiber the Road to Coroutine in PHPFrom Generator to Fiber the Road to Coroutine in PHP
From Generator to Fiber the Road to Coroutine in PHP
 
Apache Airflow Introduction
Apache Airflow IntroductionApache Airflow Introduction
Apache Airflow Introduction
 
Improved alerting with Prometheus and Alertmanager
Improved alerting with Prometheus and AlertmanagerImproved alerting with Prometheus and Alertmanager
Improved alerting with Prometheus and Alertmanager
 
Streaming with Spring Cloud Stream and Apache Kafka - Soby Chacko
Streaming with Spring Cloud Stream and Apache Kafka - Soby ChackoStreaming with Spring Cloud Stream and Apache Kafka - Soby Chacko
Streaming with Spring Cloud Stream and Apache Kafka - Soby Chacko
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기
 
Cassandra Backups and Restorations Using Ansible (Joshua Wickman, Knewton) | ...
Cassandra Backups and Restorations Using Ansible (Joshua Wickman, Knewton) | ...Cassandra Backups and Restorations Using Ansible (Joshua Wickman, Knewton) | ...
Cassandra Backups and Restorations Using Ansible (Joshua Wickman, Knewton) | ...
 
Oracle WebLogic Server: Remote Monitoring and Management
Oracle WebLogic Server: Remote Monitoring and ManagementOracle WebLogic Server: Remote Monitoring and Management
Oracle WebLogic Server: Remote Monitoring and Management
 
OpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-SideOpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-Side
 
FIWARE Real-Time Media Stream processing using Kurento
FIWARE Real-Time Media Stream processing using KurentoFIWARE Real-Time Media Stream processing using Kurento
FIWARE Real-Time Media Stream processing using Kurento
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0
What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0
What’s New in NGINX Ingress Controller for Kubernetes Release 1.5.0
 
Understanding Apache Kafka® Latency at Scale
Understanding Apache Kafka® Latency at ScaleUnderstanding Apache Kafka® Latency at Scale
Understanding Apache Kafka® Latency at Scale
 
Low latency microservices in java QCon New York 2016
Low latency microservices in java   QCon New York 2016Low latency microservices in java   QCon New York 2016
Low latency microservices in java QCon New York 2016
 

Andere mochten auch

Tango argentino
Tango argentinoTango argentino
Tango argentinosarapaol
 
Path To Prosperity Small To Midsize Companies
Path To Prosperity Small To Midsize CompaniesPath To Prosperity Small To Midsize Companies
Path To Prosperity Small To Midsize Companiesstephej2
 
Menkes bp dr ricca fauziyah
Menkes bp dr ricca fauziyahMenkes bp dr ricca fauziyah
Menkes bp dr ricca fauziyahSufya Anwar
 
Data Portfolio 06 01 2011 No Contact
Data Portfolio 06 01 2011 No ContactData Portfolio 06 01 2011 No Contact
Data Portfolio 06 01 2011 No Contactjdmassman
 
Nasco Mosaic Tile Collection
Nasco Mosaic Tile CollectionNasco Mosaic Tile Collection
Nasco Mosaic Tile Collectionablonski
 
Menejemen Kesehatan Balai Pengbatan dr. Ricca Fauziyah
Menejemen Kesehatan Balai Pengbatan dr. Ricca FauziyahMenejemen Kesehatan Balai Pengbatan dr. Ricca Fauziyah
Menejemen Kesehatan Balai Pengbatan dr. Ricca FauziyahSufya Anwar
 
Collaborative Filtering Survey
Collaborative Filtering SurveyCollaborative Filtering Survey
Collaborative Filtering Surveymobilizer1000
 
101202 firmenpräsi druckversion_e_low
101202 firmenpräsi druckversion_e_low101202 firmenpräsi druckversion_e_low
101202 firmenpräsi druckversion_e_lowaevanamerongen
 
Weather17th 20th
Weather17th 20thWeather17th 20th
Weather17th 20thamykay16
 
gooスマホ部について0707
gooスマホ部について0707gooスマホ部について0707
gooスマホ部について0707Tadayoshi Senda
 
Data Portfolio 06 21 2011 Nocontact
Data Portfolio 06 21 2011 NocontactData Portfolio 06 21 2011 Nocontact
Data Portfolio 06 21 2011 Nocontactjdmassman
 
Estado da Arte HTML5
Estado da Arte HTML5Estado da Arte HTML5
Estado da Arte HTML5MCM-IPG
 
Menkes simpus dr. nila
Menkes simpus dr. nilaMenkes simpus dr. nila
Menkes simpus dr. nilaSufya Anwar
 
Dossier sobre Assamblearisme Infantil
 Dossier sobre Assamblearisme Infantil Dossier sobre Assamblearisme Infantil
Dossier sobre Assamblearisme InfantilEl Senyor Croqueta
 

Andere mochten auch (20)

Tango argentino
Tango argentinoTango argentino
Tango argentino
 
Path To Prosperity Small To Midsize Companies
Path To Prosperity Small To Midsize CompaniesPath To Prosperity Small To Midsize Companies
Path To Prosperity Small To Midsize Companies
 
Menkes bp dr ricca fauziyah
Menkes bp dr ricca fauziyahMenkes bp dr ricca fauziyah
Menkes bp dr ricca fauziyah
 
Data Portfolio 06 01 2011 No Contact
Data Portfolio 06 01 2011 No ContactData Portfolio 06 01 2011 No Contact
Data Portfolio 06 01 2011 No Contact
 
Stop motion
Stop motionStop motion
Stop motion
 
Nasco Mosaic Tile Collection
Nasco Mosaic Tile CollectionNasco Mosaic Tile Collection
Nasco Mosaic Tile Collection
 
Menejemen Kesehatan Balai Pengbatan dr. Ricca Fauziyah
Menejemen Kesehatan Balai Pengbatan dr. Ricca FauziyahMenejemen Kesehatan Balai Pengbatan dr. Ricca Fauziyah
Menejemen Kesehatan Balai Pengbatan dr. Ricca Fauziyah
 
Collaborative Filtering Survey
Collaborative Filtering SurveyCollaborative Filtering Survey
Collaborative Filtering Survey
 
The Competitive Advantage in the Changing Digital Landscape
The Competitive Advantage in the Changing Digital Landscape The Competitive Advantage in the Changing Digital Landscape
The Competitive Advantage in the Changing Digital Landscape
 
101202 firmenpräsi druckversion_e_low
101202 firmenpräsi druckversion_e_low101202 firmenpräsi druckversion_e_low
101202 firmenpräsi druckversion_e_low
 
Responsabilidad
ResponsabilidadResponsabilidad
Responsabilidad
 
Weather17th 20th
Weather17th 20thWeather17th 20th
Weather17th 20th
 
gooスマホ部について0707
gooスマホ部について0707gooスマホ部について0707
gooスマホ部について0707
 
Data Portfolio 06 21 2011 Nocontact
Data Portfolio 06 21 2011 NocontactData Portfolio 06 21 2011 Nocontact
Data Portfolio 06 21 2011 Nocontact
 
Zendesk PRO Tips
Zendesk PRO TipsZendesk PRO Tips
Zendesk PRO Tips
 
Estado da Arte HTML5
Estado da Arte HTML5Estado da Arte HTML5
Estado da Arte HTML5
 
Building your Personal Brand
Building your Personal BrandBuilding your Personal Brand
Building your Personal Brand
 
Menkes simpus dr. nila
Menkes simpus dr. nilaMenkes simpus dr. nila
Menkes simpus dr. nila
 
Dossier sobre Assamblearisme Infantil
 Dossier sobre Assamblearisme Infantil Dossier sobre Assamblearisme Infantil
Dossier sobre Assamblearisme Infantil
 
Offshorent executive overview
Offshorent executive overviewOffshorent executive overview
Offshorent executive overview
 

Ähnlich wie HipHop Virtual Machine

Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerJackson F. de A. Mafra
 
PHP and FastCGI Performance Optimizations
PHP and FastCGI Performance OptimizationsPHP and FastCGI Performance Optimizations
PHP and FastCGI Performance OptimizationsAlessandro Pilotti
 
Introduction to OpenHFT for Melbourne Java Users Group
Introduction to OpenHFT for Melbourne Java Users GroupIntroduction to OpenHFT for Melbourne Java Users Group
Introduction to OpenHFT for Melbourne Java Users GroupPeter Lawrey
 
Media Content Delivery Systems
Media Content Delivery SystemsMedia Content Delivery Systems
Media Content Delivery Systemsashbyb
 
Magento on HHVM. Daniel Sloof
Magento on HHVM. Daniel SloofMagento on HHVM. Daniel Sloof
Magento on HHVM. Daniel SloofMeetMagentoNY2014
 
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010 Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010 Matt Gauger
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesRobert Lemke
 
Load Balancing with HAproxy
Load Balancing with HAproxyLoad Balancing with HAproxy
Load Balancing with HAproxyBrendan Jennings
 
Ch 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet ServersCh 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet Serverswebhostingguy
 
Developing high-performance network servers in Lisp
Developing high-performance network servers in LispDeveloping high-performance network servers in Lisp
Developing high-performance network servers in LispVladimir Sedach
 
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...Ontico
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet backdoor
 

Ähnlich wie HipHop Virtual Machine (20)

Hack and HHVM
Hack and HHVMHack and HHVM
Hack and HHVM
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
 
How PHP works
How PHP works How PHP works
How PHP works
 
Daniel Sloof: Magento on HHVM
Daniel Sloof: Magento on HHVMDaniel Sloof: Magento on HHVM
Daniel Sloof: Magento on HHVM
 
PHP and FastCGI Performance Optimizations
PHP and FastCGI Performance OptimizationsPHP and FastCGI Performance Optimizations
PHP and FastCGI Performance Optimizations
 
Introduction to OpenHFT for Melbourne Java Users Group
Introduction to OpenHFT for Melbourne Java Users GroupIntroduction to OpenHFT for Melbourne Java Users Group
Introduction to OpenHFT for Melbourne Java Users Group
 
Media Content Delivery Systems
Media Content Delivery SystemsMedia Content Delivery Systems
Media Content Delivery Systems
 
Magento on HHVM. Daniel Sloof
Magento on HHVM. Daniel SloofMagento on HHVM. Daniel Sloof
Magento on HHVM. Daniel Sloof
 
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010 Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in Kubernetes
 
Load Balancing with HAproxy
Load Balancing with HAproxyLoad Balancing with HAproxy
Load Balancing with HAproxy
 
Rit 2011 ats
Rit 2011 atsRit 2011 ats
Rit 2011 ats
 
Ch 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet ServersCh 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet Servers
 
Developing high-performance network servers in Lisp
Developing high-performance network servers in LispDeveloping high-performance network servers in Lisp
Developing high-performance network servers in Lisp
 
NodeJS
NodeJSNodeJS
NodeJS
 
Apache web server
Apache web serverApache web server
Apache web server
 
slides (PPT)
slides (PPT)slides (PPT)
slides (PPT)
 
2016 03 15_biological_databases_part4
2016 03 15_biological_databases_part42016 03 15_biological_databases_part4
2016 03 15_biological_databases_part4
 
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 

Mehr von Radu Murzea

The World of StackOverflow
The World of StackOverflowThe World of StackOverflow
The World of StackOverflowRadu Murzea
 
SymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developersSymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developersRadu Murzea
 
The World of PHP PSR Standards
The World of PHP PSR StandardsThe World of PHP PSR Standards
The World of PHP PSR StandardsRadu Murzea
 
PHP 7 - A look at the future
PHP 7 - A look at the futurePHP 7 - A look at the future
PHP 7 - A look at the futureRadu Murzea
 
Hack programming language
Hack programming languageHack programming language
Hack programming languageRadu Murzea
 
Hack Programming Language
Hack Programming LanguageHack Programming Language
Hack Programming LanguageRadu Murzea
 
Unit Testing in PHP
Unit Testing in PHPUnit Testing in PHP
Unit Testing in PHPRadu Murzea
 

Mehr von Radu Murzea (7)

The World of StackOverflow
The World of StackOverflowThe World of StackOverflow
The World of StackOverflow
 
SymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developersSymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developers
 
The World of PHP PSR Standards
The World of PHP PSR StandardsThe World of PHP PSR Standards
The World of PHP PSR Standards
 
PHP 7 - A look at the future
PHP 7 - A look at the futurePHP 7 - A look at the future
PHP 7 - A look at the future
 
Hack programming language
Hack programming languageHack programming language
Hack programming language
 
Hack Programming Language
Hack Programming LanguageHack Programming Language
Hack Programming Language
 
Unit Testing in PHP
Unit Testing in PHPUnit Testing in PHP
Unit Testing in PHP
 

Kürzlich hochgeladen

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

HipHop Virtual Machine

  • 1.
  • 2. Agenda  Introduction  What is HipHop VM ?  History and why it exists  Architecture and Features  General Architecture  Code cache  JIT  Garbage Collector  AdminServer  FastCGI  Extensions  HHVM-friendly PHP code  Parity
  • 3. What is HipHop VM ?  High-Level Stack-Based virtual machine that executes PHP code  Created by Facebook in a (successful) attempt to reduce load on their servers  New versions are released every 8 weeks on Thursday. 10 days before a release, the branch is cut and heavily tested.
  • 4. History of HHVM (I)  Summer 2007: Facebook started developing HPHPc, an PHP to C++ translator.  It worked by:  Building an AST based on the PHP code  Based on that AST, equivalent C++ code was generated  The C++ code was compiled to binary using g++  The binary was uploaded to the webservers where it was executed  This resulted in significant performance improvements, up to 500% in some cases compared to PHP 5.2
  • 5. History of HHVM (II)  The succes of HPHPc was so great, that the engineers decided to give it a developer-friendly brother: HPHPi  HPHPi was just like HPHPc but it ran in interpreted mode only (a.k.a. much slower)  However, it provided a lot of utilities for developers:  Debugger (known as HPHPd)  Setting watches, breakpoints  Static code analysis  Performance profiling  It also didn’t require the compilation step to run the code  HPHPc ran over 90 % of FB production code by the end of 2009  HPHPc was open-sourced on February 2010
  • 6. History of HHVM (III)  But good performance came at a cost:  Static compilation was very cumbersome  The binary had 1 GB which was a problem since production code had to be pushed to the servers DAILY  Maintaining compatibility between HPHPc and HPHPi was getting more and more difficult (they used different formats for their ASTs)  So, at the beginning of 2010, FB started developing HHVM, which was a better, longer-term solution  At first, HHVM replaced only HPHPi, while HPHPc remained in production  But now, all FBs production servers are run by HHVM  FB claims a 3x to 10x speed boost and 0.5x – 5x memory reduction compared to PHP + APC. This, of course, is on their own code, most applications will have a more modest improvement
  • 7. General Architecture (I)  General architecture is made up of:  2 webservers  A translator  A JIT compiler  A Garbage Collector  HHVM doesn’t support any OS:  It supports most flavours of Linux  It has some support for Mac OS X (only runs with JIT turned off )  There is no Windows support  The OS must have a 64-bit architecture in order for HHVM to work
  • 8. General Architecture (II)  The HHVM will follow the following steps to execute a PHP script:  Based on PHP code, build an AST (implementation for this was     reused from HPHPc) Based on the AST, build Hip Hop Bytecode (HHBC), similar to Java’s or CLR’s bytecode Cache the HHBC At runtime, pass the HHBC through the JIT compliler (if enabled) which will transform it to machine code Execute the machine code or, if JIT is disabled, execute the HHBC in interpreted mode (not as fast, but still faster than Zend PHP)
  • 9. Code Cache (I)  When request comes in, HHVM determines which file to serve up, then checks if the file’s HHBC is in SQLite-based cache  If yes, it’s executed  If no, HHVM compiles it, optimizes it and stores it in cache  This is very similar to APC  There’s a warm-up period when new server is created, because cache is empty  However, HHVM’s cache lives on disk, so it survives server restarts and there will be no more warm-up periods for that file
  • 10. Code Cache (II)  But warm-up period can be bypassed by doing pre-analysis  Pre-analysis means the cache can be generated before HHVM starts-up  Pre-analyser will actually work a little harder and will do a better job at optimizing code
  • 11. Code Cache (III)  There is a mode called RepoAuthoritative mode  HHVM will check at each request if the PHP file changed in order to know if cache must be updated  RepoAuthoritative mode means this check is not performed anymore.  But be careful because, if the file is not in cache, you’ll get a HTTP 404 error, even though the PHP file is right there  RepoAuthoritative is recommended for production because it avoides a lot of disk IO and files change rarely anyway
  • 12. JIT Compiler  Just-in-Time compilation is done during execution, not before  It translates an intermediate form of code (in this case HHBC) to machine code  A JIT compiler will constantly check to see which paths of code are executed more frequently and try to optimize those as best as possible  Since a JIT compiler will compile to machine code at runtime, the resulting machine code will be optimized for that platform or CPU, which will sometimes make it faster than even static compilation
  • 13. JIT Compiler (II)  HHVM uses so called tracelets as basic unit block of JIT  A tracelet is usually a loop because most programs spend most of their time in some “hot loops” and subsequent iterations of those loops take similar paths  A tracelet has 3 parts:  Type guard(s): prevents execution for incompatible types  Body  Link to subsequent tracelet(s)  Each tracelet has great freedom, but it is required to restore the VM to a consistent state any time execution escapes  Tracelets have only ONE execution path, which means no control flow, which they’re easy to optimize
  • 14. Garbage Collector  Most modern languages have automatic memory management  In the case of VMs, this is called Garbage Collector  There are 2 major types of GCs:  Refcounting: for each object, there is a count that constantly keeps track of how many references point to it  Tracing: periodically, during execution, the GC scans each object and determines if it’s reachable. If not, it deletes it  Tracing is easier to implement and more efficient, but PHP requires refcounting, so HHVM uses refcounting  FB engineers want to move to a tracing approach and they might get it done someday
  • 15. AdminServer  HHVM will actually start 2 webservers:  Regular one on port 80  AdminServer on the port you specify  It can be accessed at an URI like http://localhost:9191/check-health?auth=mypasshaha  The AdminServer can turn JIT on/off, show statistics about traffic, queries, memcache, CPU load, number of active threads and many more
  • 16. FastCGI  HHVM supports FastCGI starting with version 2.3.0 (released in December 2013)  FastCGI is a communication protocol used by webservers to communicate with other applications  The support for FastCGI means we don’t have to use HHVM’s poor webserver, but instead use something like Apache or nginx and let HHVM do what it does best: execute PHP code at lightning speed  Supporting FastCGI will make HHVM enter even more production systems and increase its popularity
  • 17. Extensions  HHVM supports extensions just like PHP does  They can be written in PHP, C++ or a combination of the 2  Extensions will be loaded at each request, you don’t have to keep loading an extension all over your applications  To use custom extensions, you add it to the extensions and then recompile HHVM. The resulting binary will contain your extension and you can then use it  By default, HHVM already contains the most popular extensions, like MySQL, PDO, DOM, cURL, PHAR, SimpleXML, JSON, me mcache and many others  Though, it doesn’t include MySQLi at this time
  • 18. HHVM-friendly Code (I)  Write code that HHVM can understand without running, code that contains as much static detail as possible  Avoid things like:  Dynamic function call: $function_name()  Dynamic variable name: $a = $$x + 1;  Functions like compact(), get_defined_vars(), extract() etc  Don't access dynamic properties of an object. If you want to access it, declare it. Accessing dynamic properties must use hashtable lookups, which are much slower.  Where possible, provide:  Type hinting in function parameters  Return type of functions should be as obvious as possible:
  • 19. HHVM-friendly Code (II)  Code that runs in global scope is never JIT-ed.  Any code anywhere can mutate the variables in the global scope. So, since PHP is weak-typed, it makes it impossible for the JIT compiler to predict a variable’s type  Example:  class B { public function __toString() {  $GLOBALS['a'] = 'Hello, world !';  }  }  $a = 5;  $b = new B;  echo $b; 
  • 20. Parity (I)  All this is great, but can HHVM actually run real-world code ? Well, in December 2013, it looked like this (taken from HHVM blog):
  • 21. Parity (II)  HHVM’s engineers main goal is to be able to run all PHP frameworks by Q4 2014 or Q1 2015.
  • 22. Q&A

Hinweis der Redaktion

  1. Alteratives: simpletest, behat
  2. Alteratives: simpletest, behat
  3. Alteratives: simpletest, behat
  4. Alteratives: simpletest, behat
  5. Alteratives: simpletest, behat
  6. Alteratives: simpletest, behat
  7. Alteratives: simpletest, behat