Possibility Plone 6 or Python 3.11 memory leak?

The instances run after 34 days, and it use more and more memory... also, the site is becoming laggy.

Everything runs faster after restarting the instance.

Anyone have same issue?

We restart our clients weekly. It's not a Problem with Plone 6, its' Plone :wink:

1 Like

Possibly a common behaviour due to various reasons, mostly related to Python. Regular restarts can be considered best practice if you find yourself in such a situation.

It's not a Plone problem, it's caused by using a dynamic language with a runtime that uses GC (Garbage Collection) to free objects in memory and can cause memory fragmentation. It's a well known problem with long running (> 7 days) Python processes that (de)-allocate memory for a lot of objects in memory. For large/busy sites you run multiple servers which you can do rolling restarts for every 2-7 days.

Python 2 had much more issues with this than Python3, but Python 3 can still show this behavior as well. Every design choice has advantages and drawbacks, this is one of the drawbacks.

It doesn't mean however that your specific codebase doesn't have a memory leak in its custom code. But one of the few ways to expose it is to monitor the memory usage over time and watch the graph. If it's a steep rise and then a slow curve to a 'limit' you're fine and this is the normal (de)-allocating of memory slowly going to a maximum. It's comparable to the concept of entropy in physics. If this maximum is bigger than your available server memory, lower the zodb-cache-size or zserver/wsgi threads.

If you see the same curve but then after a while a more straight line, you have a memory leak: per every requst or action somewhere some memory is lost and the used memory continues to grow linearly.

I've seen people increasing the allowed cache sizes and number of threads for Zope, then see Zope using all server memory rather quickly and then draw the conclusion "memory leak". The only way to really test this is to actually lower the threads/zodb-cache size so that after a restart you first see the normal elliptic curve but still have memory space left to observe the linearly increasing memory leak taking over after the normal growth stalls. THEN you have some heuristic proof.

8 Likes

Just out of curiosity: does anybody know about GitHub - bloomberg/memray: Memray is a memory profiler for Python and how it maybe could help to analyze memory consumptions within Plone?

This is because Python 3.11 introduced a change that causes Plone to leak memory.
There are two ways to reduce memory leaks in Plone 6 on Python 3.11:

  • Use the Python garbage collector to collect unused objects. This will reduce the amount of memory that Plone uses, but will slow down your site.
  • Upgrade to Python 3.12. This will fix the memory leak issue and will not slow down your site.
    If you are not running Plone 6 on Python 3.11, you do not need to take any action. :slightly_smiling_face:

Can you point us to a Python issue or likewise to put some meat on the bones?

1 Like