Too much memory usage

Hello,
I have a site under zope 5 which has been running for a few months. I noticed that Zope is increasing in memory usage. I even had a memory saturation which forced me to restart my processes.
How can I avoid increasing memory usage? Is there a command to execute to free memory.
Thank you

I usually add a job in my crontab to restart the instances periodically.
Weekly, nightly or whenever is needed.

I know other people disagree with this approach but it works for me.

To have a complete picture I suggest you to have a look to:

1 Like

Usually, you cannot. Unlike (e.g.) Java, Python does not have a compacting garbage collector. As a consequence, memory fragmentation builds up over time and causes increased memory usage. Python 3 has a function to monitor Python's memory management and the Linux C library allows to monitor its memory management (--> mallinfo2). Together, they allow to estimate the fragmentation degree.

Usually, the fragmentation growth rate decreases over time. If you observe this behavior, you almost cannot do anything (apart from restarting).

If you observe that the memory growth rate does not decrease, then you may have a memory leak. Usually, memory leak analysis is very expensive. Thus, even if you could do something about memory leaks, you might choose to just restart the process.

1 Like

OK, thanks.
This is very annoying for a high availability site, whose activity on the zodb is important.
I will first set up an automatic restart cron.

It shouldn't make any difference if you are using ZEO/loadbalancing/caching and stagger the restarts.

2 Likes

Unless we use session data. Users connected to an instance will be disconnected when the instance restarts! Am I fair?

You should not use Zope sessions, at least not on the default tempstorage. tempstorage does not work reliably with modern ZODB versions.

A client is using Zope sessions on a FileStorage (accessed via ZEO). This way sessions remain active across process restarts. Note that Plone's CSRF protection relies on session data being maintained in a storage with name temporary.

Ok, do you know where I can find the documentation or an example configuration to migrate the storage "transient object container" to a FileStorage. what would be the impacts on my code to read / write in my session
thank you

You read the plone.recipe.zope2instance documentation (--> PyPI) to find out how to take control over the session configuration. I do not know how this works: it is possible that you can only configure "with" or "without sessions". I know that the recipe has an option to add arbitrary definitions to the generated configuration file. However you do it, your aim is to replace the temporarystorage definition in the configuration file by a filestorage or zeoclient. This definition will much resemble that of the main database (lwith a different file/remote storage); the remaining parts of the zodb_db temporary section should remain unchanged. If you use ZEO, you configure the new session storage for it (again similar to the definition for main).

Plone Foundation Code of Conduct