Memory leakage during bulk objects creation

I’ve noticed strange Senaite behavior while creating new objects in bulk or generating a lot of analysis reports via Senaite.Impress. Senaite starts to increase memory utilization and no evidence it is going to release any memory later. When it fills all available memory Senaite restarts with no error messages or warnings. After restart memory utilization rate back to normal.

Any advice on where to look/check for?

I suspect it’s more Plone or Zope-related issue, but probably somebody dealt with it before?

regards,
–leo

Zope keeps objects in memory until the zodb-cache-size is reached, i.e. the number of objects which the ZODB cache will try to hold.
If you run out of memory, try to reduce this number in your buildout.cfg plone.recipe.zope2instance and re-run your buildout.
Anyhow, free memory is wasted memory. This is also the case in Linux environments, which is the reason why memory is never freed and always becomes completely used after a while.

thanks! ))))) you’re right on “free memory is wasted one”. I was just confused that zope silently reboots

if anyone encounters the same problem. just FYI seems that the reason for such behavior sits in Weasyprint library used by Senaite.Impress for PDF rendering: WeasyPrint Issue #1496

This bug will be fixed later. The latest Weasyprint version uses Python3, so that will be possible to use it after project migration to Python3 I guess

FIY UPDATE: Our investigation of the leak leads to next place in the code:

Senaite.Impress/publisher.py : lines 138-140

    def _layout_and_paginate(self, html):
        .....
        # Lay out and paginate the document
        html = HTML(
            string=html, url_fetcher=self.url_fetcher, base_url=self.base_url)
        document = html.render(stylesheets=self.css)
        ....
        return document

This code calls Weasyprint lib which itself causes the leak. work this around solves the issue till migartion of the whole project to Python3

Hi Leonid,
thanks a lot for your efforts tracking this down. I wasn’t aware of this issue and also didn’t notice it on our server monitoring.
How did you work around this issue?
Best regards, Ramon

Hi Ramon,

Well, I can’t say our solution is elegant, but it works.

We do call bash script from our Senaite instance which runs generating routine in Python3 environment and saves result :slight_smile:

And even more, we’ve implemented async reports pre-generation because our lab generates a lot of hi-res documents. When Sample becomes ‘Verified’ it renders Reports previews and PDFs in the background and rerenders each time the object modifies.

regards,
–leo