Bulk Calls Demo

Explore how to handle multiple asynchronous HTTP GET requests efficiently using .NET 8. This demo demonstrates best practices for managing concurrency, handling timeouts, and optimizing performance with async programming.

Bulk Call Results

Iteration Elapsed Time (ms) Completion Date Build Date
1 245 11/21/2024 9:37:50 AM 11/9/2024 5:25:00 PM
2 29 11/21/2024 9:37:50 AM 11/9/2024 5:25:00 PM
3 29 11/21/2024 9:37:50 AM 11/9/2024 5:25:00 PM
4 28 11/21/2024 9:37:50 AM 11/9/2024 5:25:00 PM
5 28 11/21/2024 9:37:50 AM 11/9/2024 5:25:00 PM
6 28 11/21/2024 9:37:51 AM 11/9/2024 5:25:00 PM
7 29 11/21/2024 9:37:51 AM 11/9/2024 5:25:00 PM
8 29 11/21/2024 9:37:51 AM 11/9/2024 5:25:00 PM
9 42 11/21/2024 9:37:51 AM 11/9/2024 5:25:00 PM
10 31 11/21/2024 9:37:51 AM 11/9/2024 5:25:00 PM

The table above shows the results of performing multiple asynchronous HTTP GET calls to the specified endpoint. Each row represents an individual request, detailing its execution time and completion date.

BulkCallsController Documentation

The BulkCallsController in this async demo project showcases the implementation of bulk asynchronous HTTP GET requests to a specified endpoint. By leveraging .NET's async capabilities, this controller demonstrates how to efficiently manage a large number of network requests without overwhelming system resources.

Key Features:

  • Concurrent HTTP Requests: Handles multiple HTTP GET requests concurrently using async tasks and `SemaphoreSlim` to limit the number of simultaneous requests, ensuring controlled parallelism and resource usage.
  • Thread Safety: Uses locks to ensure thread safety when adding results to the shared list, preventing data corruption in multi-threaded environments.
  • Timeouts and Cancellations: Implements `CancellationTokenSource` with a timeout to cancel long-running requests, demonstrating best practices for managing task lifetimes in async workflows.
  • Performance Optimization: By using asynchronous task coordination with `Task.WhenAll`, the controller efficiently handles bulk requests, significantly reducing overall execution time compared to sequential processing.

Alternative Approaches:

While the BulkCallsController effectively demonstrates handling bulk requests with `SemaphoreSlim` for concurrency control, other approaches could include:

  • Parallel.ForEach: Offers an alternative for concurrent processing but requires careful management of exceptions and concurrency controls.
  • TPL Dataflow: Provides advanced options for data buffering and parallel task execution, making it suitable for complex data processing workflows.
  • Cloud-Native Solutions: Leveraging Azure Functions or other serverless platforms with built-in scaling can offload concurrency management to cloud infrastructure.

Best Practices:

  • Monitor and Log: Use logging and telemetry to monitor the performance and health of bulk async operations, enabling proactive tuning of concurrency levels and timeouts.
  • Adjust Concurrency: Optimize the maximum thread count (`maxThreads`) based on system capabilities and endpoint performance to balance resource usage and throughput.
  • Handle Failures Gracefully: Implement retry logic or circuit breakers using libraries like Polly to handle transient failures and improve resilience.