SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
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

Mais conteúdo relacionado

Destaque

Holz Land Hogo News
Holz Land Hogo NewsHolz Land Hogo News
Holz Land Hogo NewsVenezia0208
 
Tu Task# 5
Tu  Task# 5Tu  Task# 5
Tu Task# 5Tu
 
Completo E Total
Completo E TotalCompleto E Total
Completo E TotalWanderlei
 
Radio Project Presentation
Radio Project PresentationRadio Project Presentation
Radio Project PresentationSelasie Smith
 
Ezcast pro vs Crestron Airmedia vs Barco clickshare vs Latentech wepresent
Ezcast pro vs Crestron Airmedia vs Barco clickshare vs Latentech wepresentEzcast pro vs Crestron Airmedia vs Barco clickshare vs Latentech wepresent
Ezcast pro vs Crestron Airmedia vs Barco clickshare vs Latentech wepresentvinaybs
 

Destaque (6)

Holz Land Hogo News
Holz Land Hogo NewsHolz Land Hogo News
Holz Land Hogo News
 
Social Media
Social MediaSocial Media
Social Media
 
Tu Task# 5
Tu  Task# 5Tu  Task# 5
Tu Task# 5
 
Completo E Total
Completo E TotalCompleto E Total
Completo E Total
 
Radio Project Presentation
Radio Project PresentationRadio Project Presentation
Radio Project Presentation
 
Ezcast pro vs Crestron Airmedia vs Barco clickshare vs Latentech wepresent
Ezcast pro vs Crestron Airmedia vs Barco clickshare vs Latentech wepresentEzcast pro vs Crestron Airmedia vs Barco clickshare vs Latentech wepresent
Ezcast pro vs Crestron Airmedia vs Barco clickshare vs Latentech wepresent
 

Semelhante a Speed up ZingMe-Nông trại vui vẻ 2 with PHP extension module

Node.js for enterprise - JS Conference
Node.js for enterprise - JS ConferenceNode.js for enterprise - JS Conference
Node.js for enterprise - JS ConferenceTimur Shemsedinov
 
Taming Deployment With Smart Frog
Taming Deployment With Smart FrogTaming Deployment With Smart Frog
Taming Deployment With Smart FrogSteve Loughran
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
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 PHPFabien Potencier
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
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)Itzik Kotler
 
Swift profiling middleware and tools
Swift profiling middleware and toolsSwift profiling middleware and tools
Swift profiling middleware and toolszhang hua
 
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 moreWSO2
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Rene Bakx
 
Secure Programming
Secure ProgrammingSecure Programming
Secure Programmingalpha0
 
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 modulesPuppet
 
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
 
Attacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryAttacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryJames Wickett
 
Build Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionBuild Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionHiveMQ
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Maurizio Pelizzone
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 

Semelhante a Speed up ZingMe-Nông trại vui vẻ 2 with PHP extension 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
 

Último

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
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
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
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
 
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
 
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
 
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
 
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
 
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
 

Último (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
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
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
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 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
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
 
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?
 
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...
 
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)
 
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
 
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
 
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
 

Speed up ZingMe-Nông trại vui vẻ 2 with PHP extension 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