App Engine实例内存不断增加

编程入门 行业动态 更新时间:2024-10-28 10:31:49
本文介绍了App Engine实例内存不断增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

我经常得到的内存超过了错误,所以我想阻止这种持续增加的内存使用。 p>

截图时间:

  • Memcache使用少于1MB

    li>
  • 任务队列为空
  • 流量低(0.2次/秒)

    我期望在这种情况下实例的内存使用量会下降,但这种情况并未发生。

    因为我使用Python自动垃圾收集,我不明白我怎么会造成这种情况。

    这是预期的应用程序引擎行为,有什么我可以解决它吗? p>

    解决方案

    我发现

    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:

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

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

  • 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实例内存不断增加

本文发布于:2023-10-28 13:56:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536821.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   内存   App   Engine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!