Commit 010d3686 authored by Santhosh Kumar's avatar Santhosh Kumar

revert to old cpu usage

parent b1a72fbc
...@@ -40,17 +40,20 @@ def occupy_cpu(percentage): ...@@ -40,17 +40,20 @@ def occupy_cpu(percentage):
cpu_percent = psutil.cpu_percent() cpu_percent = psutil.cpu_percent()
# Adjust the workload based on the difference between actual and desired CPU usage # Adjust the workload based on the difference between actual and desired CPU usage
workload = min(1.0, percentage / cpu_percent) if cpu_percent > 0.1:
workload = min(1.0, percentage / cpu_percent)
else:
workload = 1.0
# Start time # Start time
start_time = time.time() start_time = time.time()
# Perform CPU-bound task # Perform CPU-bound task
while (time.time() - start_time) < (workload): while (time.time() - start_time) < (percentage/100):
pass pass
# Sleep to balance CPU usage # Sleep to balance CPU usage
time.sleep(1 - workload) time.sleep(1 - percentage/100)
@app.route('/occupy_cpu/<int:percentage>', methods=['GET']) @app.route('/occupy_cpu/<int:percentage>', methods=['GET'])
def start_cpu_occupier(percentage): def start_cpu_occupier(percentage):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment