SlideShare a Scribd company logo
1 of 61
Heavy Web Optimization
                   BACK-END
                          <?php //from a PHP dev ?>




Vo Duy Tuan   PHP Developer from Reader.vn, Picto.vn & more…
$who_am_I?
   My Name is Võ Duy Tuấn
   PHP 5 Zend Certified Engineer
   Interests: PHP, Social Network, Optimize Web
   Works:
     Thegioididong

     Reader.vn,   Picto.vn CEO/Founder
     Trainer

     Freelancer

     Consultant
$table_of_content
   Warm up: Some best practices
   Back-end Optimization
   De-normalization
   Asynchronous processing
   Caching
   Scalability
1   Warm up: Some best practices
1.1. Smarty Trick
a. Prevent recompile .tpl file:
$smarty = new Smarty();
$smarty->compile_check = false;


b. Compile all .tpl files:
set_time_limit(1000);    //do not interrupt
$smarty->compileAllTemplates('.tpl',true);
1.2. Pagination
   From




   To
1.2. Pagination – Why?
   How do we make pagination feature?

mysql_query(‘SELECT COUNT(*) FROM tbl WHERE col LIKE “%word%”’)
> Get total record > Get toal page > Build page number list with a simple loop


mysql_query(‘SELECT * FROM tbl WHERE col LIKE “%word%” LIMIT 0,20’)
> Get data of current page (page 1, with 20 rows/page)




Do you have the answer  ?
1.3. Get enough data from remote server

   Send HEAD to detect 404 error from remote
    URL

   Read first bytes of remote file to detect image
    type,width/height
2   Back-end Optimization
2.1. Where is Back-end?

“80% of the end-user response time is spent on the front-
end. Most of this time is tied up in downloading all the
components in the page: images, stylesheets, scripts, Flash,
etc. Reducing the number of components in turn reduces the
number of HTTP requests required to render the page. This
is the key to faster pages.”
2.2. Back-end Optimize Theory
   Reduce disk In/Out
   Reduce complex/fuzzy
   Reduce budget
2.3. Debugging & Profiling
   Nusphere Phped Debugger
   Xdebug
   top command
   Apache bench
2.3.1. Nusphere Phped Debugger
   Installation:

       Step 1: Install php extension

       Step 2: Install DBGbar addon for Firefox or DBG

        debugger on Chrome

       Step 3: Update PHP.INI config

       Restart your web server (if needed)
2.3.1. Nusphere Phped Debugger
2.3.2. Xdebug
   Installation:

       Step 1: Install php extension

       Step 2: Update PHP.INI config

       Restart your server (if needed)
2.3.2. Xdebug
 PHP.INI
 [xdebug]
 zend_extension_ts = C:..php_xdebug-2.1.0-5.2-vc6.dll
 xdebug.profiler_output_dir = "C:xdebug"
 xdebug.profiler_output_name = "callgrind.%R.%t"
 xdebug.profiler_enable = 0
 xdebug.profiler_append=0
 xdebug.profiler_enable_trigger = 1
 xdebug.extended_info=1


 Usage:
 http://example.com/index.php?XDEBUG_PROFILE
2.3.2. Xdebug
2.3.3. linux command top
2.3.4. Apache Bench
Somewhere in the dark…
3   De-normalization
3.1. What is De-normalization?

   Most of use live with Relational DB.
   What is normalization?
       Database normalization is the process of organizing
        the fields and tables of a relational database to
        minimize redundancy and dependency .(Wiki)

   What is De-normalization?
       Denormalization is the process of attempting to
        optimise the read performance of a database by
        adding redundant data or by grouping data. (Wiki)
3.2. How to de-normalize?

   Vertical Split.
   Pre-calculated value.
   Duplicate data.
3.2.1. Vertical Split
3.2.1. Vertical Split (cont.)
3.2.2. Pre-calculated value
3.2.3. Duplicate data
3.3. Data correctness
   Normalization = Correctness
   Denormalization = Performance
4   Asynchronous processing
4.1. Job queue
4.2. Job queue :: Gearman




                       http://gearman.org/
But….
Apache can be a job queue,
4.3. Async Request
function backgroundHttpPost($url, $prm = ''){
   $p=parse_url($url);
   $fp = fsockopen($p['host'], isset($p['port'])?$p['port']:80, $en, $es, 30);

    if (!$fp)
          return false;
    else {
          $out = "POST ".$p['path']."?".$p['query']." HTTP/1.1rn";
          $out.= "Host: ".$p['host']."rn";
          $out.= "Content-Type: application/x-www-form-urlencodedrn";
          $out.= "Content-Length: ".strlen($prm)."rn";
          $out.= "Connection: Closernrn";
          if ($prm != '') $out.= $prm;
          fwrite($fp, $out); fclose($fp);
          return true;
    }
}
Usage:
$taskUrl = 'http://picto.vn/task/deletephoto';
backgroundHttpPost($taskUrl, 'photoid=' . $myPhoto->id);
5   Caching
5.1. What is caching?
5.2. What is APC?

   Alternative PHP Cache – APC
   Free PHP Extension
   PHP Opcode cache
   Support User data cache
   Run on SAME machine with PHP
   NOT support multi servers
5.3. APC Monitor
5.4. APC Using
5.5. APC Tip
   Opcode your web code only
   Disable APC for PhpMyAdmin

<Directory "/mysite/public_html/">
    ...
    php_admin_flag apc.cache_by_default On
</Directory

<Directory "/mysite/public_html/phpmyadmin/">
    ...
    php_admin_flag apc.cache_by_default Off
</Directory>
2.6. APC Tip..
   Cache STRING is better than ARRAY
   Long Time To Live better than Short
   Case study:
       Caching for Feed System:
BEFORE
BEFORE
ANALYSE
AFTER
Short TTL make fragmentation
Short TTL make fragmentation
6   Cloud computing - AWS
       Amazon Elastic Compute Cloud – Amazon EC2 + EBS
       Amazon Simple Storage Service – Amazon S3
       Amazon Simple Email Service – Amazon SES
6.1. Amazon EC2

5
6.1. Amazon EC2 (cont.)

5
6.2. Amazon S3

5
6.2. Amazon S3 (cont.)

5
6.2. Amazon S3 (cont.)

5
6.3. Amazon SES
   1,000,000 emails = $100
5
   Support SMTP
6.3. Amazon SES (cont.)

5
6.4. Adapt to AWS for scalability
   Local server (Web & RDBMS) + S3
5
   EC2 (Web) + EBS (RDB) + S3
   EC2 (Web) + EBS (local storage) + Amazon
    RDS (RDB) + S3
   EC2 (Web) + EBS (local storage) + EC2
    (noSQL) + S3

   …Can use with more Amazon Services
Thank you!
It’s time to query …

CONTACT
Fullname: Vo Duy Tuan
Email: tuanmaster2002@yahoo.com
Phone: 0938 916 902
Website: http://bloghoctap.com

More Related Content

What's hot

Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecturepostrational
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesOtto Kekäläinen
 
WordPress Security & Backup
WordPress Security & Backup WordPress Security & Backup
WordPress Security & Backup Randy Barnes
 
Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3kidtangerine
 
J M Githeko Agenda Software installation – Apche, MySQL, PHP
J M Githeko Agenda Software installation – Apche, MySQL, PHPJ M Githeko Agenda Software installation – Apche, MySQL, PHP
J M Githeko Agenda Software installation – Apche, MySQL, PHPwebhostingguy
 
Async Tasks with Django Channels
Async Tasks with Django ChannelsAsync Tasks with Django Channels
Async Tasks with Django ChannelsAlbert O'Connor
 
Speed up Your Joomla Site for Ultimate Performance
Speed up Your Joomla Site for Ultimate PerformanceSpeed up Your Joomla Site for Ultimate Performance
Speed up Your Joomla Site for Ultimate PerformanceJoomlaDay Australia
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPressMicah Wood
 
DrupalCon Barcelona 2015
DrupalCon Barcelona 2015DrupalCon Barcelona 2015
DrupalCon Barcelona 2015Daniel Kanchev
 
Complete WordPress Setup (Description about Themes & Plugins Added)
Complete WordPress Setup (Description about Themes & Plugins Added)Complete WordPress Setup (Description about Themes & Plugins Added)
Complete WordPress Setup (Description about Themes & Plugins Added)Ciceer Ghimirey
 
Drupal debugging tips
Drupal debugging tipsDrupal debugging tips
Drupal debugging tipsAdolfo Nasol
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Projectxsist10
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Web Directions
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrideugenio pombi
 

What's hot (18)

Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecture
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themes
 
WordPress Security & Backup
WordPress Security & Backup WordPress Security & Backup
WordPress Security & Backup
 
Real-Time Django
Real-Time DjangoReal-Time Django
Real-Time Django
 
Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3
 
Presentation (PPT)
Presentation (PPT)Presentation (PPT)
Presentation (PPT)
 
J M Githeko Agenda Software installation – Apche, MySQL, PHP
J M Githeko Agenda Software installation – Apche, MySQL, PHPJ M Githeko Agenda Software installation – Apche, MySQL, PHP
J M Githeko Agenda Software installation – Apche, MySQL, PHP
 
Async Tasks with Django Channels
Async Tasks with Django ChannelsAsync Tasks with Django Channels
Async Tasks with Django Channels
 
Speed up Your Joomla Site for Ultimate Performance
Speed up Your Joomla Site for Ultimate PerformanceSpeed up Your Joomla Site for Ultimate Performance
Speed up Your Joomla Site for Ultimate Performance
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPress
 
DrupalCon Barcelona 2015
DrupalCon Barcelona 2015DrupalCon Barcelona 2015
DrupalCon Barcelona 2015
 
Complete WordPress Setup (Description about Themes & Plugins Added)
Complete WordPress Setup (Description about Themes & Plugins Added)Complete WordPress Setup (Description about Themes & Plugins Added)
Complete WordPress Setup (Description about Themes & Plugins Added)
 
Drupal debugging tips
Drupal debugging tipsDrupal debugging tips
Drupal debugging tips
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5
 
Dc kyiv2010 jun_08
Dc kyiv2010 jun_08Dc kyiv2010 jun_08
Dc kyiv2010 jun_08
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 

Viewers also liked

Scale with Microservices
Scale with MicroservicesScale with Microservices
Scale with MicroservicesVõ Duy Tuấn
 
Business Intelligence in Retail Industry
Business Intelligence in Retail IndustryBusiness Intelligence in Retail Industry
Business Intelligence in Retail IndustryVõ Duy Tuấn
 
Speed up with hiphop php 2014 01-22
Speed up with hiphop php 2014 01-22Speed up with hiphop php 2014 01-22
Speed up with hiphop php 2014 01-22Võ Duy Tuấn
 
Microservices in production
Microservices in productionMicroservices in production
Microservices in productionVõ Duy Tuấn
 
Microservices and docker
Microservices and dockerMicroservices and docker
Microservices and dockerVõ Duy Tuấn
 
How to Build Recommender System with Content based Filtering
How to Build Recommender System with Content based FilteringHow to Build Recommender System with Content based Filtering
How to Build Recommender System with Content based FilteringVõ Duy Tuấn
 
Chatbot in Sale Management
Chatbot in Sale ManagementChatbot in Sale Management
Chatbot in Sale ManagementVõ Duy Tuấn
 
Javascript unit testing framework
Javascript unit testing frameworkJavascript unit testing framework
Javascript unit testing frameworkVõ Duy Tuấn
 
Magento overview and how sell Magento extensions
Magento overview and how sell Magento extensionsMagento overview and how sell Magento extensions
Magento overview and how sell Magento extensionsVõ Duy Tuấn
 
How to build a Recommender System
How to build a Recommender SystemHow to build a Recommender System
How to build a Recommender SystemVõ Duy Tuấn
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPVõ Duy Tuấn
 
Reader.vn 2012 - The Book Of Life
Reader.vn 2012 - The Book Of LifeReader.vn 2012 - The Book Of Life
Reader.vn 2012 - The Book Of LifeVõ Duy Tuấn
 
Php psr standard 2014 01-22
Php psr standard 2014 01-22Php psr standard 2014 01-22
Php psr standard 2014 01-22Võ Duy Tuấn
 
Building a Recommendation Engine - An example of a product recommendation engine
Building a Recommendation Engine - An example of a product recommendation engineBuilding a Recommendation Engine - An example of a product recommendation engine
Building a Recommendation Engine - An example of a product recommendation engineNYC Predictive Analytics
 
Recommender system algorithm and architecture
Recommender system algorithm and architectureRecommender system algorithm and architecture
Recommender system algorithm and architectureLiang Xiang
 

Viewers also liked (19)

Scale with Microservices
Scale with MicroservicesScale with Microservices
Scale with Microservices
 
Business Intelligence in Retail Industry
Business Intelligence in Retail IndustryBusiness Intelligence in Retail Industry
Business Intelligence in Retail Industry
 
Speed up with hiphop php 2014 01-22
Speed up with hiphop php 2014 01-22Speed up with hiphop php 2014 01-22
Speed up with hiphop php 2014 01-22
 
Microservices in production
Microservices in productionMicroservices in production
Microservices in production
 
React introduction
React introductionReact introduction
React introduction
 
Microservices and docker
Microservices and dockerMicroservices and docker
Microservices and docker
 
How to Build Recommender System with Content based Filtering
How to Build Recommender System with Content based FilteringHow to Build Recommender System with Content based Filtering
How to Build Recommender System with Content based Filtering
 
Chatbot in Sale Management
Chatbot in Sale ManagementChatbot in Sale Management
Chatbot in Sale Management
 
Javascript unit testing framework
Javascript unit testing frameworkJavascript unit testing framework
Javascript unit testing framework
 
Magento overview and how sell Magento extensions
Magento overview and how sell Magento extensionsMagento overview and how sell Magento extensions
Magento overview and how sell Magento extensions
 
How to build a Recommender System
How to build a Recommender SystemHow to build a Recommender System
How to build a Recommender System
 
The legendary-book
The legendary-bookThe legendary-book
The legendary-book
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHP
 
Web optimization
Web optimizationWeb optimization
Web optimization
 
Reader.vn 2012 - The Book Of Life
Reader.vn 2012 - The Book Of LifeReader.vn 2012 - The Book Of Life
Reader.vn 2012 - The Book Of Life
 
Php psr standard 2014 01-22
Php psr standard 2014 01-22Php psr standard 2014 01-22
Php psr standard 2014 01-22
 
IoC and Mapper in C#
IoC and Mapper in C#IoC and Mapper in C#
IoC and Mapper in C#
 
Building a Recommendation Engine - An example of a product recommendation engine
Building a Recommendation Engine - An example of a product recommendation engineBuilding a Recommendation Engine - An example of a product recommendation engine
Building a Recommendation Engine - An example of a product recommendation engine
 
Recommender system algorithm and architecture
Recommender system algorithm and architectureRecommender system algorithm and architecture
Recommender system algorithm and architecture
 

Similar to Heavy Web Optimization: Backend

Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiJérémy Derussé
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & ToolsIan Barber
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionIan Barber
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariJoseph Scott
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
php & performance
 php & performance php & performance
php & performancesimon8410
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisationgrooverdan
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slidesmkherlakian
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersoazabir
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend frameworkAlan Seiden
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)dantleech
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统yiditushe
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Jeff Jones
 
Tips
TipsTips
Tipsmclee
 

Similar to Heavy Web Optimization: Backend (20)

Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
php & performance
 php & performance php & performance
php & performance
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slides
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
 
Download It
Download ItDownload It
Download It
 
Symfony Performance
Symfony PerformanceSymfony Performance
Symfony Performance
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
Tips
TipsTips
Tips
 

More from Võ Duy Tuấn

Log management system for Microservices
Log management system for MicroservicesLog management system for Microservices
Log management system for MicroservicesVõ Duy Tuấn
 
Multi-tenant Database Design for SaaS
Multi-tenant Database Design for SaaSMulti-tenant Database Design for SaaS
Multi-tenant Database Design for SaaSVõ Duy Tuấn
 
Mobile outsourcing best practices
Mobile outsourcing best practicesMobile outsourcing best practices
Mobile outsourcing best practicesVõ Duy Tuấn
 
Html5, css3 and the future of web technologies
Html5, css3 and the future of web technologiesHtml5, css3 and the future of web technologies
Html5, css3 and the future of web technologiesVõ Duy Tuấn
 
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 communityVõ Duy Tuấn
 
Xây dựng mạng xã hội bằng drupal
Xây dựng mạng xã hội bằng drupalXây dựng mạng xã hội bằng drupal
Xây dựng mạng xã hội bằng drupalVõ Duy Tuấn
 
Speed up zing me – ntvv2 code with PHP extension module
Speed up zing me – ntvv2 code with PHP extension moduleSpeed up zing me – ntvv2 code with PHP extension module
Speed up zing me – ntvv2 code with PHP extension moduleVõ Duy Tuấn
 
Hanoi php day 2010 program
Hanoi php day 2010   programHanoi php day 2010   program
Hanoi php day 2010 programVõ Duy Tuấn
 
Social network game service
Social network game serviceSocial network game service
Social network game serviceVõ Duy Tuấn
 

More from Võ Duy Tuấn (10)

Log management system for Microservices
Log management system for MicroservicesLog management system for Microservices
Log management system for Microservices
 
Multi-tenant Database Design for SaaS
Multi-tenant Database Design for SaaSMulti-tenant Database Design for SaaS
Multi-tenant Database Design for SaaS
 
Flutter introduction
Flutter introductionFlutter introduction
Flutter introduction
 
Mobile outsourcing best practices
Mobile outsourcing best practicesMobile outsourcing best practices
Mobile outsourcing best practices
 
Html5, css3 and the future of web technologies
Html5, css3 and the future of web technologiesHtml5, css3 and the future of web technologies
Html5, css3 and the future of web technologies
 
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
 
Xây dựng mạng xã hội bằng drupal
Xây dựng mạng xã hội bằng drupalXây dựng mạng xã hội bằng drupal
Xây dựng mạng xã hội bằng drupal
 
Speed up zing me – ntvv2 code with PHP extension module
Speed up zing me – ntvv2 code with PHP extension moduleSpeed up zing me – ntvv2 code with PHP extension module
Speed up zing me – ntvv2 code with PHP extension module
 
Hanoi php day 2010 program
Hanoi php day 2010   programHanoi php day 2010   program
Hanoi php day 2010 program
 
Social network game service
Social network game serviceSocial network game service
Social network game service
 

Recently uploaded

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
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
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"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
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"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
 
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
 
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
 

Recently uploaded (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
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
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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
 
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...
 
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
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"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
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"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
 
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
 
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
 

Heavy Web Optimization: Backend

  • 1. Heavy Web Optimization BACK-END <?php //from a PHP dev ?> Vo Duy Tuan PHP Developer from Reader.vn, Picto.vn & more…
  • 2. $who_am_I?  My Name is Võ Duy Tuấn  PHP 5 Zend Certified Engineer  Interests: PHP, Social Network, Optimize Web  Works:  Thegioididong  Reader.vn, Picto.vn CEO/Founder  Trainer  Freelancer  Consultant
  • 3. $table_of_content  Warm up: Some best practices  Back-end Optimization  De-normalization  Asynchronous processing  Caching  Scalability
  • 4. 1 Warm up: Some best practices
  • 5. 1.1. Smarty Trick a. Prevent recompile .tpl file: $smarty = new Smarty(); $smarty->compile_check = false; b. Compile all .tpl files: set_time_limit(1000); //do not interrupt $smarty->compileAllTemplates('.tpl',true);
  • 6. 1.2. Pagination  From  To
  • 7. 1.2. Pagination – Why?  How do we make pagination feature? mysql_query(‘SELECT COUNT(*) FROM tbl WHERE col LIKE “%word%”’) > Get total record > Get toal page > Build page number list with a simple loop mysql_query(‘SELECT * FROM tbl WHERE col LIKE “%word%” LIMIT 0,20’) > Get data of current page (page 1, with 20 rows/page) Do you have the answer  ?
  • 8. 1.3. Get enough data from remote server  Send HEAD to detect 404 error from remote URL  Read first bytes of remote file to detect image type,width/height
  • 9. 2 Back-end Optimization
  • 10. 2.1. Where is Back-end? “80% of the end-user response time is spent on the front- end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.”
  • 11. 2.2. Back-end Optimize Theory  Reduce disk In/Out  Reduce complex/fuzzy  Reduce budget
  • 12. 2.3. Debugging & Profiling  Nusphere Phped Debugger  Xdebug  top command  Apache bench
  • 13. 2.3.1. Nusphere Phped Debugger  Installation:  Step 1: Install php extension  Step 2: Install DBGbar addon for Firefox or DBG debugger on Chrome  Step 3: Update PHP.INI config  Restart your web server (if needed)
  • 15. 2.3.2. Xdebug  Installation:  Step 1: Install php extension  Step 2: Update PHP.INI config  Restart your server (if needed)
  • 16. 2.3.2. Xdebug PHP.INI [xdebug] zend_extension_ts = C:..php_xdebug-2.1.0-5.2-vc6.dll xdebug.profiler_output_dir = "C:xdebug" xdebug.profiler_output_name = "callgrind.%R.%t" xdebug.profiler_enable = 0 xdebug.profiler_append=0 xdebug.profiler_enable_trigger = 1 xdebug.extended_info=1 Usage: http://example.com/index.php?XDEBUG_PROFILE
  • 20. Somewhere in the dark…
  • 21. 3 De-normalization
  • 22. 3.1. What is De-normalization?  Most of use live with Relational DB.  What is normalization?  Database normalization is the process of organizing the fields and tables of a relational database to minimize redundancy and dependency .(Wiki)  What is De-normalization?  Denormalization is the process of attempting to optimise the read performance of a database by adding redundant data or by grouping data. (Wiki)
  • 23. 3.2. How to de-normalize?  Vertical Split.  Pre-calculated value.  Duplicate data.
  • 28. 3.3. Data correctness  Normalization = Correctness  Denormalization = Performance
  • 29. 4 Asynchronous processing
  • 31. 4.2. Job queue :: Gearman  http://gearman.org/
  • 32. But…. Apache can be a job queue,
  • 33. 4.3. Async Request function backgroundHttpPost($url, $prm = ''){ $p=parse_url($url); $fp = fsockopen($p['host'], isset($p['port'])?$p['port']:80, $en, $es, 30); if (!$fp) return false; else { $out = "POST ".$p['path']."?".$p['query']." HTTP/1.1rn"; $out.= "Host: ".$p['host']."rn"; $out.= "Content-Type: application/x-www-form-urlencodedrn"; $out.= "Content-Length: ".strlen($prm)."rn"; $out.= "Connection: Closernrn"; if ($prm != '') $out.= $prm; fwrite($fp, $out); fclose($fp); return true; } } Usage: $taskUrl = 'http://picto.vn/task/deletephoto'; backgroundHttpPost($taskUrl, 'photoid=' . $myPhoto->id);
  • 34.
  • 35. 5 Caching
  • 36. 5.1. What is caching?
  • 37. 5.2. What is APC?  Alternative PHP Cache – APC  Free PHP Extension  PHP Opcode cache  Support User data cache  Run on SAME machine with PHP  NOT support multi servers
  • 38.
  • 40.
  • 41.
  • 43.
  • 44. 5.5. APC Tip  Opcode your web code only  Disable APC for PhpMyAdmin <Directory "/mysite/public_html/"> ... php_admin_flag apc.cache_by_default On </Directory <Directory "/mysite/public_html/phpmyadmin/"> ... php_admin_flag apc.cache_by_default Off </Directory>
  • 45. 2.6. APC Tip..  Cache STRING is better than ARRAY  Long Time To Live better than Short  Case study:  Caching for Feed System:
  • 49. AFTER
  • 50. Short TTL make fragmentation
  • 51. Short TTL make fragmentation
  • 52. 6 Cloud computing - AWS  Amazon Elastic Compute Cloud – Amazon EC2 + EBS  Amazon Simple Storage Service – Amazon S3  Amazon Simple Email Service – Amazon SES
  • 54. 6.1. Amazon EC2 (cont.) 5
  • 56. 6.2. Amazon S3 (cont.) 5
  • 57. 6.2. Amazon S3 (cont.) 5
  • 58. 6.3. Amazon SES  1,000,000 emails = $100 5  Support SMTP
  • 59. 6.3. Amazon SES (cont.) 5
  • 60. 6.4. Adapt to AWS for scalability  Local server (Web & RDBMS) + S3 5  EC2 (Web) + EBS (RDB) + S3  EC2 (Web) + EBS (local storage) + Amazon RDS (RDB) + S3  EC2 (Web) + EBS (local storage) + EC2 (noSQL) + S3  …Can use with more Amazon Services
  • 61. Thank you! It’s time to query … CONTACT Fullname: Vo Duy Tuan Email: tuanmaster2002@yahoo.com Phone: 0938 916 902 Website: http://bloghoctap.com

Editor's Notes

  1. Determine the existing size of your shared memory segment: sysctl -a | grep shmmax Set sysctl -w kernel.shmmax=50331648
  2. Determine the existing size of your shared memory segment: sysctl -a | grep shmmax Set sysctl -w kernel.shmmax=50331648
  3. More installation LAMP: http://jonathanhui.com/building-ec2-amazon-linux-lamp
  4. Mailchimp: http://mailchimp.com/pricing/