Знаете ли вы какое-нибудь решение?
Я брошу сюда код, который я использую для трекера в если это поможет (трекер — это функция-декоратор, однако это не связано с проблемой
Код: Выделить всё
import psutil
import os
import time
def process_memory():
"""
Use the psutil library to access the memory statistics of the process using the ID obtained with os.getpid().
The returned value corresponds to the Resident Set Size (RSS),
which is the portion of the process's memory stored in RAM.
Returns:
int: RAM memory used by the process (in bytes).
"""
process = psutil.Process(os.getpid())
mem_info = process.memory_info()
return mem_info.rss
def Tracker(func):
def wrapper(*args, **kwargs):
#####################################
## -- Before Function Execution -- ##
#####################################
# Measure Memory
mem_before = process_memory()
# Measure CPU percentage
psutil.cpu_percent(interval=None)
time.sleep(1)
##############################
## -- Function Execution -- ##
##############################
responses, final_tracker = func(*args, **kwargs)
###########################
## -- After Execution -- ##
###########################
# Measure memory
mem_after = process_memory()
consumed_memory = (mem_after - mem_before) / (1024 ** 2) # Convert bytes to MB
# Measure CPU percentage
cpu_usage = psutil.cpu_percent(interval=None)
final_tracker = {
"Memory Consumed (MB)": consumed_memory,
"CPU Consumed (%)": cpu_usage
}
return responses, final_tracker
return wrapper
Я пытался изменить конфигурацию запуска облака, чтобы установить ЦП как всегда выделенное ( это не работает)
Подробнее здесь: https://stackoverflow.com/questions/787 ... -cloud-run