SlideShare a Scribd company logo
ZingMe Practice
For Building Scalable PHP Website




                  By Chau Nguyen Nhat Thanh
                    ZingMe Technical Manager
                         Web Technical - VNG
Agenda

●
    About ZingMe
●
    Scaling PHP application
    ●
        Scalability definition
    ●
        Scaling up vs scaling out
    ●
        Load balancing
    ●
        Problem with PHP when using load balancer
    ●
        User session management
    ●
        Problem with code deployment
                                                    2
Agenda(cont.)
●   ZingMe practice in building scalable PHP
    applications
    ●   Choosing scale out
    ●   Load balancing model
    ●   User session management system
    ●   Code deployment system
●   ZingMe more
    ●   Open social API
About ZingMe
●   A social network
About ZingMe
●   25M registered accounts
●   1.7M daily active users
●   5M monthly active users
●   > 300 servers (1.2 K cores)
    ●   50 DB servers, >40 Memcached servers
    ●   ~ 100 Web servers
    ●   40 servers for Hadoop farm
    ●   Others (storage, ...)
About ZingMe
●   Load balancing: HA proxy, LVS, hardware (?)
●   Web server: Nginx, lighttpd, apache, hardware (?)
●   Web caching: squid, varnish, hardware (?)
●   Caching: Redis, memcached
●   Programming language: PHP, C++,Java, python,
    bash script
●   Searching: Solr, lucene
●   DB: MySQL , NOSQL
●   Log system: Scriber + Hadoop
Scaling PHP application
●   Scalability definition
●   Scaling up vs scaling out
●   Load balancing
●   User session management
●   Code deployment
Scalability definition
“Scalability is a desirable property of a system,
a network, or a process, which indicates its
ability to either handle growing amounts of work
in a graceful manner or to be enlarged” from
Wikipedia
”A web application is scalable when is able to
manage a growing traffic with additional
resources (CPU, RAM) without software
changes” by Jan Burkl, Enrico Zimuel (Zend
Technologies)
Scaling up vs scaling out
●   Scaling up (vertically)
    ●   Add more resources to single node in a
        system
    ●   Resources can be software or hardware
    ●   Make system more powerful by increase node
        powerful
    ●   Has an upper limit
    ●   Hard to implement HA solution
    ●   Cost: expensive
Scaling up vs scaling out
●   Scaling out (horizontally)
    ●   Add more nodes to a system
    ●   Make system more powerful by increase
        number of nodes in the system
    ●   Maybe has no upper limit
    ●   Easy to implement HA solution
    ●   Cost: cheap
Scaling up vs scaling out




          •
            From slide ”How to scale PHP application”
     •
       by Jan Burkl, Enrico Zimuel (Zend Technologies)
Load balancing
●   The need of a load balancer
    ●   Most of big web site choose scale out
    ●   Need a component for distribute load among
        the nodes
    ●   Such component called load balancer
Load balancing




   •
      from ”Server load balancing architectures”
   •
     by Gregor Roth, JavaWorld.com, 10/21/08
Load balancing
●   How load balancer work?
    ●   Has 2 interfaces: Back-end, Front-end
    ●   Front-end receive the request from client
    ●   Back-end forward request to internal node
    ●   Back-end receive the response from node
    ●   Front-end response to client
    ●   Status monitor for monitoring the back-end
        interface
Load balancing
●   Web application load balancer
    ●   Work in layer 7
    ●   Can filter HTTP header and body in both
        request and response
    ●   Can be hardware or software
    ●   F5 BIG-IP, Citrix Netscale, Cisco
    ●   HA Proxy, Nginx, lighttpd
Problem with PHP when using
           load balancer
●   PHP stores session info into local disk by
    default
●   How to scale session to 2 nodes ?
●   Can be scaled if:
    ●   Load balancer has a method for routing the
        same user requests into the same nodes (1)
    ●   Override the default PHP mechanism for
        storing session of all nodes in the same
        storage (2)
Problem with PHP when using
           load balancer
●   Method (1)
    ●   Load balancer must keep state for connection
    ●   Overhead for routing request
    ●   Not balancing
●   Method (2)
    ●   Must change software
    ●   No overhead for routing request
    ●   More balancer than (1)
PHP session management
●   Choose method (2)
●   Centralize storage among web server
    ●   Storage can be NFS, DB, memcached...
    ●   All web servers access the same storage
●   Override the default behavior of PHP
    session functions
●   Bottleneck can be in storage
PHP session management
●   Call session_set_save_handler( callback
    $open , callback $close , callback $read ,
    callback $write , callback $destroy ,
    callback $gc ) to override default behavior
●   More infos:
    ●   http://php.net/manual/en/function.sessio
        n-set-save-handler.php
Problem with code deployment
●   Adding new server to system:
    ●   What kind of configuration must be changed?
    ●   Which code will be deployed ? In which
        server?
    ●   How can we monitor them?
Problem with PHP code
               deployment
●   What will we change in PHP code ?
    ●   Separate all configuration to configuration file
    ●   Do not hard code any configuration
    ●   Put the code in a central server like SVN
    ●   Use scripts to pull all code to production
        server
    ●   Build profiler system for monitor the code
ZingMe practice for building
         scalable web site
●   Choose Scale out
●   Use HA proxy for load balancing
●   Use Memcached for session storage
●   Simple code deployment system base on
    SVN and bash script
ZingMe practice for building
         scalable web site
●   Divide into small services
●   Use commodity hardwares
●   Use open source software
●   Server has the same environment
●   Add new server < 5mins
ZingMe load balancing model
ZingMe load balancing model
●   Use HA proxy
    ●   HTTP based proxy
    ●   High availability
    ●   Use epoll
●   Use content switching to divide the service
    into group
●   Define load balancing factors based on the
    power of the back-end server
ZingMe load balancing model
Normal traffic
ZingMe load balancing model
ZingMe traffic
ZingMe user session
              management
●   Use memcached for high performance
●   Override Zend_Session
●   3K hits/s
Why we choose memcache?
●   L1 cache reference                          0.5 ns
●   Branch mispredict                             5 ns
●   L2 cache reference                            7 ns
●   Mutex lock/unlock                            25 ns
●   Main memory reference                       100 ns
●   Compress 1K bytes with Zippy              3,000 ns
●   Send 2K bytes over 1 Gbps network        20,000 ns
●   Read 1 MB sequentially from memory      250,000 ns
●   Round trip within same datacenter       500,000 ns
●   Disk seek                              10,000,000 ns
●   Read 1 MB sequentially from disk     20,000,000 ns
●   Send packet CA->Netherlands->CA      150,000,000 ns

                                           From Jeff Dean - google.com
ZingMe code deployment
●   Developer upload code to SVN
●   SO runs scripts to deploy code to production server
●   Has staging server for real environment test
●   Dev cannot touch to production environment
●   Using environment parameter
    ●   Nginx: fastcgi_param
    ●   Apache: setenv
ZingMe more
●   Standard latency for server side code
    processing < 200ms
●   Live demos Profiler system
●   Open social API updated infos
    ●   Sandbox for developer
    ●   Will be open soon
ZingMe more
●   Optimize node before scale it up
    ●   Performance C++ > Java > PHP
    ●   Why PHP ?
        –   Easy to implement business
        –   Easy to deploy
    ●   Why C++?
        –   Performance
    ●   Can we mix PHP and C++?
        –   Next session will answer
Q&A




Contact info:
Chau Nguyen Nhat Thanh
thanhcnn@vinagame.com.vn
me.zing.vn/thanhcnn2000

More Related Content

PDF
Zingme practice for building scalable website with PHP
PPTX
Improving Kafka at-least-once performance at Uber
PDF
Load balancing at tuenti
PDF
Web performance optimization - MercadoLibre
PDF
hbaseconasia2019 Test-suite for Automating Data-consistency checks on HBase
PDF
Scaling PostgreSQL with Skytools
PPTX
Benchmarking NGINX for Accuracy and Results
PDF
Handle Large Messages In Apache Kafka
Zingme practice for building scalable website with PHP
Improving Kafka at-least-once performance at Uber
Load balancing at tuenti
Web performance optimization - MercadoLibre
hbaseconasia2019 Test-suite for Automating Data-consistency checks on HBase
Scaling PostgreSQL with Skytools
Benchmarking NGINX for Accuracy and Results
Handle Large Messages In Apache Kafka

What's hot (20)

PDF
Denser, cooler, faster, stronger: PHP on ARM microservers
ODP
Shootout at the PAAS Corral
ODP
Shootout at the AWS Corral
PDF
How to Monitor MySQL
PDF
Optimizing Your Frontend Performance
PDF
Pulsar Storage on BookKeeper _Seamless Evolution
PDF
Massively Scaled High Performance Web Services with PHP
PDF
Connection Pooling in PostgreSQL using pgbouncer
PPTX
Message Queuing on a Large Scale: IMVUs stateful real-time message queue for ...
PDF
Extending functionality in nginx, with modules!
PPTX
NGINX High-performance Caching
ODP
GUC Tutorial Package (9.0)
PPTX
Supercharge Application Delivery to Satisfy Users
PDF
92 grand prix_2013
PPTX
Warsaw MuleSoft Meetup #12 Effective Streaming
KEY
Nginx - Tips and Tricks.
PDF
7 Ways To Crash Postgres
PDF
Producer Performance Tuning for Apache Kafka
PDF
Apache Kafka: A high-throughput distributed messaging system @ JCConf 2014
PDF
Mystery Machine Overview
Denser, cooler, faster, stronger: PHP on ARM microservers
Shootout at the PAAS Corral
Shootout at the AWS Corral
How to Monitor MySQL
Optimizing Your Frontend Performance
Pulsar Storage on BookKeeper _Seamless Evolution
Massively Scaled High Performance Web Services with PHP
Connection Pooling in PostgreSQL using pgbouncer
Message Queuing on a Large Scale: IMVUs stateful real-time message queue for ...
Extending functionality in nginx, with modules!
NGINX High-performance Caching
GUC Tutorial Package (9.0)
Supercharge Application Delivery to Satisfy Users
92 grand prix_2013
Warsaw MuleSoft Meetup #12 Effective Streaming
Nginx - Tips and Tricks.
7 Ways To Crash Postgres
Producer Performance Tuning for Apache Kafka
Apache Kafka: A high-throughput distributed messaging system @ JCConf 2014
Mystery Machine Overview
Ad

Viewers also liked (9)

PPT
20130714 php matsuri - highly available php
PDF
Jquery at-webcamp
PDF
Choosing a european fund domicile: the view of global asset managers
PPTX
อาหารไทย กลุ่ม 2
PPS
Stress
PDF
lookbookpress
PPTX
Building a horizontally scalable API in php
PPT
Scalability In PHP
PPS
Scalable PHP
20130714 php matsuri - highly available php
Jquery at-webcamp
Choosing a european fund domicile: the view of global asset managers
อาหารไทย กลุ่ม 2
Stress
lookbookpress
Building a horizontally scalable API in php
Scalability In PHP
Scalable PHP
Ad

Similar to 01 zingme practice for building scalable website with php (20)

PDF
Scalable Architecture 101
PPTX
Apache Performance Tuning: Scaling Out
ODP
MNPHP Scalable Architecture 101 - Feb 3 2011
ODP
Apache httpd 2.4: The Cloud Killer App
PPT
Large-scale projects development (scaling LAMP)
PDF
How to scale PHP applications
KEY
Site Performance - From Pinto to Ferrari
PPTX
North east user group tour
PPT
Planning for-high-performance-web-application
PDF
Scale Apache with Nginx
PDF
PDF
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
PDF
Fixing twitter
PDF
Fixing_Twitter
PDF
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
PPTX
BTV PHP - Building Fast Websites
PPT
Zend Con 2008 Slides
PDF
Framework and Application Benchmarking
PDF
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PDF
InterConPHP 2014 - Scaling PHP
Scalable Architecture 101
Apache Performance Tuning: Scaling Out
MNPHP Scalable Architecture 101 - Feb 3 2011
Apache httpd 2.4: The Cloud Killer App
Large-scale projects development (scaling LAMP)
How to scale PHP applications
Site Performance - From Pinto to Ferrari
North east user group tour
Planning for-high-performance-web-application
Scale Apache with Nginx
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing twitter
Fixing_Twitter
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
BTV PHP - Building Fast Websites
Zend Con 2008 Slides
Framework and Application Benchmarking
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
InterConPHP 2014 - Scaling PHP

More from Nguyen Duc Phu (17)

PPTX
iOS Gaming with Cocos2d
PPT
05 - Phan Thai Trung - Tu dong dat hang tu he thong ban le lon nhat Trung Quoc
PPT
8 - Javascript unit testing framework
PPT
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
PPT
Hanoi php day 2008 - 03. dang minh tuan - html, css, javascript
PPT
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
PPT
Hanoi php day 2008 - 02. phan thai trung - drupal
PPT
13 social network game
PPTX
12 trung-oss-magento-overview
PPT
11 building joomla! extensions with flex integration
PDF
10 su dung drupal xay dung mang xa hoi
PPT
09 html5 css3-the_future_of_web_technology
PPT
07 build your-own_php_extension
PDF
04 web optimization
PDF
02 vng thanhnt-speedup_ntvv2_by_ph_pextmodule_
PPT
14 how startups can benefit from launch community
PPT
Hanoi PHP Day 2008 - 04 - Nguyen Duc Phu - Search Engine: New Collection S...
iOS Gaming with Cocos2d
05 - Phan Thai Trung - Tu dong dat hang tu he thong ban le lon nhat Trung Quoc
8 - Javascript unit testing framework
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 03. dang minh tuan - html, css, javascript
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Hanoi php day 2008 - 02. phan thai trung - drupal
13 social network game
12 trung-oss-magento-overview
11 building joomla! extensions with flex integration
10 su dung drupal xay dung mang xa hoi
09 html5 css3-the_future_of_web_technology
07 build your-own_php_extension
04 web optimization
02 vng thanhnt-speedup_ntvv2_by_ph_pextmodule_
14 how startups can benefit from launch community
Hanoi PHP Day 2008 - 04 - Nguyen Duc Phu - Search Engine: New Collection S...

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
Teaching material agriculture food technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Empathic Computing: Creating Shared Understanding
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Cloud computing and distributed systems.
PDF
Approach and Philosophy of On baking technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
NewMind AI Weekly Chronicles - August'25 Week I
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
Understanding_Digital_Forensics_Presentation.pptx
Teaching material agriculture food technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Empathic Computing: Creating Shared Understanding
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Cloud computing and distributed systems.
Approach and Philosophy of On baking technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Network Security Unit 5.pdf for BCA BBA.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
sap open course for s4hana steps from ECC to s4
Digital-Transformation-Roadmap-for-Companies.pptx

01 zingme practice for building scalable website with php

  • 1. ZingMe Practice For Building Scalable PHP Website By Chau Nguyen Nhat Thanh ZingMe Technical Manager Web Technical - VNG
  • 2. Agenda ● About ZingMe ● Scaling PHP application ● Scalability definition ● Scaling up vs scaling out ● Load balancing ● Problem with PHP when using load balancer ● User session management ● Problem with code deployment 2
  • 3. Agenda(cont.) ● ZingMe practice in building scalable PHP applications ● Choosing scale out ● Load balancing model ● User session management system ● Code deployment system ● ZingMe more ● Open social API
  • 4. About ZingMe ● A social network
  • 5. About ZingMe ● 25M registered accounts ● 1.7M daily active users ● 5M monthly active users ● > 300 servers (1.2 K cores) ● 50 DB servers, >40 Memcached servers ● ~ 100 Web servers ● 40 servers for Hadoop farm ● Others (storage, ...)
  • 6. About ZingMe ● Load balancing: HA proxy, LVS, hardware (?) ● Web server: Nginx, lighttpd, apache, hardware (?) ● Web caching: squid, varnish, hardware (?) ● Caching: Redis, memcached ● Programming language: PHP, C++,Java, python, bash script ● Searching: Solr, lucene ● DB: MySQL , NOSQL ● Log system: Scriber + Hadoop
  • 7. Scaling PHP application ● Scalability definition ● Scaling up vs scaling out ● Load balancing ● User session management ● Code deployment
  • 8. Scalability definition “Scalability is a desirable property of a system, a network, or a process, which indicates its ability to either handle growing amounts of work in a graceful manner or to be enlarged” from Wikipedia ”A web application is scalable when is able to manage a growing traffic with additional resources (CPU, RAM) without software changes” by Jan Burkl, Enrico Zimuel (Zend Technologies)
  • 9. Scaling up vs scaling out ● Scaling up (vertically) ● Add more resources to single node in a system ● Resources can be software or hardware ● Make system more powerful by increase node powerful ● Has an upper limit ● Hard to implement HA solution ● Cost: expensive
  • 10. Scaling up vs scaling out ● Scaling out (horizontally) ● Add more nodes to a system ● Make system more powerful by increase number of nodes in the system ● Maybe has no upper limit ● Easy to implement HA solution ● Cost: cheap
  • 11. Scaling up vs scaling out • From slide ”How to scale PHP application” • by Jan Burkl, Enrico Zimuel (Zend Technologies)
  • 12. Load balancing ● The need of a load balancer ● Most of big web site choose scale out ● Need a component for distribute load among the nodes ● Such component called load balancer
  • 13. Load balancing • from ”Server load balancing architectures” • by Gregor Roth, JavaWorld.com, 10/21/08
  • 14. Load balancing ● How load balancer work? ● Has 2 interfaces: Back-end, Front-end ● Front-end receive the request from client ● Back-end forward request to internal node ● Back-end receive the response from node ● Front-end response to client ● Status monitor for monitoring the back-end interface
  • 15. Load balancing ● Web application load balancer ● Work in layer 7 ● Can filter HTTP header and body in both request and response ● Can be hardware or software ● F5 BIG-IP, Citrix Netscale, Cisco ● HA Proxy, Nginx, lighttpd
  • 16. Problem with PHP when using load balancer ● PHP stores session info into local disk by default ● How to scale session to 2 nodes ? ● Can be scaled if: ● Load balancer has a method for routing the same user requests into the same nodes (1) ● Override the default PHP mechanism for storing session of all nodes in the same storage (2)
  • 17. Problem with PHP when using load balancer ● Method (1) ● Load balancer must keep state for connection ● Overhead for routing request ● Not balancing ● Method (2) ● Must change software ● No overhead for routing request ● More balancer than (1)
  • 18. PHP session management ● Choose method (2) ● Centralize storage among web server ● Storage can be NFS, DB, memcached... ● All web servers access the same storage ● Override the default behavior of PHP session functions ● Bottleneck can be in storage
  • 19. PHP session management ● Call session_set_save_handler( callback $open , callback $close , callback $read , callback $write , callback $destroy , callback $gc ) to override default behavior ● More infos: ● http://php.net/manual/en/function.sessio n-set-save-handler.php
  • 20. Problem with code deployment ● Adding new server to system: ● What kind of configuration must be changed? ● Which code will be deployed ? In which server? ● How can we monitor them?
  • 21. Problem with PHP code deployment ● What will we change in PHP code ? ● Separate all configuration to configuration file ● Do not hard code any configuration ● Put the code in a central server like SVN ● Use scripts to pull all code to production server ● Build profiler system for monitor the code
  • 22. ZingMe practice for building scalable web site ● Choose Scale out ● Use HA proxy for load balancing ● Use Memcached for session storage ● Simple code deployment system base on SVN and bash script
  • 23. ZingMe practice for building scalable web site ● Divide into small services ● Use commodity hardwares ● Use open source software ● Server has the same environment ● Add new server < 5mins
  • 25. ZingMe load balancing model ● Use HA proxy ● HTTP based proxy ● High availability ● Use epoll ● Use content switching to divide the service into group ● Define load balancing factors based on the power of the back-end server
  • 26. ZingMe load balancing model Normal traffic
  • 27. ZingMe load balancing model ZingMe traffic
  • 28. ZingMe user session management ● Use memcached for high performance ● Override Zend_Session ● 3K hits/s
  • 29. Why we choose memcache? ● L1 cache reference 0.5 ns ● Branch mispredict 5 ns ● L2 cache reference 7 ns ● Mutex lock/unlock 25 ns ● Main memory reference 100 ns ● Compress 1K bytes with Zippy 3,000 ns ● Send 2K bytes over 1 Gbps network 20,000 ns ● Read 1 MB sequentially from memory 250,000 ns ● Round trip within same datacenter 500,000 ns ● Disk seek 10,000,000 ns ● Read 1 MB sequentially from disk 20,000,000 ns ● Send packet CA->Netherlands->CA 150,000,000 ns From Jeff Dean - google.com
  • 30. ZingMe code deployment ● Developer upload code to SVN ● SO runs scripts to deploy code to production server ● Has staging server for real environment test ● Dev cannot touch to production environment ● Using environment parameter ● Nginx: fastcgi_param ● Apache: setenv
  • 31. ZingMe more ● Standard latency for server side code processing < 200ms ● Live demos Profiler system ● Open social API updated infos ● Sandbox for developer ● Will be open soon
  • 32. ZingMe more ● Optimize node before scale it up ● Performance C++ > Java > PHP ● Why PHP ? – Easy to implement business – Easy to deploy ● Why C++? – Performance ● Can we mix PHP and C++? – Next session will answer
  • 33. Q&A Contact info: Chau Nguyen Nhat Thanh thanhcnn@vinagame.com.vn me.zing.vn/thanhcnn2000