ASP.NET Site Performance Secrets

ASP.NET Site Performance Secrets
eBook: $35.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $95.98    Print cover: $59.99
save 44%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Speed up your ASP.NET website by identifying performance bottlenecks that hold back your site's performance and fixing them
  • Tips and tricks for writing faster code and pinpointing those areas in the code that matter most, thus saving time and energy
  • Drastically reduce page load times
  • Configure and improve compression – the single most important way to improve your site's performance
  • Written in a simple problem-solving manner – with a practical hands-on approach and just the right amount of theory you need to make sense of it all


Book Details

Language : English
Paperback : 456 pages [ 235mm x 191mm ]
Release Date : October 2010
ISBN : 1849690685
ISBN 13 : 9781849690683
Author(s) : Matt Perdeck
Topics and Technologies : All Books, Web Development, .NET, Microsoft SQL Server

Table of Contents

Chapter 1: High Level Diagnosis
Chapter 2: Reducing Time to First Byte
Chapter 3: Memory
Chapter 4: CPU
Chapter 5: Caching
Chapter 6: Thread Usage
Chapter 7: Reducing Long Wait Times
Chapter 8: Speeding up Database Access
Chapter 9: Reducing Time to Last Byte
Chapter 10: Compression
Chapter 11: Optimizing Forms
Chapter 12: Reducing Image Load Times
Chapter 13: Improving JavaScript Loading
Chapter 14: Load Testing
  • Chapter 1: High Level Diagnosis
    • Assuring good performance
      • Continuous monitoring
      • Setting performance goals
      • Iterative improvements
      • Monitoring services
    • High-level diagnosis with Waterfall charts
    • Creating a Waterfall chart using Firebug
      • Installing Firebug
      • Creating the Waterfall chart
      • Interpreting the Waterfall chart
        • Request and response information
        • Timeline information
        • Page-level information
        • Saving information
    • Categorizing bottlenecks using Waterfall charts
      • Scenario 1: Main .aspx file takes long to arrive
      • Scenario 2: Main .aspx file takes long to load over the Internet
      • Scenario 3: Images take long to load
      • Scenario 4: JavaScript file blocks rendering
    • Waterfall generators for other browsers
      • Fiddler (browser-independent)
      • Internet Explorer via WebPagetest
      • Google Chrome
      • Apple Safari
    • More Waterfall chart generators
    • Find out more
    • Summary
  • Chapter 2: Reducing Time to First Byte
    • Pinpointing bottlenecks
      • Memory
        • Windows Server 2003
        • Windows Vista, Windows Server 2008, or Windows 7
        • Simulating a memory shortage
      • Caching
      • CPU
      • Thread usage
      • Long wait times
    • Additional measures
      • Deployment
        • Building projects in release mode
        • Publishing your website
        • Disabling debug mode
        • Reducing number of assemblies
      • Reducing round trips
        • Using Server.Transfer instead of Response.Redirect
        • Always specifying the default file in URLs
        • Permanent redirects
        • Minimizing CNAME records
      • SSL
      • Unwanted requests
        • Search engine bots
        • Hotlinking
        • CAPTCHA
        • Scrapers
        • Usability testing
    • Find out more
    • Summary
  • Chapter 3: Memory
    • Managed resources
      • Life cycle
      • Generations
      • Large Object Heap
      • Counters
      • CLR profiler
      • Garbage collector versions
      • Acquire late
      • Release early
      • Using StringBuilder to concatenate strings
        • Using StringBuilder
        • When not to use StringBuilder
        • StringBuilder capacity
      • Using Compare for case-insensitive compares
      • Using Response.Write buffer
      • Pooling objects over 85 KB
    • Unmanaged resources
      • IDisposable
      • Counters
    • Sessions
      • Reducing session state life time
      • Reducing space taken by session state
      • Using another session mode
      • Stop using session state
    • Find out more
    • Summary
  • Chapter 4: CPU
    • Identifying bottlenecks
    • Tools
    • Data access
      • Connection pooling
      • DataSet versus List
      • Returning multiple result sets
      • Sending multiple inserts in one go
      • Using native data providers
    • Exceptions
      • Revealing the time taken by exceptions
      • Counters
    • DataBinder.Eval
    • Garbage collector
    • Threading
    • StringBuilder
    • Regex instantiation
    • UtcNow
    • Foreach
    • Virtual properties
    • Avoid unnecessary processing
    • Trimming HTTP pipeline
    • Find out more
    • Summary
  • Chapter 5: Caching
    • Browser caching
      • OutputCache directive
      • Enabling caching in code
      • Disabling caching in code
    • Proxy caching
      • Caching different versions of the same page
      • Cookies
      • Removing query string from URL
        • URLRewrite extension to IIS 7
        • RewritePath method in Global.asax
        • Resetting the form action attribute
    • Output caching
      • What to cache and what not to cache
      • Enabling output caching
      • Output cache example
      • VaryByParam
      • VaryByHeader
      • VaryByCustom
      • VaryByCustom by browser
      • Fragment caching
      • Post-cache substitution
      • Output cache provider
        • Creating an output cache provider
        • Using an output cache provider
    • Kernel caching and IIS 7 output caching
      • Configuring IIS caching
      • Limitations of kernel caching
      • Checking the contents of the kernel cache
    • Data caching
      • Basic use
      • Expiry
      • Priority
      • File dependencies
      • Database dependencies
        • Restrictions on queries
        • Starting the Service Broker
        • Starting the listening service
        • Creating the dependency
      • Item removed callback
        • Things to keep in mind
      • Optimal use of server cache
    • Find out more
    • Summary
  • Chapter 6: Thread Usage
    • Asynchronous web service access
      • Synchronous version
      • Asynchronous version
    • Asynchronous data access layer
      • Usage
      • Implementation
      • Performance testing
    • Asynchronous generic handlers
      • Synchronous version
      • Asynchronous version
      • Implementation
      • Performance testing
    • Asynchronous file writes
      • Synchronous version
      • Asynchronous version
      • A word of caution
    • Asynchronous web requests
    • Configuration changes
      • IIS 6, IIS 7 Classic Mode
        • I/O-related configuration
        • ASP.NET 2.0
      • IIS 7 integrated mode
      • Maximum queue size
    • Setting timeouts aggressively
    • Find out more
    • Summary
  • Chapter 7: Reducing Long Wait Times
    • Measuring wait times
      • Creating custom counters
        • Creating counters with Visual Studio
        • Creating counters programmatically
      • Updating counters in your code
      • Viewing custom counters in perfmon
    • Waiting concurrently
    • Retrieving multiple result sets from the database
    • Reducing overhead by using off-box session modes
      • Reducing trips to the database
      • Setting EnableSessionState
      • Reducing serialization and transfer overhead
      • Cutting your dependence on sessions
    • Thread locking
      • Minimizing the duration of locks
      • Using granular locks
      • Using System.Threading.Interlocked
      • Using ReaderWriterLock
        • Acquiring a reader lock
        • Acquiring a writer lock
        • Alternating readers and writers
    • Optimizing disk writes
      • Avoiding head seeks
      • Using FileStream.SetLength to avoid fragmentation
      • Using 64 K buffers
      • Disabling 8.3 filenames
    • Find out more
    • Summary
  • Chapter 8: Speeding up Database Access
    • Pinpointing bottlenecks
      • Missing indexes and expensive queries
        • Missing indexes
        • Expensive queries
        • Unused indexes
      • Locking
      • Execution plan reuse
        • Performance counters
        • dm_exec_query_optimizer_info
        • sys.dm_exec_cached_plans
      • Fragmentation
      • Memory
      • Disk usage
      • CPU
    • Fixing bottlenecks
      • Missing indexes
        • Clustered index
        • Non-clustered index
        • Included columns
        • Selecting columns to give an index
        • Maintaining indexes
      • Expensive queries
        • Cache aggregation queries
        • Keeping records short
        • Considering denormalization
        • Being careful with triggers
        • Using table variables for small temporary result sets
        • Using full-text search instead of LIKE
        • Replacing cursors with set-based code
        • Minimizing traffic from SQL server to web server
        • Object naming
        • Using SET NOCOUNT ON
        • Using FILESTREAM for values over 1 MB
        • Avoiding functions on columns in WHERE clauses
        • Using UNION ALL instead of UNION
        • Using EXISTS instead of COUNT to find existence of records
        • Combining SELECT and UPDATE
      • Locking
        • Gathering detailed locking information
        • Reducing blocking
        • Reducing deadlocks
      • Execution plan reuse
        • Ad hoc queries
        • Simple parameterization
        • sp_executesql
        • Stored procedures
        • Preventing reuse
      • Fragmentation
        • Index rebuild
        • Index reorganize
        • Heap table defragmentation
      • Memory
      • Disk usage
        • Optimizing query processing
        • Moving the logfile to a dedicated physical disk
        • Reducing fragmentation of the NTFS filesystem
        • Considering moving the tempdb database to its own disk
        • Splitting the database data over two or more disks
        • Moving heavily-used database objects to another disk
        • Using the optimal RAID configuration
      • CPU
    • Find out more
    • Summary
  • Chapter 9: Reducing Time to Last Byte
    • Pinpointing bottlenecks
      • Compression
      • ViewState
        • What is ViewState?
        • Why reduce ViewState?
        • Measuring your ViewState
      • Optimizing forms
      • White space
    • Fixing bottlenecks
      • ViewState
        • Seeing ViewState generated by each control
        • Disabling Viewstate
        • Identifying controls that do not need ViewState
        • Reloading from database cache
        • Storing a shorter version of the property value
        • Storing ViewState on the server
        • Compressing Viewstate
      • Reducing white space
        • Creating the filter
        • Creating the HTTP Module
        • Adding the HTTP Module to web.config
    • Additional measures
      • Event validation
      • Inline JavaScript and CSS
      • Avoiding inline styling
      • Reducing space taken by ASP.NET IDs
        • Opting out of IDs
        • Keeping IDs short
      • Using ASP.NET comments instead of HTML comments
      • Using Literal control instead of Label control
      • Avoiding repetition
        • Using shorter URLs
    • Find out more
    • Summary
  • Chapter 10: Compression
    • Agreeing on compression
    • Configuring compression in IIS 7
      • Installing the dynamic content compression module
      • Enabling compression
      • Setting compression by site, folder, or file
      • Compression level
      • Disabling compression based on CPU usage
      • Setting the request frequency threshold for static compression
      • Caching compressed dynamic files
        • Storing compressed files in the output cache
        • What if a client doesn't accept compressed content?
    • Configuring compression in IIS 6
      • Switching on compression in the IIS Manager
      • Setting permissions on the folder where compressed static files are cached
    • Updating the metabase
      • Resetting the IIS server
    • Configuring compression in IIS 5
    • Using compression in your development environment
      • Installing IIS 7
      • Enabling compression
      • Creating a development site in IIS
      • Modifying your project so it uses the development site
    • Measuring the difference compression makes
    • Improving the compressibility of your pages
    • Is compression the magic bullet?
    • Find out more
    • Summary
  • Chapter 11: Optimizing Forms
    • Client-side validation
      • ASP.NET validation controls
        • Quick example
        • Available validator controls
        • Validation summary
        • Disabling validation
        • Overhead
      • Validate JavaScript library
        • Initialization
        • Built-in validation methods
        • Adding validation methods
        • Formatting error messages
        • Content Delivery Network (CDN)
        • Overhead
    • Submitting forms asynchronously
      • UpdatePanel control
      • Page Methods
      • Web service
      • Generic handler
        • Building the generic handler
        • Cross Site Request Forgery (CSRF) attacks
        • Calling the generic handler
      • WCF Data Services and the Entity Framework
        • Creating the entity data model
        • Creating the WCF Data Service
        • Calling the WCF Data Service from JavaScript
        • Bugs and limitations in WCF Data Services
      • Creating an activity indicator
    • AJAX-type grids
      • Free, lightweight grids
      • Paid, heavyweight grids
      • Building your own grid
      • Working sample code
    • Find out more
    • Summary
  • Chapter 12: Reducing Image Load Times
    • Caching
      • Cache-Control response header
      • Preventing conditional requests
      • Expires header
      • Configuring Cache-Control in IIS 7
      • Configuring Cache-Control in IIS 6
      • Giving identical URLs to identical images
    • Serving images from cookieless subdomains
    • Parallel loading
    • Image control adapter
    • Image size
      • Using the optimal image format
      • Why to avoid scaling images in HTML
      • Tools
        • PNGOUT
        • Pngcrush
        • Jpegtran
        • NConvert
        • ImageMagick
    • Combining images
    • Ways to avoid images
      • Rounded corners in CSS
      • Utility symbols
    • Shortcut icon
    • Content Delivery Network
    • Find out more
    • Summary
  • Chapter 13: Improving JavaScript Loading
    • Problem: JavaScript loading blocks page rendering
      • Confirming with a test site
      • Approaches to reduce the impact on load times
    • Approach 1: Start loading after other components
    • Approach 2: Loading JavaScript more quickly
      • Techniques used with images
      • Free Content Delivery Networks
      • GZIP compression
      • Minifying a JavaScript file
        • Tools
        • Impact of minification
        • Implementing minification
      • Combining or breaking up
        • When and why to combine
        • When and why to break up
        • Measuring each scenario
        • Preventing 304 messages
        • Implementing automatic file combining
      • Removing unused code
    • Approach 3: Loading JavaScript on demand
      • Separating user interface code from render code
      • OnDemandLoader library
      • Initializing OnDemandLoader
      • Invoking not-yet-loaded functions
      • Preloading
    • Approach 4: Loading Javascript without blocking
      • Moving all <script> tags to the end of the page
      • Separating user interface code and render code
      • Introducing page loading indicator
      • Loading code in parallel with page
        • Initializing the loader object
        • Loading the code while the page is loading
        • Ensuring that code runs after the page is rendered
    • Improving ad loading
    • Improving CSS Loading
      • Minifying CSS
      • Removing unused CSS selectors
      • Loading CSS without blocking rendering
    • Find out more
    • Summary
  • Chapter 14: Load Testing
    • Using a load test environment
      • Load testing individual components during development
      • Testing page-by-page
      • Testing performance improvements
      • Acceptance testing
      • Additional best practices
    • Building a load test environment
    • Hosting the website under load
      • Installing IIS on Vista or Windows 7
        • Limitations
        • Installation
        • Opening the Firewall
        • Installing Windows Server 2008
        • Running Windows Server 2008 alongside Vista or Windows 7
        • Installing Virtual PC 2007
        • Installing Windows Server 2008
        • Getting more out of Virtual PC
        • Creating a shared folder
        • Installing .NET 4 or .NET 3.5 Service Pack 1
        • Installing and configuring IIS 7 on Windows Server 2008
        • Opening the Firewall
      • Installing Windows Server 2003
        • Running Windows Server 2003 alongside Vista or Windows 7
        • Installing Windows Server 2003
        • Creating a shared folder
        • Installing .NET 4 or .NET 3.5 Service Pack 1
        • Installing and configuring IIS 6 on Windows Server 2003
        • Opening the Firewall
      • ASP.NET test site
    • Installing a database
      • Downloading
      • Installation
      • Opening port in Firewall
      • Enabling remote administration
      • Test page
    • Setting up a load generator
      • Load generation services
      • WCAT
        • Installing WCAT
        • Creating a simple test
        • Running a simple test
        • Recording scenario files using fiddler
        • Adding thinking time
        • Other free load generation tools
      • Visual Studio Team System 2008 Test Edition/ Visual Studio 2010 Ultimate
        • Setting up a demo site
        • Creating a simple web test
        • Creating a second web test
        • Coded web tests
        • Combining web tests into a load test
        • Running the load test
        • Load testing components
      • Making sure the load generator isn’t bottlenecking
    • Find out more
    • Summary

Matt Perdeck

Matt Perdeck has over 20 years experience developing high-performance software systems, ranging from the largest ATM network in the Netherlands to embedded software in advanced Wide Area Networks. He has a B.Sc. in Computer Science from the University of Technology Twente, the Netherlands, and an M.B.A. from the University of Western Australia and Copenhagen Business School. He has worked in Australia, the Netherlands, Slovakia, and Thailand. He has extensive .NET and SQL Server development experience and has written several .NET articles. As an old-school software engineer, he is passionate about making things faster, simpler, and more efficiently.

Code Downloads

Download the code and support files for this book.

Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

ASP.NET Site Performance Secrets +    Oracle User Productivity Kit 3.5 =
50% Off
the second eBook
Price for both: £34.45

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Learn how to pinpoint and fix bottlenecks relating to all aspects of your site – server side, client side, code, images, and database.
  • Ensure shorter wait times for your site.
  • Eliminate the need to hire a DBA, by speeding up database access using insight into index structures and other advanced techniques.
  • Drastically speed up image loading, by exploiting browser behavior and by removing the hidden overhead in each image file.
  • Use ASP.NET's caching feature to dramatically improve performance by adding just a few lines of code.
  • Prevent a little known bottleneck overlooked by most developers – a shortage of worker threads in IIS – by using asynchronous methods.
  • Enable compression in IIS 6 and IIS 7 to cut file transfer times and bandwidth costs.
  • Reduce your Memory and CPU usage.
  • Optimize the deployment and usage of forms on your website.
  • Speed up JavaScript and CSS loading.
  • Diagnose problems as they occur, using waterfall charts.
  • Load-test your environment to measure the level of improvement in performance.
  • Find heaps of reference links and descriptions of free and low cost tools and services that make it easy to spot performance issues right away.


In Detail

Do you think that only experts with a deep understanding of the inner workings of ASP.NET, SQL Server, and IIS can improve a website's performance? Think again – because this book tosses that notion out of the window. It will help you resolve every web developer's nightmare – a slow website – with angry managers looking over your shoulder, raging calls from advertisers and clients – the lot. You don't have the time or energy to gain a thorough and complete understanding of ASP.NET performance optimization – You just need your site to run faster! This book will show you how.

This hands-on book shows how to dramatically improve the performance of your ASP.NET-based website straight away, without forcing you through a lot of theoretical learning. It teaches you practical, step-by-step techniques that you can use right away to make your site faster with just the right amount of theory you need to make sense of it all.

Start reading today and you could have a faster website tomorrow.

Unlike other performance-related books, here you'll first learn how to pinpoint the bottlenecks that hold back your site's performance, so you can initially focus your time and energy on those areas of your site where you can quickly make the biggest difference. It then shows you how to fix the bottlenecks you found with lots of working code samples and practical advice, and just the right amount of theoretical detail.

The first chapter details techniques for diagnosing performance issues using Waterfall charts. Subsequent chapters then each focus on one individual aspect of your website, providing you with numerous real-life scenarios and performance-enhancing techniques for each of them. In the last chapter, you learn how to effectively load-test your environment in order to measure the change in performance of your site without having to update your production environment – whether it is a new release or simply a small change in the database.


Written in a practical and clear conversational style, this book is filled with real-life website performance scenarios. It is replete with lots of working code samples and practical advice, and just the right amount of theory you need to make sense of it all.

Who this book is for

This book is written for ASP.NET/SQL Server-based website developers who want to speed up their site using simple, proven tactics without going through a lot of unnecessary theoretical learning. If your website isn't performing well, this is the ideal book for you.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software