Web Performance Optimization
-
Upload
pavel-paulau -
Category
Technology
-
view
1.260 -
download
0
description
Transcript of Web Performance Optimization
Web Performance Optimization
2010 © Pavel Paulau
Getting started
2
• Look into web front-ends performance
• Learn how to- Estimate and track web performance- Analyze and diagnose page bottlenecks- Make website faster easily without code modification and eye candy losses
• Forget for a hour about load, transactions and servers
3
End user experienceEnd user experience1
Automated web performance testingAutomated web performance testing2
In-depth performance analysisIn-depth performance analysis3
Effective content delivery and transformationEffective content delivery and transformation4
Optimization examplesOptimization examples5
ConclusionConclusion6
Performance aspects
4
• AvailabilityThe amount of time an application is available to the
end user.
• Response timeThe amount of time it takes for the application to respond
to a user request.
• ThroughputThe rate at which application-oriented events occur.
• UtilizationThe percentage of the theoretical capacity of a
resource that is being used.
Behind the scene
5
• Just one user’s click lead to- Tens of HTTP requests- Hundreds of XHR calls- Kilobytes of network traffic- Multiple CPU calls- Expensive IO operations
• However, the end user doesn’t know anything about HTTP, web technologies, browsers and servers
• The only thing the user experiences is a page load time
Challenges
6
• Traditional performance testing techniques do not reflect real browser behavior
• Dependence on connection quality
• Multiple browsers and versions of browsers
• Lots of components and pages
• Third-party components
• A false view of the performance bottlenecks
Browsers multiplicity
7
Firefox 3.x30.5
Opera 101.2
Chrome 57.6
IE 68.1Chrome 6
2.7
IE 829.3
Safari 52.6
IE 713.9
Safari 41.1
Browser Connections per Hostname* II Scripts Script* II Scripts Stylesheet* II Scripts Image* Async. Scripts* Cache Redirects*Chrome 5 6 Yes Yes Yes No YesChrome 6 6 Yes Yes Yes No YesFirefox 3.x 6 Yes Yes Yes Yes YesIE 6 2 No No No No NoIE 7 2 No No No No NoIE 8 6 Yes Yes No No NoOpera 10 8 No No No No NoSafari 4 6 Yes Yes Yes No NoSafari 5 6 Yes Yes Yes No Yes
* browserscope.org
Different browsers offer different performance
8
Source: Gomez Real-User Monitoring
> Real users around the world> Broadband
> 466M pages over 30 days> 200+ sites
Response time components
9
Server side Content delivery Rendering
Outside the application -still part of our responsibility
Critical forWeb 2.0
application
80-90% of the end-user response time is spent on the frontend
Web performance anatomy
10
ServerBrowser
Latency
HTTP
Cache
ParsingLayoutingRendering
Ads, widgets, analytics
ImagesCSSJavaScriptFlash
DNS Server
3rd-partyservers
Internet
AJAX/XHRIE
FirefoxChrome
SafariOpera
Performance impact
11
• E-commerce applications- People stay on website longer and view more pages
- People perceive business to be more trustworthy
- Significantly decreased visitor frustration levels
- Google uses site speed in web search ranking
• Enterprise applications- Faster responses keep users more attentive and
concentrated
- Some business processes require extremely fast interactions
12
End user experienceEnd user experience1
Automated web performance testingAutomated web performance testing2
In-depth performance analysisIn-depth performance analysis3
Effective content delivery and transformationEffective content delivery and transformation4
Optimization examplesOptimization examples5
ConclusionConclusion6
Performance metrics
13
There are two basic approaches to performance estimation• Time-driven testing – measuring absolute load time
- Time to first byte
- Time to first impression
- onLoad time
- Fully loaded time
• Rank-driven testing – based on best practices- Yahoo! YSlow grades
- Google Page Speed scores
- dynaTrace AJAX edition ranks
Test automation framework
14
Analyst workstation Test environment LAMP (WAMP) Server
Show Slow
WebPagetest
URL Blast
Selenium Remote-Control
Test Controller(Java, C#, Python,Ruby, Perl, PHP)
Advantages
15
• Open source solution> Free and flexible
• Websites testing with real browsers, not via HTTP requests
> Parsing and rendering aren’t ignored
• End-to-end process> Benchmark → Analysis → Optimization
• Scripting using the most popular languages> Java, C#, Python, Ruby, PHP, Perl.
Features. Results storage and visualization
16
• Test results stored in MySQL database. Reliable and accessible approach
• “Measurements over time” feature provides the continuous control support
• Screen shots, waterfall views, visual comparison, video capture, content and domain breakdowns… not a full list of analytic solutions
Features. WAN emulation
17
• Using Dummynet it’s possible to define the following connection options:
- Bandwidth download speed- Bandwidth upload speed- Network latency- Packet loss
• That’s an extremely important feature for worldwide applications without CDN
Features. Optimization checklist
18
19
End user experienceEnd user experience1
Automated web performance testingAutomated web performance testing2
In-depth performance analysisIn-depth performance analysis3
Effective content delivery and transformationEffective content delivery and transformation4
Optimization examplesOptimization examples5
ConclusionConclusion6
Available tools
20
• Free and open source tools available for almost any browser:- Firebug with add-ons (Firefox)
- dynaTrace Ajax Edition (IE)
- Speed Tracer (Chrome)
- Web Inspector/Developer Tools (Safari/Chrome)
- HttpWatch (IE/Firefox)
- Dragonfly (Opera)
• These tools vary in functionality, flexibility and advantages, but together provide amazing capabilities
21
It’s possible just to grade web pages total performance with any general rating system
or KPI’s.
Performance Ranking
22
Sometimes it is not unlikely to notice a problem at a glance – just with HTTP waterfall charts. Blocking issues, non-existent elements, too long requests could be found within a minute.
HTTP waterfall charts
23
Understanding of what is really going on inside of browser is a key point of page speed
analysis.
Timeline analysis
24
When JavaScript becomes a trouble it’s extremely easy to analyze code execution and find the most
expensive call
JavaScript Profiling
25
Not only JS-scripts but style spreadsheets lead to performance issues.Additional analysis features provide an ability to controls the effectiveness of CSS usage
CSS Usage Analysis
26
The most delicious feature of these tools is a strong possibility to get an instantaneous advice
based on diverse best practices
Optimization advices
27
End user experienceEnd user experience1
Automated web performance testingAutomated web performance testing2
In-depth performance analysisIn-depth performance analysis3
Effective content delivery and transformationEffective content delivery and transformation4
Optimization examplesOptimization examples5
ConclusionConclusion6
2828
• Eliminate wasteful work
• Identify the action that's consuming most of user response time.
• Make the application do that action less often.
• Make the application do that action faster.
The fastest way to do something is don’t do it
Common optimization principles
2929
Google, Yahoo! and dynaTrace specialists provide and constantly update best practices on
Cache optimization
Round-trip times minimization
Components size minimization
Parsing and rendering optimization
Available best practices
Cache optimization
30
• A first-time visit to a page may require several HTTP requests to load all the components.
• By using Expires or Cache-Control headers these components become cacheable, which avoids unnecessary HTTP requests on subsequent page views.
• Expires headers are most often associated with images, but they can and should be used on all page components including scripts, stylesheets and Flash.
Round-trip times minimization
31
• Decreasing the number of components on a page reduces the
number of HTTP requests and network packets required to
render the page, resulting in faster page loads.
• Common way to reduce the number of
components includes- Combine multiple scripts into one script
- Combine multiple CSS files into single stylesheet
- Use CSS Sprites and image maps
Round-trip times minimization
32
• Inserting a redirect between the user and the final HTML document delays everything on the page since nothing on the page can be rendered and no components can be downloaded until the HTML document arrives.
• Reference to missing resources is a time wasting process
XHR calls minimization
33
• JavaScript and XmlHttpRequests are the basis for what in general is called AJAX. Frameworks like jQuery make it very easy to make AJAX calls in order to retrieve additional content from the server.
• When the user navigates to the next page we request the next page via an AJAX call and refresh the DOM. This avoids a full round-trip and avoids the browser reloading the whole page.
• A mistake that is often made is that too much information is fetched dynamically with too many calls.
Component size minimization
34
• Most modern browsers support data compression for HTML, CSS, and JavaScript files. This allows content to be sent over the network in more compact form and can result in a dramatic reduction in download time.
• Gzip is the most popular and effective compression method currently available and generally reduces the response size by about 70%.
Component size minimization
35
• Minification removes unnecessary characters from a file to reduce its size, thereby improving load times.
• When a file is minified, comments and unneeded white space characters (spaces, newlines, and tabs) are removed. This improves response time since the size of the download files is reduced.
• Properly formatting and compressing images can save many bytes of data.
Rendering optimization
36
• JavaScript scripts block parallel downloads - to help the page load faster, move scripts to the bottom of the page if they are deferrable.
• Moving stylesheets to the document head element helps pages appear to load quicker since this allows pages to render progressively.
• Specifying a width and height for all images allows for faster rendering by eliminating the need for unnecessary reflows and repaints.
Effective DOM manipulation
37
• Many JavaScript libraries provide nice visual effects, e.g: dynamic popup menus, accordion effects, etc.
• Where most of these frameworks do a good job on sample web sites, some of them do not perform well on real life pages with large DOMs.
• It is important to analyze the impact of visual effects on the browser’s CPU, the rendering engine and the overall web site performance.
3-rd party components
38
• You can't control it all
• Speed up what you can
Ensure that things you have control over are lightening fast
• Defer everything you can't control
Make sure it’s the last thing that is called on the page before it's done loading
39
End user experienceEnd user experience1
Automated web performance testingAutomated web performance testing2
In-depth performance analysisIn-depth performance analysis3
Effective content delivery and transformationEffective content delivery and transformation4
Optimization examplesOptimization examples5
ConclusionConclusion6
Sotheby’s landing page
40
• Page load time (IE7, 1024/512 Kbps, 50 ms RTT)• 15.5 seconds (first view)• 7.5 seconds (repeat view)
• Google Page Speed score• 67 (D)
• Yahoo! YSlow grade• 63 (D)
• dynaTrace AJAX edition rank• 73 (C)
Optimization list
41
CSS merging eliminates 33 HTTP requests.
JS merging eliminates 16 HTTP requests.
CSS, JS and HTML minimization saves about 160 kilobytes of network traffic.
Images optimization reduce the page size by about 130 kilobytes.
GZip compression removes 420 kilobytes of unnecessary network traffic.
Cache tweaks (Expire headers and ETag optimization) to make repeat load faster.
Automatic adjustments with Apache mod_pagespeed.
Page resources
42
Before
After
Performance metrics
43
15.5 s
5.5 s
First View7.5 s
2.5 s
Repeat View
Page load time – 3x faster
Optimization ranks
67 (D)
91 (A)
Page Speed
63 (D)
90 (A)
YSlow
73 (C)
96 (A)
dynaTrace
44
End user experienceEnd user experience1
Automated web performance testingAutomated web performance testing2
In-depth performance analysisIn-depth performance analysis3
Effective content delivery and transformationEffective content delivery and transformation4
Optimization examplesOptimization examples5
ConclusionConclusion6
Resume
45
• Websites performance matters
• Traditional performance testing techniques cover only smallest part of the end user experience
• There are methods and tools to test, analyze and optimize websites speed
• These methods don’t contradict common performance testing approaches but complement them
Do not ignore front-ends!
46
Books- High Performance Web Sites
- Even Faster Web Sites
- Website Optimization
- Complete Web Monitoring
- High Performance JavaScript
Web- Google Web Performance Best Practices
- Yahoo! Best Practices for Speeding Up Your Web Site
- DynaTrace Best Practices on Web Site Performance Optimization
Best practices
47
Tools
Google Page Speed Tools Familyhttp://code.google.com/speed/page-speed/
dynaTrace AJAX Editionhttp://ajax.dynatrace.com/ajax/en/
Yahoo! YSlowhttp://developer.yahoo.com/yslow/
WebPagetesthttp://www.webpagetest.org/
Show Slowhttp://www.showslow.com/
Let's Make the Web Fasterhttp://code.google.com/intl/en-EN/speed/tools.html