Worker terminated due to reaching memory limit: JS heap out of memory



  • We have deployed jsreport (4.10.1) on a dedicated VM in the Production environment.
    Configuration is as follows -
    RAM: 32GB
    CPU: 4 Cores
    Architecture: x64
    (non-containerised)
    numberOfWorkers: 1

    We keep getting Worker terminated due to reaching memory limit: JS heap out of memory once in a while. And it gets crashed and restarts after that.

    Could you please let us know if we need to change any configurations or settings to avoid this issue?

    Following is the error screenshot:
    0_1761727027267_upload-8b6e3935-b88f-42f9-8f09-70edfa5b93f1

    Let us know if you need any additional details.

    We have some queries:

    Could you please let us know the default heap size?

    How many percentage of RAM should be allocated to heap?

    If we have set only one worker then why are we getting heap size limit issue?

    Do references held by previous renders get freed up after report rendering finishes?

    Please let us know so that we will be able to monitor and set appropriate configurations.



  • See this config
    https://jsreport.net/learn/configuration#workers
    https://nodejs.org/api/worker_threads.html#worker_threads_worker_resourcelimits

    Could you please let us know the default heap size?

    These are the runtime/nodejs settings.
    Each thread gets the same default limit as the main thread
    ~1.5 GB on 64-bit systems

    How many percentage of RAM should be allocated to heap?

    There is no rule of thumb, try what works best for you.
    The main thread can remain in default, and the rest can be divided among workers.

    If we have set only one worker then why are we getting heap size limit issue?

    Because every worker has the nodejs default limit.

    Do references held by previous renders get freed up after report rendering finishes?

    nodejs is the garbage-collected runtime. So it gets cleaned from memory when the GC gets triggered by the runtime.



  • Hi,

    I’m experiencing a very similar issue, but specifically related to xlsx templates and different jsreport versions.

    While testing, I noticed a significant performance difference between jsreport 2.11 and jsreport 4.12.

    Starting from two clean images (fresh containers with default configuration), the execution time of the same xlsx template is much slower on 4.12 compared to 2.11. In our case this has a very negative impact on heavy customer reports, which are quite large.

    With 2.11 the report completes successfully and relatively fast.
    With 4.12 the same report often ends up consuming much more memory and eventually the container crashes with:

    Worker terminated due to reaching memory limit: JS heap out of memory

    In production this becomes problematic because large reports can easily trigger an out-of-memory condition, while the exact same template works without issues on the older version.

    The problem is very easy to reproduce using the official Docker images:

    docker run -p 5488:5488 jsreport/jsreport:2.11.0
    docker run -p 80:5488 jsreport/jsreport:4.12.0

    Running the same xlsx template on both instances clearly shows the difference in performance and memory usage.

    I’ve prepared a minimal reproducible example starting from a simple Excel template, and I’m attaching a URL with the sample Excel file used for the test.
    File excel:
    https://docs.google.com/spreadsheets/d/1IKceiO1fEWLTqOKw2tzjdWNuls5In7uN/edit?usp=sharing&ouid=105405265111194914502&rtpof=true&sd=true
    export:
    https://drive.google.com/file/d/18q2cVxPUBsn75Cd2-nZyu7XsZTMInpZ7/view?usp=sharing

    Also on chrome-pdf I have similar difference and a constant increasing of container memory even with the "dedicated-process" strategy.

    Thanks!



  • Hi,

    In addition, here is a simple reproduction of the 'JS heap out of memory' error in the playground.

    It loads a simple XLSX template having 3839 lines (1.1 MB) without any transformation nor templating tasks. Just print the template.

    https://playground.jsreport.net/w/jb-liger_lectra1/h4~axBkn

    Thanks for your help !


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.