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 174 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM
2 31 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM
3 31 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM
4 29 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM
5 28 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM
6 32 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM
7 29 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM
8 31 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM
9 29 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM
10 29 9/19/2024 4:13:42 PM 9/16/2024 11:09:37 AM

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.