确定在运行 Google Cloud 函数时的可用内存量的方法是?

huangapple go评论70阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月13日 19:38:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242524.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定