forked from iam-veeramalla/aws-devops-zero-to-hero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86d9246
commit 841a416
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import time | ||
|
||
def simulate_cpu_spike(duration=30, cpu_percent=80): | ||
print(f"Simulating CPU spike at {cpu_percent}%...") | ||
start_time = time.time() | ||
|
||
# Calculate the number of iterations needed to achieve the desired CPU utilization | ||
target_percent = cpu_percent / 100 | ||
total_iterations = int(target_percent * 5_000_000) # Adjust the number as needed | ||
|
||
# Perform simple arithmetic operations to spike CPU utilization | ||
for _ in range(total_iterations): | ||
result = 0 | ||
for i in range(1, 1001): | ||
result += i | ||
|
||
# Wait for the rest of the time interval | ||
elapsed_time = time.time() - start_time | ||
remaining_time = max(0, duration - elapsed_time) | ||
time.sleep(remaining_time) | ||
|
||
print("CPU spike simulation completed.") | ||
|
||
if __name__ == '__main__': | ||
# Simulate a CPU spike for 30 seconds with 80% CPU utilization | ||
simulate_cpu_spike(duration=30, cpu_percent=80) |