A comprehensive demonstration of streaming capabilities in .NET 8 using IAsyncEnumerable, showcasing large dataset handling, performance monitoring, and real-time analytics.
- Efficient large dataset streaming
- Configurable batch processing
- Progress monitoring and analytics
- Memory-efficient data handling
- AsyncEnumerable extensions for enhanced streaming
- Performance monitoring and metrics
- Real-time data analytics
- Swagger documentation
- .NET 8 SDK
- Visual Studio 2022 or VS Code
# Clone the repository
git clone https://github.com/yourusername/asyncenumerable-webapi-demo.git
cd asyncenumerable-webapi-demo
# Run the API
dotnet run --project src/AsyncEnumerableApi/AsyncEnumerableApi.csproj
The API will be available at https://localhost:7001
GET /api/LargeData/stream?totalItems=10000&batchSize=1000
Parameters:
totalItems
: Number of items to generate (default: 10000)batchSize
: Items per batch (default: 1000)delayMs
: Delay between batches in millisecondscategory
: Filter by categoryminPrice
: Minimum price filtermaxPrice
: Maximum price filter
GET /api/LargeData/advanced-stream
Features:
- High-rated product filtering
- Quality score calculation
- Progress monitoring
- Batch processing
GET /api/LargeData/categories
Provides category-wise statistics including:
- Product counts
- Average prices
- Total stock
- Average ratings
// Stream with delay between items
await foreach (var item in source.WithDelay(100))
// Stream with batch processing
await foreach (var item in source.WithBatchDelay(1000, 100))
// Stream with progress reporting
await foreach (var item in source.WithProgress(count =>
Console.WriteLine($"Processed {count} items")))
- Real-time streaming metrics
- Memory usage tracking
- Processing rate monitoring
- Error handling
-
Memory Management
- Use appropriate batch sizes
- Monitor memory usage
- Implement backpressure when needed
-
Error Handling
- Implement retry logic
- Handle cancellation properly
- Log errors and progress
-
Performance
- Configure batch sizes based on data size
- Adjust delays based on client capabilities
- Monitor streaming metrics
This project is licensed under the MIT License