App Engine 实例内存不断增加 [英] App Engine instance memory constantly increasing

查看:23
本文介绍了App Engine 实例内存不断增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的应用引擎实例 (Python) 的内存使用量在初始启动期后相对平稳.对我的应用程序的每个请求都是短暂的,似乎应该在不久之后释放单个请求的所有内存使用情况.

然而,实际情况并非如此.下面是控制台提供的实例内存使用情况的快照.我的应用程序流量相对较低,所以我通常只运行一个实例.在图表中的两天期间,内存使用趋势不断增加.(这两个 blip 是两个实例短暂运行的地方.)

我经常遇到内存超出错误,所以我想防止内存使用量的持续增加.

快照时:

  • Memcache 使用不到 1MB
  • 任务队列为空
  • 流量低(0.2 次/秒)

我希望实例内存使用量在这些情况下会下降,但事实并非如此.

因为我使用的是带有自动垃圾收集功能的 Python,所以我不知道我是如何导致这种情况的.

这是预期的应用引擎行为吗?我可以做些什么来修复它?

解决方案

我发现了

I'd expect the memory usage of my app engine instances (Python) to be relatively flat after an initial startup period. Each request to my app is short lived, and it seems all memory usage of single request should be released shortly afterwards.

This is not the case in practice however. Below is a snapshot of instance memory usage provided by the console. My app has relatively low traffic so I generally have only one instance running. Over the two-day period in the graph, the memory usage trend is constantly increasing. (The two blips are where two instances were briefly running.)

I regularly get memory exceeded errors so I'd like to prevent this continuous increase of memory usage.

At the time of the snapshot:

  • Memcache is using less than 1MB
  • Task queues are empty
  • Traffic is low (0.2 count/second)

I'd expect the instance memory usage to fall in these circumstances, but it isn't happening.

Because I'm using Python with its automatic garbage collection, I don't see how I could have caused this.

Is this expected app engine behavior and is there anything I can do to fix it?

解决方案

I found another answer that explains part of what is going on here. I'll give a summary based on that answer:

  1. When using NDB, entities are stored in a context cache, and the context cache is part of your memory usage.

  2. From the documentation, one would expect that memory to be released upon the completion of an HTTP request.

  3. In practice, the memory is not released upon the completion of the HTTP request. Apparently, context caches are reused, and the cache is cleared before its next use, which can take a long time to happen.

For my situation, I am adding _use_cache=False to most entities to prevent them from being stored in the context cache. Because of the way my app works, I don't need the context caches for these entities, and this reduces memory usage.

The above is only a partial solution however!

Even with caching turned off for most of my entities, my memory usage is still constantly increasing! Below is snapshot over a 2.5 day period where the memory continuously increases from 36 MB to 81 MB. This is over the 4th of July weekend with low traffic.

这篇关于App Engine 实例内存不断增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆