CSC 2720 Building Web Applications Improving Web Application Performance.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Database Tuning Principles, Experiments and Troubleshooting Techniques Baseado nos slides do tutorial com o mesmo nome da autoria de: Dennis Shasha
Performance Testing - Kanwalpreet Singh.
CHAPTER 15 WEBPAGE OPTIMIZATION. LEARNING OBJECTIVES How to test your web-page performance How browser and server interactions impact performance What.
Amazon CloudFront An introductory discussion. What is Amazon CloudFront? 5/31/20122© e-Zest Solutions Ltd. Amazon CloudFront is a web service for content.
MCTS GUIDE TO MICROSOFT WINDOWS 7 Chapter 10 Performance Tuning.
Session 13 Active Server Pages (ASP) Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Technical Architectures
1 Caching in HTTP Representation and Management of Data on the Internet.
1 Chapter 12 Working With Access 2000 on the Internet.
PHP (2) – Functions, Arrays, Databases, and sessions.
Analysis and Performance Information Systems 337 Prof. Harry Plantinga.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Module 8: Monitoring SQL Server for Performance. Overview Why to Monitor SQL Server Performance Monitoring and Tuning Tools for Monitoring SQL Server.
Web Application Architecture: multi-tier (2-tier, 3-tier) & mvc
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
22-Aug-15 | 1 |1 | Help! I need more servers! What do I do? Scaling a PHP application.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
1 Web Servers (IIS and Apache) Outline 9.1 Introduction 9.2 HTTP Request Types 9.3 System Architecture 9.4 Client-Side Scripting versus Server-Side Scripting.
How the Web Works. WWW – part of the Internet (others: , FTP, Telnet) Loaded to a Server | Viewed in a Browser (Client) Client: Request & Render.
INTRODUCTION TO WEB DATABASE PROGRAMMING
6/1/2001 Supplementing Aleph Reports Using The Crystal Reports Web Component Server Presented by Bob Gerrity Head.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Research on cloud computing application in the peer-to-peer based video-on-demand systems Speaker : 吳靖緯 MA0G rd International Workshop.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Computer System Architectures Computer System Software
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
MCTS Guide to Microsoft Windows 7
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
Global NetWatch Copyright © 2003 Global NetWatch, Inc. Factors Affecting Web Performance Getting Maximum Performance Out Of Your Web Server.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 21 - Web Servers (IIS, PWS and Apache) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
Ideas to Improve SharePoint Usage 4. What are these 4 Ideas? 1. 7 Steps to check SharePoint Health 2. Avoid common Deployment Mistakes 3. Analyze SharePoint.
Web Caching By Neeraj Agrawal. Caching Caching is widely used for improving performance in many context( e.g processor caches in hardware, buffer pool.
Chapter 6 Server-side Programming: Java Servlets
1 Welcome to CSC 301 Web Programming Charles Frank.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
“Load Testing Early and Often” By Donald Doane Presentation to the Rockville MDCFUG.
Empirical Quantification of Opportunities for Content Adaptation in Web Servers Michael Gopshtein and Dror Feitelson School of Engineering and Computer.
PERFORMANCE ENHANCEMENT IN ASP.NET By Hassan Tariq Session #1.
2007cs Servers on the Web. The World-Wide Web 2007 cs CSS JS HTML Server Browser JS CSS HTML Transfer of resources using HTTP.
Web Server.
Introduction and Principles Web Server Scripting.
Infrastructure for Data Warehouses. Basics Of Data Access Data Store Machine Memory Buffer Memory Cache Data Store Buffer Bus Structure.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Unit 1 – Web Concepts Instructor: Brent Presley.
Accelerating PHP Applications Ilia Alshanetsky O’Reilly Open Source Convention August 3rd, 2005.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Web Cache. What is Cache? Cache is the storing of data temporarily to improve performance. Cache exist in a variety of areas such as your CPU, Hard Disk.
LOAD RUNNER. Product Training Load Runner 3 Examples of LoadRunner Performance Monitors Internet/Intranet Database server App servers Web servers Clients.
Cofax Scalability Document Version Scaling Cofax in General The scalability of Cofax is directly related to the system software, hardware and network.
Introduction to Performance Tuning Chia-heng Tu PAS Lab Summer Workshop 2009 June 30,
Enhance Your Page Load Speed And Improve Traffic.
GENERAL SCALABILITY CONSIDERATIONS
Web Protocols and Practice
WWW and HTTP King Fahd University of Petroleum & Minerals
Introduction and Principles
Platform as a Service.
Web Caching? Web Caching:.
PHP / MySQL Introduction
Scaling and Performance
Chapter 27 WWW and HTTP.
Lecture 1: Multi-tier Architecture Overview
Moodle Scalability What is Scalability?
Lecture 34: Testing II April 24, 2017 Selenium testing script 7/7/2019
Yale Digital Conference 2019
Presentation transcript:

CSC 2720 Building Web Applications Improving Web Application Performance

Outline  Introduction  Locating the bottleneck  Improvement Methods

Introduction  To improve the performance of a web application could mean  To reduce latency  i.e., to reduce the time delay between sending a request and receiving the corresponding response, or between sending a request and receiving all the page components, such as images, that are needed to render the page.  To serve as many concurrent requests as possible without failing or exceeding a response time limit  Response time – the time a server takes to serve a request

PHP Performance Optimization  Obtaining good performance is not merely writing fast PHP scripts. High performance PHP requires a good understanding of the underlying hardware, the operating system and supporting software such as the web server and database.  Source: debugging-php.phphttp://phplens.com/lens/php-book/optimizing- debugging-php.php  Often involves trade-off among CPU, storage, bandwidth and other resource requirements

Factors that affect the performance  Running out of resources  Processors  Memory  Storage  Network bandwidth  # of the maximum database connections  Poorly designed database schema and queries  Poorly written PHP code  Too much disk access

Locating the Bottlenecks – Profiling  To measure the behavior of a server-side script as it executes, particularly frequency and duration of function calls (Ref: Wikipedia)  Help you detect which parts of your code are worth your attention (e.g., functions that are called the most, functions that take a long time to run)  Can be used to analyze the performance of a database indirectly by measuring the functions that interact with the database (e.g., The mysqli_* functions)  e.g. of Profiling Tools  XDebug:

 Tests a web application for its robustness, availability, and error handling capabilities under a heavy load, particularly to ensure the software doesn't crash in conditions of insufficient computational resources (such as memory or disk space), unusually high concurrency, or denial of service attacks. (Ref: Wikipedia)  Use in conjunction with other tools to find out  The maximum # of requests/users a server can handle before failing or slowing down significantly  The bottleneck (i.e., which resource run out first?)  The average time a page and its components to fully load. Locating the Bottlenecks – Stress Tests

 Microsoft Web Application Stress Tool Microsoft Web Application Stress Tool  Can emulate HTTP requests (with parameters) from clients  Can generate large number of requests within a short period of time (stress test)  Can help you gather info such as the average and the highest latency experienced from accessing a URL

Locating the Bottlenecks – System Info  Show the usage and availability of various system resources (e.g., CPU, memory, virtual memory, I/O). The usage can be the overall usage or usage by individual processes.  Use in conjunction with stress tests tools to locate the bottleneck of a server  e.g. of tools  "Task Manager" on Windows OS  The command "tops" on most Unix/Linux OS

Improvement Methods Small changes that could make a big difference. 1.PHP accelerators (Opcode compiler + Opcode cache) 2.Content caching  Utilizing client's and proxy's cache  Cache output 3.Server-Side web proxy 4.Compression 5.Connection pooling

Improvement Methods Fine tuning your web applications, servers, and OS 6.Reducing number of HTTP requests 7.Query optimization 8.Optimizing PHP code 9.Additional methods that make a page loads faster 10.Tuning the Server (Apache)

1. PHP Accelerators  Typically made up of an opcode compiler and an opcode cache  Opcode compiler – compiles PHP code into opcode  Opcode cache – keeps frequently used compiled PHP scripts in memory  A PHP accelerator can help reducing the response time of PHP scripts significantly because  Interpreting opcode is faster than interpreting PHP code  Loading opcode from memory is faster than loading PHP scripts from disk  List of PHP accelerators: 

1.1 How PHP Accelerators Work Source:

2.1 Content Caching – Utilizing Client and Proxy Caches  Request clients/proxies to cache reusable components (e.g., images, scripts and stylesheets) in order to avoid retransmitting the same components Proxy Client A Client B Server index.php x.jpg y.css To illustrate, suppose Clients A and B share a proxy server. The HTML page generated by index.php needs x.jpg and y.css. Only x.jpg and y.css are cacheable.

Proxy Client A Client B Server Proxy Client A Client B Server The 1 st time client A requests index.php from the server, all three files need to be transferred from the server. After the request, x.jpg and y.css are chached in the client A's and proxy's cache. index.php x.jpg y.css index.php x.jpg y.css

Proxy Client A Client B Server If client B accesses index.php after client A has accessed the same file, then client B could load the page faster because the proxy server only needs to retrieve the HTML content from the server. In practice, there could be more than one proxy servers between the clients and the server. Proxy Client A Client B Server In subsequent requests, client A only needs to download the HTML page generated by index.php. index.php x.jpg y.css index.php x.jpg y.css

2.1 Content Caching – Utilizing Client and Proxy Caches  Use the Expires or Cache-Control header fields to tell the clients and proxies how a component should be cached e.g.,  When should the component be considered as expired?  Is the component cacheable?  Recommendations  For static components: implement a "Never expire" policy by setting far future Expires header.  For dynamic components: use an appropriate Cache-Control header to help clients with conditional requests. Cache-Controlconditional requests

2.1 Content Caching – Utilizing Client and Proxy Caches  For examples  To indicate that a component expires on a fixed time and date Expires: Sat, 11 Apr :00:00 GMT  To indicate that a component expires in one hour (relative to the access time) and the client must revalidate the content with the server when the component becomes stale Cache-Control: max-age=3600, must-revalidate  To set caching policy for static components, you can configure the web server.  To set up expiration policy for different files with Apache, see module mod_expires or these examples. mod_expiresexamples  To set up default header values for different files with Apache, see module mod_headers or these examples.mod_headersexamples

2.1 Content Caching – Utilizing Client and Proxy Caches  References and Reading Materials  Caching Tutorial  Contains specific info about how (and how not) to cache   Working with cached pages in PHP   HTTP conditional requests in PHP  304/index.en.html 304/index.en.html  Use Server Cache Control to Improve Performance 

2.2. Content Caching – Reusing Generated Output  If a script only generates new content periodically, cache the generated output to avoid executing code and querying database for every request.  Examples of cacheable output  List of high scores for an online game  List of products on an e-commerce website in which the products are updated daily  PHP examples about output caching  Caching output in PHP   Output Caching with PHP 

3. Server-Side Web Proxy  Use a web proxy at the server side to relieve the web server from serving frequently requested static files  An example of web proxy: SquidSquid 

4. Compression  Reduce the data size before transmitting 1.(Online) Use HTTP Compression – Compress textual data on the fly before sending them to a clientHTTP Compression  Can typically reduce the size of textual data by 70% 2.(Offline) Use compression tools to reduce the file size of JavaScript, CSS, Images, Video, etc.  The compression tools must not change the file format or the content of these files. Otherwise the files cannot be referred from HTML files.  e.g., use optipng for PNGs, gifsicle for GIFs and jpegoptim for JPGs

4.1. Compression – HTTP Compression  A publicly defined way to compress textual content transferred from web servers to browsers  Compression is done at the server.  Built into HTTP 1.1 and is supported by most browsers  Drawback: Takes time and CPU cycles to compress  Ref:  Using HTTP Compression in PHP  Configure php.ini to enable automatic HTTP compression  zlib runtime configuration (  Perform HTTP compression in PHP scripts programmatically  Examples of using ob_gzhandler (

5. Connection Pooling (Why?)  A database connection incurs overhead – it requires resources to create the connection, authenticate it, maintain it, and then release it when it is no longer required.  The overhead is particularly high for Web-based applications.  A server-side script typically opens a connection, performs few queries, and then close the connection.  Often, more effort is spent connecting and disconnecting than is spent during the interactions themselves.  Ref: IBM WebSphere App. Server – What is Connection Pooling?IBM WebSphere App. Server – What is Connection Pooling?

5. Connection Pooling  A connection pool is a cache of opened database connections.  When a script needs to establish a connection to the database, a connection is selected from the pool if one is available. Otherwise a new connection is created.  When a script closes the connection, the connection is not actually closed but returned to the pool so that the connection can be reused by other scripts.  Note: Implementing a connection pool is not easy. Usually we just use it if it is available.

5.1. Connection Pooling in PHP  PHP's Persistent ConnectionPersistent Connection  Use mysql_pconnect() to open a persistent database connection  There is no equivalence in MySQLImproved ( mysqli ) extension.  Must be used with care because changes made to the database states, such as setting autocommit to "off", will affect the next script that uses the connection.  Other connection pooling solutions:  SQL Relay:  Apache Module mod_dbd:

6. Reducing # of HTTP Requests (Why?)  A large portion of the total response time to create a fully rendered page is spent on downloading the page components like images, stylesheets, JavaScript, etc.  Some browsers only allow at most two concurrent requests per server. That means the page components have to take turn to load.  Ref:

6. Reducing # of HTTP Requests  Reducing # of components  reducing # of HTTP requests  Page loads faster  Methods to reduce the # of page components  Combine multiple stylesheets into one  Combine multiple scripts into one  CSS Sprites – Tile multiple images into one image and then make use CSS to clip the needed image from the combined image. CSS Sprites

7. Query Optimization  Tune DB Schema  First three normal forms  help ensure data integrity  Denormalization – a process that attempts to optimize the performance of a database by adding redundant data or by grouping data (but makes maintaining data integrity difficult).  Query only what you really need  e.g., instead of using "SELECT *", select only the columns you need and use LIMIT to limit the number of rows retrieved from the DB  Make use of indexes to improve the performance of data retrieval  Take a database course …  Ref: How to Optimize Queries (Theory an Practice) 

8. Optimizing PHP Code  Make use of output buffer  See PHP Output Bufering Control: <?php ob_start(); // Start output buffering // All the output are kept in memory instead // of sending to the client. ?> Foo <?php echo "Blah Blah Blah"; ?> <?php ob_end_flush(); // Flush everything in the output buffer // to the client at once. ?>

8. Optimizing PHP Code echo $str1, " ", $str2, " ", $str3; executes faster than echo $str1. " ". $str2. " ". $str3;  Note: This only works with echo, which is a function that can take several strings as arguments.  If you have CPU-intensive tasks to perform, consider implement them as C extensions.  Use the predefined functions (as oppose to writing your own functions) whenever possible

8. Optimizing PHP Code  Instead of writing for ($i=0; $i < count($array); $i++) … Use a variable to store the array size and rewrite the loop as $array_size = count($array); for ($i=0; $i < $array_size; $i++) …  More tips about optimizing PHP code can be found at

9. Additional Methods that Make a Page Loads Faster  Post-load Components  Load the less important components on the background  Preload Components  Anticipating what components are needed in the future and pre-load them (i.e., utilizing browser's idle time)  Split Components Across Domains  Maximize parallel downloads (a browser may only issue a few HTTP request in parallel to the same sever)  Make sure you're using not more than 2-4 domains because of the DNS lookup penalty.  Ref: Best Practices for Speeding Up Your Web Site (

10. Tuning the Server (Apache)  SendBufferSize – Size of output buffer  MaxClients – Maximum # of clients  StartServers – The number of child processes to create at start up  MinSpareServers, MaxSpareServers – The number of idle child processes to keep alive  Keep-alive – tells the server to reuse the same socket connection for multiple HTTP requests to reduce the overhead of frequent connects  Source:

Scaling  To improve the performance by introducing more machines (to host more servers)  Server Clusters  Database Replication  Improve performance or availability of the whole database system  MySQL Replication (

References  Best Practices for Speeding Up Your Web Site   Performance Research, Part 1: What the 80/20 Rule Tells Us about Reducing HTTP Requests   Performance Research, Part 2: Browser Cache Usage - Exposed!   Practical PHP Performance  performance /page3.html performance /page3.html