• Save
speed up ntvv2 by php ext module
Upcoming SlideShare
Loading in...5
×
 

speed up ntvv2 by php ext module

on

  • 3,855 views

 

Statistics

Views

Total Views
3,855
Views on SlideShare
3,855
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

speed up ntvv2 by php ext module speed up ntvv2 by php ext module Presentation Transcript

  • 18/12/2010Speed up ZingMe-NTVV2 withPHP extension module By Nguyen Trung Thanh ZingMe Team leader Web Technical - VNG
  • ContentsIntroductionWhy?PHP extension basicSWIGSample
  • 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 memoryPHP high-level overhead cpu/memAdvance facility with PHP-FPM Cache something in PHP processStrictly Confidential – Do Not Distribute
  • PHP extension basicWhat is an extension?LifecycleSetting up a build environmenthttp://devzone.zend.com/article/4486http://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 extensionsAll 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
  • SWIGSWIG is an interface compiler that connects programs written in C and C++ with scripting languages such as PHP, Python, Ruby...How SWIG worksUsing SWIGInstall module to PHP extensionsSampleStrictly Confidential – Do Not Distribute
  • How SWIG works
  • What does SWIG do for you ?NamespaceConstantsType conversion For simple types (int, float, char *, enum)Wraps complex types Pointers to structs and classesExposes functions
  • Using SWIGDefile module in swig fileGenerate source codeCreate module project, build it
  • Define moduleData typeWrapper 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++ declarationsstruct or classfunctions•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 stepsGenerate codeCreate project, compiling – Add genterated code to projectRunning – Add extension module to PHP
  • SampleCache data in PHP moduleStrictly Confidential – Do Not Distribute
  • Q&A