Azure Application Gateway Performance Optimization

Introduction

Azure Application Gateway is a scalable, managed application delivery controller that enables you to manage traffic to your web applications. Optimizing its performance is crucial for ensuring a seamless and responsive user experience, reducing latency, and maximizing throughput. This guide provides best practices and techniques to achieve optimal performance for your Application Gateway deployments.

Key Performance Factors

Several factors influence Application Gateway performance:

  • Instance Count and Size: The number and size of Application Gateway instances directly impact its capacity to handle traffic.
  • Backend Health: The responsiveness and availability of your backend servers are critical.
  • Network Latency: Latency between Application Gateway, backend servers, and clients.
  • Configuration Complexity: Rule complexity, WAF policies, and SSL certificate processing can add overhead.
  • Traffic Patterns: The volume, type, and burstiness of incoming traffic.
  • Protocol Usage: HTTP/1.1, HTTP/2, and WebSocket usage.

Configuration Best Practices

Proper configuration is the foundation of good performance.

Health Probes

Configure health probes effectively to ensure traffic is only sent to healthy backend instances. Tune probe intervals, thresholds, and timeouts appropriately.

Tip:

Use a shorter probe interval (e.g., 15-30 seconds) and a low number of unhealthy thresholds (e.g., 2-3) for critical applications to detect failures faster.

Request Routing Rules

Keep routing rules as simple as possible. Complex rules, especially those involving many URL path maps or host-based routing rules, can impact performance.

SSL Certificates

Use efficient SSL certificates and consider optimizing certificate chain lengths. For high-traffic scenarios, consider using Application Gateway v2's faster SSL handshake capabilities.

Scaling and Tiering

Choosing the right tier and scaling strategy is essential.

SKUs: Standard_v2 and WAF_v2

The v2 SKUs (Standard_v2 and WAF_v2) offer significant performance improvements over the v1 SKUs, including autoscaling and multi-tenant architecture. They are generally recommended for new deployments.

Autoscaling

Enable autoscaling on v2 SKUs to automatically adjust the number of instances based on traffic load. Configure minimum and maximum instance counts to balance cost and performance.

Manual Scaling

For predictable traffic patterns, manual scaling can be used to set a fixed number of instances, ensuring consistent performance.

Caching and Compression

Leverage Application Gateway's built-in features to reduce server load and improve response times.

HTTP Compression

Enable HTTP compression (Gzip) for static and dynamic content to reduce the size of responses, leading to faster transfer times for clients and reduced bandwidth usage.

// Enable compression in your Application Gateway configuration
// Example (conceptual, actual implementation involves Azure portal/CLI/ARM)
{
    "httpSettings": {
        "compressionEnabled": true,
        "compressionTypes": ["Gzip"]
    }
}

HTTP Caching

Configure caching rules to cache static assets directly within Application Gateway. This diverts a significant amount of traffic from your backend servers.

SSL Offloading

By offloading SSL/TLS decryption from your backend servers to Application Gateway, you free up valuable CPU resources on your application instances, allowing them to focus on serving application logic. The v2 SKUs are optimized for efficient SSL processing.

Monitoring and Troubleshooting

Continuous monitoring is key to identifying and resolving performance bottlenecks.

Azure Monitor Metrics

Utilize Azure Monitor to track key Application Gateway metrics such as:

  • Total Requests
  • Healthy Host Percent
  • Response Time (Average and Percentiles)
  • CPU Usage
  • Data In/Out
  • Backend Status

Diagnostic Logs

Enable diagnostic logs to capture detailed information about requests, backend responses, and errors. These logs can be sent to Log Analytics, Storage Accounts, or Event Hubs for analysis.

Application Insights

Integrate Application Gateway with Azure Application Insights to gain deeper insights into application performance, identify slow transactions, and pinpoint backend issues.

Advanced Techniques

  • HTTP/2 Support: Enable HTTP/2 on Application Gateway to take advantage of multiplexing, header compression, and server push for improved performance with compatible clients.
  • Connection Draining: Configure connection draining to gracefully remove backend instances from rotation during updates or maintenance, preventing loss of ongoing requests.
  • Sticky Sessions (Session Affinity): If your application requires it, configure sticky sessions to ensure a user's requests are consistently routed to the same backend server. Be mindful of its impact on load distribution.
  • Web Application Firewall (WAF) Tuning: For WAF-enabled gateways, carefully tune WAF rules to minimize false positives and avoid adding unnecessary latency to requests.