SlideShare a Scribd company logo
1 of 20
18/12/2010


Speed up ZingMe-NTVV2 with
PHP extension module




                     By Nguyen Trung Thanh
                        ZingMe Team leader
                       Web Technical - VNG
Contents

Introduction
Why?
PHP extension basic
SWIG
Sample
INTRODUCTION - ntvv2
Introduction

• Ntvv2 (http://me.zing.vn/apps/ntvv2)
  – 1.M daily active user
  – Average 800 rps (per webserver) max 1100
    rps
  – 9300 rps (all database servers)
  – 3 webservers
• Use Membase for cache and storage
• Use other db for secondary storage
• All bussiness function is moved to PHP
  extension
Why to write PHP module?
Make complicated Bussiness functions run
 faster, consume less memory

PHP high-level overhead cpu/mem

Advance facility with PHP-FPM
    Cache something in PHP process


Strictly Confidential – Do Not Distribute
PHP extension basic

What is an extension?

Lifecycle

Setting up a build environment
http://devzone.zend.com/article/4486
http://devzone.zend.com/article/1021-Extension-Writing-Part-I-
   Introduction-to-PHP-and-Zend
What is an extension?

Have you ever used PHP extension?

PHP consist of many extensions

All function we used is from extensions
Lifecycle
Setting up build environment

- Setup PHP-devel
- Sample extension
Is it complicated?


●
 Is there any sexier and easier way?
●
 We can use SWIG
SWIG
SWIG is an interface compiler that connects
  programs written in C and C++ with
  scripting languages such as PHP, Python,
  Ruby...
How SWIG works
Using SWIG
Install module to PHP extensions
Sample


Strictly Confidential – Do Not Distribute
How SWIG works
What does SWIG do for you ?

Namespace
Constants
Type conversion
  For simple types (int, float, char *, enum)
Wraps complex types
  Pointers to structs and classes
Exposes functions
Using SWIG

Defile module in swig file
Generate source code
Create module project, build it
Define module

Data type
Wrapper class/functions
                                            %module ntvv2module
                                            %{
                                            #include <string>
                                            #include <vector>
                                            #include <list>
                                            #include <string>
                                            #include “ntvvgame.h"
                                            %}
                                            struct LandInfo{
                                               int id;
                                               std::string data;
                                            }            ;
Strictly Confidential – Do Not Distribute   LandInfo updateLandInfo(int uid, int landID);
Exposure


•Swig recognizes C/C++ declarations
'struct' or 'class'
functions
•Hiding elements
%ignore solver::noupdate;
%include “satsolver/solver.h”
Useful commands
•Renaming
%rename("to_s") asString();
%rename( "name=" ) set_name( const char *name );
%rename("empty?") empty();
•Aliasing
%alias get "[]";
•Constants
%constant int Script = C_CONSTANT;
•Defines
%define YUILogComponent "bindings"
%enddef
%define %macro(PARAMETER)
SWIG steps

Generate code

Create project, compiling
    – Add genterated code to project
Running
    – Add extension module to PHP
Sample

Cache data in PHP module




Strictly Confidential – Do Not Distribute
Q&A

More Related Content

Viewers also liked

how startups can benefit from launch community
how startups can benefit from launch communityhow startups can benefit from launch community
how startups can benefit from launch community
hazzaz
 
EAV in Magento
EAV in MagentoEAV in Magento
EAV in Magento
hazzaz
 
build your own php extension
build your own php extensionbuild your own php extension
build your own php extension
hazzaz
 
social network game
social network gamesocial network game
social network game
hazzaz
 
dangminhtuan-htmlcssjavascript
dangminhtuan-htmlcssjavascriptdangminhtuan-htmlcssjavascript
dangminhtuan-htmlcssjavascript
hazzaz
 
zingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphpzingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphp
hazzaz
 

Viewers also liked (8)

Hurricanes and social media are similar
Hurricanes and social media are similarHurricanes and social media are similar
Hurricanes and social media are similar
 
how startups can benefit from launch community
how startups can benefit from launch communityhow startups can benefit from launch community
how startups can benefit from launch community
 
EAV in Magento
EAV in MagentoEAV in Magento
EAV in Magento
 
build your own php extension
build your own php extensionbuild your own php extension
build your own php extension
 
social network game
social network gamesocial network game
social network game
 
Zing
ZingZing
Zing
 
dangminhtuan-htmlcssjavascript
dangminhtuan-htmlcssjavascriptdangminhtuan-htmlcssjavascript
dangminhtuan-htmlcssjavascript
 
zingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphpzingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphp
 

Similar to speed up ntvv2 by php ext module

Taming Deployment With Smart Frog
Taming Deployment With Smart FrogTaming Deployment With Smart Frog
Taming Deployment With Smart Frog
Steve Loughran
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
Fabien Potencier
 
Swift profiling middleware and tools
Swift profiling middleware and toolsSwift profiling middleware and tools
Swift profiling middleware and tools
zhang hua
 
June 2014 PDX PUG: Writing and Publishing Puppet Modules
June 2014 PDX PUG: Writing and Publishing Puppet Modules June 2014 PDX PUG: Writing and Publishing Puppet Modules
June 2014 PDX PUG: Writing and Publishing Puppet Modules
Puppet
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
Maurizio Pelizzone
 

Similar to speed up ntvv2 by php ext module (20)

GWT MVP Case Study
GWT MVP Case StudyGWT MVP Case Study
GWT MVP Case Study
 
Node.js for enterprise - JS Conference
Node.js for enterprise - JS ConferenceNode.js for enterprise - JS Conference
Node.js for enterprise - JS Conference
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Taming Deployment With Smart Frog
Taming Deployment With Smart FrogTaming Deployment With Smart Frog
Taming Deployment With Smart Frog
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Swift profiling middleware and tools
Swift profiling middleware and toolsSwift profiling middleware and tools
Swift profiling middleware and tools
 
SOA with C, C++, PHP and more
SOA with C, C++, PHP and moreSOA with C, C++, PHP and more
SOA with C, C++, PHP and more
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
 
Secure Programming
Secure ProgrammingSecure Programming
Secure Programming
 
Portland Puppet User Group June 2014: Writing and publishing puppet modules
Portland Puppet User Group June 2014: Writing and publishing puppet modulesPortland Puppet User Group June 2014: Writing and publishing puppet modules
Portland Puppet User Group June 2014: Writing and publishing puppet modules
 
June 2014 PDX PUG: Writing and Publishing Puppet Modules
June 2014 PDX PUG: Writing and Publishing Puppet Modules June 2014 PDX PUG: Writing and Publishing Puppet Modules
June 2014 PDX PUG: Writing and Publishing Puppet Modules
 
Attacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryAttacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous Delivery
 
Build Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionBuild Your Own HiveMQ Extension
Build Your Own HiveMQ Extension
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Knolx session
Knolx sessionKnolx session
Knolx session
 

More from hazzaz

Coffee1
Coffee1Coffee1
Coffee1
hazzaz
 
Suy ngam
Suy ngamSuy ngam
Suy ngam
hazzaz
 
Tu dong dat hang tu he thong ban le lon nhat trung quoc
Tu dong dat hang tu he thong ban le lon nhat trung quocTu dong dat hang tu he thong ban le lon nhat trung quoc
Tu dong dat hang tu he thong ban le lon nhat trung quoc
hazzaz
 
trung oss magento overview
trung oss magento overviewtrung oss magento overview
trung oss magento overview
hazzaz
 
su dung drupal xay dung mang xa hoi
su dung drupal xay dung mang xa hoisu dung drupal xay dung mang xa hoi
su dung drupal xay dung mang xa hoi
hazzaz
 
html5 css3 the future of web technology
html5 css3 the future of web technologyhtml5 css3 the future of web technology
html5 css3 the future of web technology
hazzaz
 
java script unit testing framework
java script unit testing frameworkjava script unit testing framework
java script unit testing framework
hazzaz
 
kiem tien online
kiem tien onlinekiem tien online
kiem tien online
hazzaz
 
web optimization
web optimizationweb optimization
web optimization
hazzaz
 
mysql optimization
mysql optimizationmysql optimization
mysql optimization
hazzaz
 
css_trends
css_trendscss_trends
css_trends
hazzaz
 
Phan mem tu do nguon mo
Phan mem tu do nguon moPhan mem tu do nguon mo
Phan mem tu do nguon mo
hazzaz
 
Howtobuildyourownframework
HowtobuildyourownframeworkHowtobuildyourownframework
Howtobuildyourownframework
hazzaz
 
nguyenhainhathuy-building-restful-web-service
nguyenhainhathuy-building-restful-web-servicenguyenhainhathuy-building-restful-web-service
nguyenhainhathuy-building-restful-web-service
hazzaz
 
Node js
Node jsNode js
Node js
hazzaz
 
nguyen-duc-phu-search-engine
nguyen-duc-phu-search-enginenguyen-duc-phu-search-engine
nguyen-duc-phu-search-engine
hazzaz
 
02 phan-thai-trung-drupal
02 phan-thai-trung-drupal02 phan-thai-trung-drupal
02 phan-thai-trung-drupal
hazzaz
 

More from hazzaz (20)

Coffee1
Coffee1Coffee1
Coffee1
 
Suy ngam
Suy ngamSuy ngam
Suy ngam
 
Tu dong dat hang tu he thong ban le lon nhat trung quoc
Tu dong dat hang tu he thong ban le lon nhat trung quocTu dong dat hang tu he thong ban le lon nhat trung quoc
Tu dong dat hang tu he thong ban le lon nhat trung quoc
 
trung oss magento overview
trung oss magento overviewtrung oss magento overview
trung oss magento overview
 
su dung drupal xay dung mang xa hoi
su dung drupal xay dung mang xa hoisu dung drupal xay dung mang xa hoi
su dung drupal xay dung mang xa hoi
 
html5 css3 the future of web technology
html5 css3 the future of web technologyhtml5 css3 the future of web technology
html5 css3 the future of web technology
 
java script unit testing framework
java script unit testing frameworkjava script unit testing framework
java script unit testing framework
 
kiem tien online
kiem tien onlinekiem tien online
kiem tien online
 
web optimization
web optimizationweb optimization
web optimization
 
mysql optimization
mysql optimizationmysql optimization
mysql optimization
 
Albus
AlbusAlbus
Albus
 
css_trends
css_trendscss_trends
css_trends
 
Cloud
CloudCloud
Cloud
 
Phan mem tu do nguon mo
Phan mem tu do nguon moPhan mem tu do nguon mo
Phan mem tu do nguon mo
 
redis
redisredis
redis
 
Howtobuildyourownframework
HowtobuildyourownframeworkHowtobuildyourownframework
Howtobuildyourownframework
 
nguyenhainhathuy-building-restful-web-service
nguyenhainhathuy-building-restful-web-servicenguyenhainhathuy-building-restful-web-service
nguyenhainhathuy-building-restful-web-service
 
Node js
Node jsNode js
Node js
 
nguyen-duc-phu-search-engine
nguyen-duc-phu-search-enginenguyen-duc-phu-search-engine
nguyen-duc-phu-search-engine
 
02 phan-thai-trung-drupal
02 phan-thai-trung-drupal02 phan-thai-trung-drupal
02 phan-thai-trung-drupal
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

speed up ntvv2 by php ext module

  • 1. 18/12/2010 Speed up ZingMe-NTVV2 with PHP extension module By Nguyen Trung Thanh ZingMe Team leader Web Technical - VNG
  • 4. Introduction • Ntvv2 (http://me.zing.vn/apps/ntvv2) – 1.M daily active user – Average 800 rps (per webserver) max 1100 rps – 9300 rps (all database servers) – 3 webservers • Use Membase for cache and storage • Use other db for secondary storage • All bussiness function is moved to PHP extension
  • 5. Why to write PHP module? Make complicated Bussiness functions run faster, consume less memory PHP high-level overhead cpu/mem Advance facility with PHP-FPM Cache something in PHP process Strictly Confidential – Do Not Distribute
  • 6. PHP extension basic What is an extension? Lifecycle Setting up a build environment http://devzone.zend.com/article/4486 http://devzone.zend.com/article/1021-Extension-Writing-Part-I- Introduction-to-PHP-and-Zend
  • 7. What is an extension? Have you ever used PHP extension? PHP consist of many extensions All function we used is from extensions
  • 9. Setting up build environment - Setup PHP-devel - Sample extension
  • 10. Is it complicated? ● Is there any sexier and easier way? ● We can use SWIG
  • 11. SWIG SWIG is an interface compiler that connects programs written in C and C++ with scripting languages such as PHP, Python, Ruby... How SWIG works Using SWIG Install module to PHP extensions Sample Strictly Confidential – Do Not Distribute
  • 13. What does SWIG do for you ? Namespace Constants Type conversion For simple types (int, float, char *, enum) Wraps complex types Pointers to structs and classes Exposes functions
  • 14. Using SWIG Defile module in swig file Generate source code Create module project, build it
  • 15. Define module Data type Wrapper class/functions %module ntvv2module %{ #include <string> #include <vector> #include <list> #include <string> #include “ntvvgame.h" %} struct LandInfo{ int id; std::string data; } ; Strictly Confidential – Do Not Distribute LandInfo updateLandInfo(int uid, int landID);
  • 16. Exposure •Swig recognizes C/C++ declarations 'struct' or 'class' functions •Hiding elements %ignore solver::noupdate; %include “satsolver/solver.h”
  • 17. Useful commands •Renaming %rename("to_s") asString(); %rename( "name=" ) set_name( const char *name ); %rename("empty?") empty(); •Aliasing %alias get "[]"; •Constants %constant int Script = C_CONSTANT; •Defines %define YUILogComponent "bindings" %enddef %define %macro(PARAMETER)
  • 18. SWIG steps Generate code Create project, compiling – Add genterated code to project Running – Add extension module to PHP
  • 19. Sample Cache data in PHP module Strictly Confidential – Do Not Distribute
  • 20. Q&A