ASP.NET Core 2 High Performance - Second Edition

Book description

Learn how to develop web applications that deploy cross-platform and are optimized for high performance using ASP.NET Core 2

About This Book

  • Master high-level web app performance improvement techniques using ASP.NET Core 2.0
  • Find the right balance between premature optimization and inefficient code
  • Design workflows that run asynchronously and are resilient to transient performance issues

Who This Book Is For

This book is aimed for readers who can build a web application and have some experience with ASP.NET or some other web application framework (such as Ruby on Rails or Django). They can be people who are happy learning details independently but who struggle to discover the topics that they should be researching. The reader should be interested in improving the performance of their web app and in learning about ASP.NET Core and modern C#.

What You Will Learn

  • Understand ASP.NET Core 2 and how it differs from its predecessor
  • Address performance issues at the early stages of development
  • Set up development environments on Windows, Mac, and Linux
  • Measure, profile and find the most significant problems
  • Identify the differences between development workstations and production infrastructures, and how these can exacerbate problems
  • Boost the performance of your application but with an eye to how it affects complexity and maintenance
  • Explore a few cutting-edge techniques such as advanced hashing and custom transports

In Detail

The ASP.NET Core 2 framework is used to develop high-performance and cross-platform web applications. It is built on .NET Core 2 and includes significantly more framework APIs than version 1.

This book addresses high-level performance improvement techniques. It starts by showing you how to locate and measure problems and then shows you how to solve some of the most common ones. Next, it shows you how to get started with ASP.NET Core 2 on Windows, Mac, Linux, and with Docker containers.

The book illustrates what problems can occur as latency increases when deploying to a cloud infrastructure. It also shows you how to optimize C# code and choose the best data structures for the job. It covers new features in C# 6 and 7, along with parallel programming and distributed architectures.

By the end of this book, you will be fixing latency issues and optimizing performance problems, but you will also know how this affects the complexity and maintenance of your application. Finally, we will explore a few highly advanced techniques for further optimization.

Style and approach

A step-by-step practical guide filled with real-world use cases and examples

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. What's New in ASP.NET Core 2?
    1. What's new in Core 2
      1. What's new in .NET Core 2
        1. Performance improvements
      2. What's new in ASP.NET Core 2
        1. Performance improvements
    2. Standards
    3. New C# features
      1. C# 6
        1. String interpolation
        2. Null conditional
        3. Exception filters
        4. Asynchronous availability
        5. Expression bodies
      2. C# 7
        1. Literals
        2. Tuples
        3. Out variables
        4. References
        5. Patterns
        6. More expression bodies
        7. More asynchronous improvements
    4. JavaScript
    5. Summary
  3. Why Performance Is a Feature
    1. Performance as a feature
    2. Common classes of performance problems
      1. Language considerations
      2. Types of performance problems
        1. When performance matters
          1. Slower is sometimes better
        2. Why issues are missed
          1. Measuring
      3. The benefits of planning ahead
    3. Understanding hardware
      1. Storage access speeds
      2. Scaling approach changes
    4. Tools and costs
      1. Tools
      2. Looking at some alternative tools
    5. The new .NET
    6. Summary
  4. Setting Up Your Environment
    1. Windows
      1. Visual Studio 2017
        1. Installing VS
      2. Installing .NET Core 2
      3. Creating your first app
    2. Mac
      1. Visual Studio for Mac
        1. Installing VS Mac
      2. Installing .NET Core 2
      3. Creating your first app
      4. Visual Studio Code
    3. Linux
      1. Getting started with .NET Core on Linux
      2. Installing .NET Core 2
      3. Creating your first app
      4. Containerization with Docker
        1. Using ASP.NET Core 2 with Docker
    4. Summary
  5. Measuring Performance Bottlenecks
    1. Tools
      1. SQL
        1. SQL Server Profiler
          1. Executing a simple query
        2. MiniProfiler
      2. Application profiling
        1. Glimpse
          1. Using Glimpse
        2. IDE
      3. Monitoring HTTP
        1. Browsers
          1. Chrome
          2. Firefox
        2. Fiddler
      4. Network
        1. Microsoft Message Analyzer
        2. Wireshark
      5. Roll your own
    2. Science
      1. Repeatability
        1. Only change one thing
    3. Summary
  6. Fixing Common Performance Problems
    1. Latency
    2. Asynchronous operations
      1. Simple asynchronous tools
      2. Background queuing
      3. Hangfire
    3. Select N+1 problems
      1. Efficient paging
      2. Static site generators
    4. Pragmatic solutions with hardware
      1. A desktop example
      2. Web applications
    5. Oversized images
      1. Image resolution
      2. Image format
    6. Summary
  7. Addressing Network Performance
    1. Internet protocols
      1. TCP/IP
        1. Slow-start
      2. HTTP
        1. Headers
        2. HTTP methods
        3. Status codes
        4. Encryption
          1. Key exchange
          2. Delay diagnostics
          3. Performance tweaks
        5. HTTP/2
        6. WebSockets
    2. Compression
      1. Lossless compression algorithms
      2. Bundling and minification
        1. Bundling
        2. Minification
        3. Changes in ASP.NET Core
      3. Image optimization
        1. PNG
        2. JPEG
        3. Other image formats
        4. Resizing images
    3. Caching
      1. Browser
      2. Server
      3. Proxy servers between you and your users
        1. CDNs
    4. Summary
  8. Optimizing I/O Performance
    1. Input/output
      1. Categories of I/O
        1. Disks
        2. Virtual filesystems
        3. Databases
        4. APIs
      2. Network diagnostics tools
        1. Ping
        2. Tracert
        3. Nslookup
        4. Build your own
    2. Solutions
      1. Batching API requests
      2. Efficient DB operations
        1. Database tuning
        2. Reporting
          1. Aggregates
          2. Sampling
        3. Inserting data
          1. GUIDs
        4. Advanced DB topics
    3. Simulation and testing
    4. Summary
  9. Understanding Code Execution and Asynchronous Operations
    1. Getting started with the core projects
      1. .NET Core
      2. ASP.NET Core
        1. Kestrel
    2. Data structures
      1. Lists
      2. Dictionaries
      3. Collection benchmarks
      4. Bloom filters
    3. Hashing and checksums
      1. Hashing benchmarks
    4. Serialization
    5. SIMD CPU instructions
    6. Parallel programming
      1. Task Parallel Library
      2. Parallel LINQ
      3. Parallel benchmarking
      4. Parallel programming limitations
    7. Multithreading and concurrency
      1. Locking
    8. Practices to avoid
      1. Reflection
      2. Regular expressions
      3. String concatenation in tight loops
      4. Dynamic typing
      5. Synchronous operations
      6. Exceptions
    9. Summary
  10. Learning Caching and Message Queuing
    1. Why caching is hard
      1. Web caching
        1. Caching background
          1. HTTP headers
          2. Cache busting
        2. Service workers
          1. Service worker example
        3. Web and proxy servers
          1. IIS
          2. Varnish
        4. Working with a content delivery network
        5. When not to cache
      2. Application layer caching
        1. Redis
        2. Database result set caching
    2. Message queuing
      1. Coffee shop analogy
      2. Message queuing styles
      3. Common messaging patterns
        1. Unicast
        2. Pub/sub
      4. RabbitMQ
      5. Queuing frameworks and libraries
    3. Summary
  11. The Downsides of Performance-Enhancing Tools
    1. Managing complexity
      1. Understanding complexity
      2. Complexity reduction
        1. Frameworks
        2. Architecture
          1. Monolith versus microservices
          2. Architecture comparison
        3. Refactoring
    2. A culture of high performance
      1. A blameless culture
      2. Intellectual dishonesty
      3. Slow down to go faster
      4. From the ground up
      5. Shared values
    3. The price of performance
    4. Distributed debugging
      1. Logging
        1. Error logging
        2. Application Insights
        3. Integrated logging
        4. Centralized logging
      2. Statistics
    5. Managing stale caches
    6. Summary
  12. Monitoring Performance Regressions
    1. Profiling and measurement
    2. Testing
      1. Automated testing
      2. Continuous integration
      3. Slow testing
      4. Fixing performance regressions
      5. Load testing
      6. Realism
        1. Realistic environments
        2. Realistic workloads
          1. Feature switching
      7. Experimenting for science
      8. A/B testing
      9. User interface testing
        1. Web UI testing tools
        2. Automating UI performance tests
    3. Staying alert
    4. DevOps
      1. DevOps tooling
        1. Provisioning
        2. Monitoring
    5. Hosting
    6. Summary
  13. The Way Ahead
    1. Reviewing what we learned
    2. Further reading
      1. Going native
      2. Processor architecture
      3. Hardware is hard
      4. Machine learning
      5. Big data and MapReduce
      6. Orleans
      7. Custom transports
      8. Advanced hashing
    3. Library and framework support
    4. The future
    5. Summary

Product information

  • Title: ASP.NET Core 2 High Performance - Second Edition
  • Author(s): James Singleton
  • Release date: October 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788399760