Menu

#1078 Memory usage since cache removal

v1.0_(example)
open
None
1
2015-09-29
2015-08-18
No

Hi Nicola,,

Since the removal of the disk cache feature, TCPDF became a bit faster (there was not only this - but it's a good part of it) - but also started to eat huge amonts of memory again.
Here is an example, from 6.0.22 to 6.2.11 for the same document :

6.0.22 : This process lasted 1416,31445098 s (24 min), It used 40,25 Mb of ram (current usage is 39,5 Mb)
6.2.11 : couldn't end (yet) the process, I'm hitting 2.8G memory usage before the end of the process

The generated document is big (91 pages) but don't contain much images + no hi-res image (the final PDF is 2Mb only)

I was thinking about adding again a part of the cache process, which would put any page of the object on disk cache when a new page is made (using part of the old code, the only difference is that the function would load from disk or return the page depending on the type of the page data).
It seems to be a nice mix between the old way (everything to disk, even while working on a page) and the new way (nothing to disk till the end).
The security issue has to be handeled though (I remember page deletion was made via a loaded variable)

Would that be a good idea ? Any recommendation ?

Thanks

Discussion

  • Mathieu Masseboeuf

    Actually, I'm no more sure this is related to diskcache usage, as … I was not using it.
    I'll now try to apply the changes from 6.0.99 to 6.1.0 manually to understand where memory is getting hammered.

    Here is the result of my another bach of tests :

    TCPDF 6.0.098 :
    [2015-08-24 19:39:53] Gc is enabled, memory limit at 2G, current memory usage is at 23,25 Mb
    [2015-08-24 19:40:40] Pdf generated : xxx
    This process lasted 47,4544160366 s (1 min)
    It used 108,5 Mb of ram (current usage is 53 Mb)

    TCPDF 6.0.99 :
    [2015-08-24 19:52:07] Gc is enabled, memory limit at 2G, current memory usage is at 23,25 Mb
    [2015-08-24 19:52:51] Pdf generated : xxx
    This process lasted 44,8236570358 s (1 min)
    It used 108,5 Mb of ram (current usage is 53,5 Mb)

    TCPDF 6.1.0 :
    [2015-08-24 19:47:32] Gc is enabled, memory limit at 2G, current memory usage is at 23,25 Mb
    [2015-08-24 19:48:18] Pdf generated : xxx
    This process lasted 46,8104188442 s (1 min)
    It used 164,25 Mb of ram (current usage is 149,75 Mb)

    TCPDF 6.2.11 :
    [2015-08-24 19:32:49] Gc is enabled, memory limit at 2G, current memory usage is at 23 Mb
    [2015-08-24 19:33:31] Pdf generated : xxx
    This process lasted 42,5723860264 s (1 min)
    It used 164 Mb of ram (current usage is 149,5 Mb)

    Thanks.

     
  • Mathieu Masseboeuf

    OK, I found the origin of the problem.

    It was not due to the cache at all - but to a single line :
    register_shutdown_function(array($this, '_destroy'), true);

    That one is placed in the constructor of the object, and created before everything is initialized. Anyway, from what I understood, it would seem that using register_shutdown_function() in this way is keeping PHP from doing any garbage collection until the end of the script. Without this call, PHP is able to garbage collect throughout the script and keep memory usage low.
    Calling it after (I have a subclass, the first thing which I do is telling a function the projet name so it can set the proper log files) won't keep all the memory till the end of the script.
    I'm not sure how to fix that properly though (yet) …

     
  • Mathieu Masseboeuf

    Just to make it clear (can't edit the ticket name), this is not related to cache removal, but to changes in the way objects get destroyed by register_shutdown_function

     

Log in to post a comment.

MongoDB Logo MongoDB