英文:
How to determine the amount of free memory when running a google cloud function?
问题
当运行Google Cloud函数时,内存大小可以设置(https://cloud.google.com/functions/docs/configuring/memory)。
如果我选择 512MB
,我如何确定加载我的库后剩余的512MB中有多少是空闲的?例如,如果我需要加载和处理大小为12MB的数据,并且加载我的库需要500MB,那么我将没有足够的内存。而如果加载我的库需要250MB,那么我可能会有足够的内存。
我正在使用Python,如果有什么东西我可以输出到日志,然后在GCP日志资源管理器中检查,那将非常有用。
英文:
When running a google cloud function the memory size can be set (https://cloud.google.com/functions/docs/configuring/memory).
If I select 512MB
, how can I determine how much of that 512MB is free after loading my libraries ? So for example - if I need to load and process data that's 12MB in size, and it takes 500MB to load my libraries, I won't have enough memory. Whereas if it takes 250MB to load my libraries I probably will have enough memory.
I'm using Python, if there's something that I can output to a log and then inspect in the gcp logs explorer that would be useful
答案1
得分: 3
You can use psutil virtual_memory 来确定已使用多少内存和可用内存。
但是您需要使用 pip install psutil
安装该库。
至于 Python 运行时,最近可用,但对于 Node.js,您可以使用以下代码获取可用内存:
const freeMemory = process.memoryUsage();
参考链接:Node.js process.memoryUsage() 方法
英文:
You can use psutil virtual_memory to determine how much memory is used and how much is available.
But you will need to install that library using pip install psutil
.
As python runtime is now recently available but for node js one you can use following to get the available memory:
const freeMemory = process.memoryUsage();
Reference for this : Node.js process.memoryUsage() Method
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论