Skip to content

Latest commit

 

History

History
151 lines (111 loc) · 5 KB

File metadata and controls

151 lines (111 loc) · 5 KB

ADR-002: Prioritize Concurrent Operations

Status: Accepted Date: 2025-12-30 Deciders: Ahmed Mustafa

Context

User explicitly stated a key pain point: "if we can utilize concurrent operations, agents or tools."

.NET development involves many operations that can benefit from parallelism:

  • Running tests across multiple projects
  • Analyzing multiple source files
  • Building multiple projects in a solution
  • Reviewing changes across multiple files
  • Generating documentation for multiple assemblies

Traditional sequential processing can be slow for large codebases.

Decision

We will prioritize concurrent operations throughout DotNetDevMCP's architecture.

All applicable operations will support parallel execution where safe and beneficial.

Implementation Strategy

  1. Async/Await Throughout: All I/O operations use async/await
  2. Parallel Task Execution: Use Task.WhenAll, Parallel.ForEachAsync
  3. Orchestration Layer: Dedicated layer to coordinate concurrent operations
  4. Resource Management: Pooling and throttling to prevent exhaustion
  5. Agent Coordination: Support for agent-based concurrent workflows

Concurrent Operation Targets

High Priority:

  • Test execution (parallel across projects)
  • Multi-file analysis (concurrent code analysis)
  • Multi-solution operations (analyze multiple solutions)
  • Build operations (parallel project builds where possible)

Medium Priority:

  • Documentation generation (parallel assembly processing)
  • Log analysis (concurrent log file processing)
  • Git operations (parallel file diff analysis)

Low Priority (Future):

  • Real-time code analysis
  • Background indexing

Consequences

Positive

  • Performance: 50-80% reduction in execution time for batch operations
  • User Satisfaction: Addresses primary pain point
  • Scalability: Handles large codebases efficiently
  • Resource Utilization: Better use of multi-core systems
  • Competitive Advantage: Faster than sequential alternatives

Negative

  • Complexity: Concurrent code is harder to write and debug
  • Resource Management: Need careful throttling to avoid exhaustion
  • Error Handling: More complex error scenarios (partial failures)
  • Testing Complexity: Need to test concurrent scenarios
  • Potential Race Conditions: Must be careful with shared state

Mitigation Strategies

  • Immutability: Prefer immutable data structures
  • Cancellation Tokens: Support cancellation throughout
  • Throttling: Limit concurrent operations (e.g., MaxDegreeOfParallelism)
  • Resource Pooling: Share expensive resources (Roslyn workspaces)
  • Comprehensive Testing: Test concurrent scenarios thoroughly
  • Logging: Detailed logging for debugging concurrent issues

Technical Details

Example: Parallel Test Execution

public async Task<TestResults> ExecuteTestsAsync(
    Solution solution,
    CancellationToken cancellationToken = default)
{
    // Discover test projects
    var testProjects = await _testDiscovery.DiscoverAsync(solution, cancellationToken);

    // Execute in parallel with throttling
    var parallelOptions = new ParallelOptions
    {
        MaxDegreeOfParallelism = Environment.ProcessorCount,
        CancellationToken = cancellationToken
    };

    var results = new ConcurrentBag<ProjectTestResult>();

    await Parallel.ForEachAsync(testProjects, parallelOptions, async (project, ct) =>
    {
        var result = await _testExecutor.RunAsync(project, ct);
        results.Add(result);
    });

    // Aggregate results
    return _resultAggregator.Aggregate(results);
}

Resource Management

public class WorkspacePool : IDisposable
{
    private readonly ObjectPool<AdhocWorkspace> _pool;
    private readonly int _maxInstances;

    public WorkspacePool(int maxInstances = 4)
    {
        _maxInstances = maxInstances;
        _pool = ObjectPool.Create(new WorkspacePoolPolicy(maxInstances));
    }

    public AdhocWorkspace Rent() => _pool.Get();
    public void Return(AdhocWorkspace workspace) => _pool.Return(workspace);
}

Metrics

We will measure success by:

  • Execution Time: Compare sequential vs. parallel execution
  • Resource Usage: Monitor CPU, memory, disk I/O
  • Throughput: Operations per second
  • User Satisfaction: Feedback on performance

Target Improvements

  • Test execution: 50% faster for solutions with 3+ test projects
  • Multi-solution analysis: 70% faster for 5+ solutions
  • Code analysis: 60% faster for 100+ files

References

Notes

This decision aligns with modern .NET best practices and takes full advantage of multi-core processors common in development machines.