The Scaling Habits of ASP.NET
         Applications
        Richard Campbell
Richard Campbell
• Background
  – After thirty years, done every job in the computer
    industry you’ve ever heard of
• Currently
  – Co-Founder of Strangeloop Networks
  – Co-Host of .NET Rocks!
  – Host of RunAs Radio
50 000 foot view
                                                         Business Success

                                           Business
                                           Traction
                            Make it Work
                            Right
Page Views




             Make it Work




              Version 1      Version 2       Version 3     Version N
                                         Time
What are we measuring?
• Capacity
   – Total number of known users
   – Number of active users (aka active sessions)
   – Number of concurrent users (aka concurrent requests)
• Throughput
   – Page Views per Month
   – Requests per Second
   – Transactions per Second
• Performance
   – Load time in milliseconds
   – Time to first byte (TTFB), Time to last byte (TTLB)
The Anatomy of a Web Request
Performance Equation


       Legend:

        R:                                    Response time

        RTT:                                  Round Trip Time

        App Turns:                            Http Requests

        Concurrent Requests:                  # server sockets open by browser

        Cs:                                   Server Side Compute time

        Cc:                                   Client Compute time
Source: Field Guide to Application Delivery Systems, by Peter Sevcik and Rebecca Wetzel, NetForecast
Where do the numbers come from?



                                                                                                                 Server Code Timing: 0.8 secs



                          4.5 sec


                                                                                                                    Client Code Timing: 1.2 secs


                                       http://www.speedtest.net/




                                                                   Ping statistics for 209.162.190.188:
                                                                       Packets: Sent = 4, Received = 4, Lost = 0 (0%
                                                                   loss),
                                                                   Approximate round trip times in milli-seconds:
                                                                       Minimum = 80ms, Maximum = 92ms, Average = 85ms

http://www.websiteoptimization.com/services/analyze/
Performance Spreadsheet



                               Factor 1       Factor 2              Factor 3               Time
P1 = Payload/Bandwidth          208 KB Payload 717 KB/Sec Bandwidth                          0.29 seconds
P2 = AppTurns * Roundtrip Time   51 Appturns     85 ms Roundtrip     2 Concurrent Requests 2.168 seconds
P3 = Compute Time at Server     0.8 Seconds                                                   0.8 seconds
P4 = Compute Time at Client     1.2 Seconds                                                   1.2 seconds
                                                                                           4.458 seconds
Version 1: Make it work
• Get Version 1 out the door
• Define the initial hardware platform
• Meet the launch date




          The only one who likes your app is you
Scaling Habits
•   10 to 50 requests/second
•   5 to 15 users
•   15 active sessions at peak
•   Problems with performance on areas of the
    site
    – Multi-User Issues
    – Complex input screens
    – Reports
Solutions for Version 1
• Fix logical scaling problems
  – Multi-user data access
• Get user feedback
  – Humiliating but useful
  – Fix the actual user pains
  – Watch your app in use
Version 2: Make it work right

• Focus on features
  – What is missing
• Bug Fixing
• Rethink the App or UI
  – Some new directions
• Larger and more diverse users
  base
               Now your boss likes your app too
Scaling Habits
•   50 to 100 requests/second
•   15 to 50 users (5-10 are remote!)
•   30 active sessions at peak
•   Problems
    – Fights with IT over remote access
    – Reach the single server limit
       • What does this look like?
What does it really look like?
•   Memory consumption above 80%
•   Processor consumption at 100% all the time
•   Request queues start to grow out of hand
•   Page timeouts (server not available)
•   Sessions get lost
•   People can’t finish their work!
Solutions for Version 2
• More Hardware
  – Dedicated web server
  – Separate database server (probably shared)
• Find the low hanging fruit
  – Fix querying
  – Get your page size under control
Version 3: Business Traction

• Weighing business priorities
  – Formal IT transition point
  – There is budget
• Scaling versus Reliability
  – Which one is more important
• 99% verses 100% up time
  – Cost of Reliability
                    People you don’t know like your app
Scaling Habits
•   300 to 1000 requests/second
•   100 to 500 users
•   300 active sessions at peak
•   Problems
    – Performance is now front and center
    – Consequences of downtime are now significant
Network vs. Development IQ

• Network IQ Test               • Development IQ Test
   – Explain each of the           – Explain the network
     Web.config file                 diagram of your
   – Explain the load-               application
     balancing scheme              – Explain how to access the
     required by the app             production log files
   – Explain the bottlenecks       – Explain the redundancy
     of the production system        model of the production
                                     system
Solutions for Version 3
• Move to multiple web servers: You need a load balancer
• More bandwidth: Move to a hosting facility
• Get methodical, use profiling
   – Red Gate Ants, SQL Profiler, Web Site Optimizer
• Get the facts on the problem areas
   – Work methodically and for the business on addressing
     slowest lines of code
   – Focus on understanding what the right architecture is
     rather than ad-hoc architecting
• Let the caching begin!
Version N: Business Success

• IT costs now out weigh the software development
• Getting new features to production takes months
   – Or Cowboy it! (which always happens)
• IT and Dev process is a focus – Tech Politics




                     It’s no longer your app
Scaling Habits
•   500+ requests/second
•   5000+ users
•   3000 active sessions at peak
•   Problems
    – Running out of memory with inproc sessions
    – Worker process recycling
    – Cache Coherency
    – Session Management
A Word About Load-balancing

                                           Sticky vs. Round
                      Load Balancer         Robin vs. WMI
                        Virtual IP



Web Server 1   Web Server 2     Web Server 3    Web Server 4




                      Persistent Data
                        Session?
Performance and Scale
• Now the problem is that scale and
  performance are intertwined
  – A new class of ‘timing’ problem shows up under
    load (and are almost impossible to reproduce
    outside of production)
  – Caches are flushed more than expected
     • And performance plummets
Solutions for Version N
• Your architecture is now hardware and software
   – Use third party accelerators
   – Create a performance team and focus on best practices
   – Use content routing
      • Separate and pre-generate all static resources
• Cache, cache, and more cache
   – Output Cache – All static pages are cached
   – Response.Cache – Look for database gets with few updates
Summary
• Focus on actual user performance problems
  – What is reality?
• Start with low hanging fruit
• Use methodical, empirical performance
  improvement
• At large scale, the network is the computer

Scaling habits of ASP.NET

  • 1.
    The Scaling Habitsof ASP.NET Applications Richard Campbell
  • 2.
    Richard Campbell • Background – After thirty years, done every job in the computer industry you’ve ever heard of • Currently – Co-Founder of Strangeloop Networks – Co-Host of .NET Rocks! – Host of RunAs Radio
  • 3.
    50 000 footview Business Success Business Traction Make it Work Right Page Views Make it Work Version 1 Version 2 Version 3 Version N Time
  • 4.
    What are wemeasuring? • Capacity – Total number of known users – Number of active users (aka active sessions) – Number of concurrent users (aka concurrent requests) • Throughput – Page Views per Month – Requests per Second – Transactions per Second • Performance – Load time in milliseconds – Time to first byte (TTFB), Time to last byte (TTLB)
  • 5.
    The Anatomy ofa Web Request
  • 6.
    Performance Equation Legend: R: Response time RTT: Round Trip Time App Turns: Http Requests Concurrent Requests: # server sockets open by browser Cs: Server Side Compute time Cc: Client Compute time Source: Field Guide to Application Delivery Systems, by Peter Sevcik and Rebecca Wetzel, NetForecast
  • 7.
    Where do thenumbers come from? Server Code Timing: 0.8 secs 4.5 sec Client Code Timing: 1.2 secs http://www.speedtest.net/ Ping statistics for 209.162.190.188: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 80ms, Maximum = 92ms, Average = 85ms http://www.websiteoptimization.com/services/analyze/
  • 8.
    Performance Spreadsheet Factor 1 Factor 2 Factor 3 Time P1 = Payload/Bandwidth 208 KB Payload 717 KB/Sec Bandwidth 0.29 seconds P2 = AppTurns * Roundtrip Time 51 Appturns 85 ms Roundtrip 2 Concurrent Requests 2.168 seconds P3 = Compute Time at Server 0.8 Seconds 0.8 seconds P4 = Compute Time at Client 1.2 Seconds 1.2 seconds 4.458 seconds
  • 9.
    Version 1: Makeit work • Get Version 1 out the door • Define the initial hardware platform • Meet the launch date The only one who likes your app is you
  • 10.
    Scaling Habits • 10 to 50 requests/second • 5 to 15 users • 15 active sessions at peak • Problems with performance on areas of the site – Multi-User Issues – Complex input screens – Reports
  • 11.
    Solutions for Version1 • Fix logical scaling problems – Multi-user data access • Get user feedback – Humiliating but useful – Fix the actual user pains – Watch your app in use
  • 12.
    Version 2: Makeit work right • Focus on features – What is missing • Bug Fixing • Rethink the App or UI – Some new directions • Larger and more diverse users base Now your boss likes your app too
  • 13.
    Scaling Habits • 50 to 100 requests/second • 15 to 50 users (5-10 are remote!) • 30 active sessions at peak • Problems – Fights with IT over remote access – Reach the single server limit • What does this look like?
  • 15.
    What does itreally look like? • Memory consumption above 80% • Processor consumption at 100% all the time • Request queues start to grow out of hand • Page timeouts (server not available) • Sessions get lost • People can’t finish their work!
  • 16.
    Solutions for Version2 • More Hardware – Dedicated web server – Separate database server (probably shared) • Find the low hanging fruit – Fix querying – Get your page size under control
  • 17.
    Version 3: BusinessTraction • Weighing business priorities – Formal IT transition point – There is budget • Scaling versus Reliability – Which one is more important • 99% verses 100% up time – Cost of Reliability People you don’t know like your app
  • 18.
    Scaling Habits • 300 to 1000 requests/second • 100 to 500 users • 300 active sessions at peak • Problems – Performance is now front and center – Consequences of downtime are now significant
  • 19.
    Network vs. DevelopmentIQ • Network IQ Test • Development IQ Test – Explain each of the – Explain the network Web.config file diagram of your – Explain the load- application balancing scheme – Explain how to access the required by the app production log files – Explain the bottlenecks – Explain the redundancy of the production system model of the production system
  • 20.
    Solutions for Version3 • Move to multiple web servers: You need a load balancer • More bandwidth: Move to a hosting facility • Get methodical, use profiling – Red Gate Ants, SQL Profiler, Web Site Optimizer • Get the facts on the problem areas – Work methodically and for the business on addressing slowest lines of code – Focus on understanding what the right architecture is rather than ad-hoc architecting • Let the caching begin!
  • 21.
    Version N: BusinessSuccess • IT costs now out weigh the software development • Getting new features to production takes months – Or Cowboy it! (which always happens) • IT and Dev process is a focus – Tech Politics It’s no longer your app
  • 22.
    Scaling Habits • 500+ requests/second • 5000+ users • 3000 active sessions at peak • Problems – Running out of memory with inproc sessions – Worker process recycling – Cache Coherency – Session Management
  • 23.
    A Word AboutLoad-balancing Sticky vs. Round Load Balancer Robin vs. WMI Virtual IP Web Server 1 Web Server 2 Web Server 3 Web Server 4 Persistent Data Session?
  • 24.
    Performance and Scale •Now the problem is that scale and performance are intertwined – A new class of ‘timing’ problem shows up under load (and are almost impossible to reproduce outside of production) – Caches are flushed more than expected • And performance plummets
  • 25.
    Solutions for VersionN • Your architecture is now hardware and software – Use third party accelerators – Create a performance team and focus on best practices – Use content routing • Separate and pre-generate all static resources • Cache, cache, and more cache – Output Cache – All static pages are cached – Response.Cache – Look for database gets with few updates
  • 26.
    Summary • Focus onactual user performance problems – What is reality? • Start with low hanging fruit • Use methodical, empirical performance improvement • At large scale, the network is the computer