@@ -84,7 +84,7 @@ public CpuStressService(
8484 }
8585
8686 /// <inheritdoc />
87- public Task < SimulationResult > TriggerCpuStressAsync ( int durationSeconds , CancellationToken cancellationToken , int targetPercentage = 100 )
87+ public Task < SimulationResult > TriggerCpuStressAsync ( int durationSeconds , CancellationToken cancellationToken , string level = "high" )
8888 {
8989 // ==========================================================================
9090 // STEP 1: Validate the duration (no upper limits - app is meant to break)
@@ -93,7 +93,12 @@ public Task<SimulationResult> TriggerCpuStressAsync(int durationSeconds, Cancell
9393 ? DefaultDurationSeconds
9494 : durationSeconds ;
9595
96- var actualPercentage = Math . Clamp ( targetPercentage , 1 , 100 ) ;
96+ // Normalize level to lowercase and default to "high" if invalid
97+ var normalizedLevel = ( level ? . ToLowerInvariant ( ) ) switch
98+ {
99+ "moderate" => "moderate" ,
100+ _ => "high"
101+ } ;
97102
98103 var simulationId = Guid . NewGuid ( ) ;
99104 var startedAt = DateTimeOffset . UtcNow ;
@@ -111,17 +116,17 @@ public Task<SimulationResult> TriggerCpuStressAsync(int durationSeconds, Cancell
111116 {
112117 [ "DurationSeconds" ] = actualDuration ,
113118 [ "ProcessorCount" ] = processorCount ,
114- [ "TargetPercentage " ] = actualPercentage
119+ [ "Level " ] = normalizedLevel
115120 } ;
116121
117122 // Register this simulation with the tracker
118123 _simulationTracker . RegisterSimulation ( simulationId , SimulationType . Cpu , parameters , cts ) ;
119124
120125 _logger . LogInformation (
121- "Starting CPU stress simulation {SimulationId}: {Duration}s @ {Percentage}% across {ProcessorCount} cores" ,
126+ "Starting CPU stress simulation {SimulationId}: {Duration}s @ {Level} across {ProcessorCount} cores" ,
122127 simulationId ,
123128 actualDuration ,
124- actualPercentage ,
129+ normalizedLevel ,
125130 processorCount ) ;
126131
127132 // ==========================================================================
@@ -132,7 +137,7 @@ public Task<SimulationResult> TriggerCpuStressAsync(int durationSeconds, Cancell
132137 // This is important because the caller (HTTP request) shouldn't be blocked
133138 // waiting for the entire duration.
134139
135- _ = Task . Run ( ( ) => ExecuteCpuStress ( simulationId , actualDuration , actualPercentage , cts . Token ) , cts . Token ) ;
140+ _ = Task . Run ( ( ) => ExecuteCpuStress ( simulationId , actualDuration , normalizedLevel , cts . Token ) , cts . Token ) ;
136141
137142 // ==========================================================================
138143 // STEP 4: Return the result immediately
@@ -145,7 +150,7 @@ public Task<SimulationResult> TriggerCpuStressAsync(int durationSeconds, Cancell
145150 SimulationId = simulationId ,
146151 Type = SimulationType . Cpu ,
147152 Status = "Started" ,
148- Message = $ "CPU stress started on { processorCount } cores for { actualDuration } seconds at { actualPercentage } % . " +
153+ Message = $ "CPU stress started on { processorCount } cores for { actualDuration } seconds ( { normalizedLevel } intensity) . " +
149154 "Observe CPU metrics in Task Manager, dotnet-counters, or Application Insights. " +
150155 "High CPU like this is typically caused by spin loops, inefficient algorithms, or infinite loops." ,
151156 ActualParameters = parameters ,
@@ -165,8 +170,8 @@ public Task<SimulationResult> TriggerCpuStressAsync(int durationSeconds, Cancell
165170 /// </para>
166171 /// <para>
167172 /// This method uses dedicated threads with spin loops to consume available CPU.
168- /// If targetPercentage is 100 , it runs a tight loop.
169- /// If targetPercentage is less than 100 , it uses a duty cycle (work/sleep) to simulate load.
173+ /// For "high" level , it runs a tight loop for ~100% usage .
174+ /// For "moderate" level , it uses a duty cycle (work/sleep) to simulate ~65% load.
170175 /// </para>
171176 /// <para>
172177 /// <strong>Why Dedicated Threads Instead of Parallel.For?</strong>
@@ -175,8 +180,11 @@ public Task<SimulationResult> TriggerCpuStressAsync(int durationSeconds, Cancell
175180 /// thread pool remains available for the dashboard and metrics collection.
176181 /// </para>
177182 /// </remarks>
178- private void ExecuteCpuStress ( Guid simulationId , int durationSeconds , int targetPercentage , CancellationToken cancellationToken )
183+ private void ExecuteCpuStress ( Guid simulationId , int durationSeconds , string level , CancellationToken cancellationToken )
179184 {
185+ // Convert level to internal percentage: moderate = 65%, high = 100%
186+ var targetPercentage = level == "moderate" ? 65 : 100 ;
187+
180188 try
181189 {
182190 // Calculate the end time using Stopwatch for high precision
0 commit comments