简体   繁体   English

Google Cloud Run:脚本需要很少的 memory,但达到 memory 限制

[英]Google Cloud Run: script requires little memory, yet reaches memory limit

On Google Cloud Run, I have a Python script that requires a small amount of memory. According to tracemalloc the peak memory is of the order of 20 Mb.在 Google Cloud Run 上,我有一个 Python 脚本,它需要少量的 memory。根据tracemalloc ,峰值 memory 约为 20 Mb。 Yet, about 1 of 4 runs fails:然而,大约 4 次运行中有 1 次失败:

"Memory limit of 512 MiB exceeded with 516 MiB used." “使用了 516 MiB,超出了 512 MiB 的内存限制。”

Furthermore, in the "Cloud Run Metrics" it says that "Container memory utilization" of all runs is higher than 70%.此外,在“Cloud Run Metrics”中,它表示所有运行的“容器 memory 利用率”高于 70%。

What could be the reason?可能是什么原因? Could this be explained by any memory overhead of Google Cloud Run?这可以用 Google Cloud Run 的任何 memory 开销来解释吗? If yes, what is the order of magnitude of this memory overhead?如果是,这个memory开销的数量级是多少? What can I do to reduce the memory usage?我可以做些什么来减少 memory 的使用? Any other suggestions or solutions?还有其他建议或解决方案吗?

Thanks in advance!提前致谢!

The memory footprint of Cloud Run is not only your Python script, but your whole container. Cloud Run 的 memory 足迹不仅仅是你的 Python 脚本,而是你的整个容器。 You have to measure the memory footprint of your container to have an idea of the required memory on Cloud Run.您必须测量容器的 memory 占用空间,才能了解 Cloud Run 上所需的 memory。 If you use Docker, docker stats can help you on that task (on your local environment)如果您使用 Docker,docker docker stats可以帮助您完成该任务(在您的本地环境中)

You can also choose smaller base image, remove useless binaries/libraries,... to reduce the memory footprint您还可以选择较小的基本映像,删除无用的二进制文件/库,...以减少 memory 占用空间

Somehow, with each run, the memory in the container kept growing, hitting the memory limit after a couple of runs.不知何故,每次运行时,容器中的 memory 都在不断增长,在几次运行后达到 memory 的限制。

Finally, I was able to solve it by adding最后,我能够通过添加来解决它

import gc
...
gc.collect()

In both Docker and Google Cloud Run, after each run, the memory is now cleaned up.在 Docker 和 Google Cloud Run 中,每次运行后,memory 现在都被清理了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift Google Cloud Firestore 侦听器 Memory 问题/应用程序崩溃 - Swift Google Cloud Firestore Listener Memory Issue / App Crash 谷歌云笔记本实例运行脚本不在启动 - google cloud notebook instance run script not in startup Google Cloud Platform:如何监控 memory VM 实例的使用情况 - Google Cloud Platform: how to monitor memory usage of VM instances Cloud Run,每个实例的理想 vCPU 和 memory 数量? - Cloud Run, ideal vCPU and memory amount per instance? 如何对 Google Cloud Build 进行身份验证以调用需要身份验证的 Cloud Run 服务? - How to authenticate a Google Cloud Build to invoke a Cloud Run service that requires authentication? 如何使用 Google Cloud Run 运行“hello world”python 脚本 - How to run a "hello world" python script with Google Cloud Run 谷歌云平台限制定价 - Google Cloud Platform limit the pricing 如何在特定文件集从谷歌云到达云存储时启动云数据流管道 function - how to launch a cloud dataflow pipeline when particular set of files reaches Cloud storage from a google cloud function 如何在谷歌云中运行 tmux session 作为 startup_script? - How to run a tmux session as startup_script in google cloud? Firebase Cloud Function - 容器工作者超过 256 MiB 的内存限制,在服务 29 个请求后使用了 258 MiB - GenerateThumbnail - Firebase Cloud Function - Container worker exceeded memory limit of 256 MiB with 258 MiB used after servicing 29 requests - GenerateThumbnail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM