Majority of reports being rendered through jsreport are just several number pages long pdf files. However some users needs to render pdf reports with hundreds or even thousands of pages. I was giving these users support during the last weeks and decided to blog post about it and describe what are the configuration options you need to set when receiving errors from the long reports rendering.
Rendering templating engine is usually very quick and it rarely takes longer than 5 seconds. But when you have complex computations in helpers you may need to increase the default timeout for it. Note that all timeouts are specified in ms.
"templatingEngines": {
"timeout": 600000
}
To increase scripts use this configuration.
"extensions": {
"scripts": {
"timeout": 600000
}
}
Pdf rendering on the other hand is the most time consuming task. It can easily take couple of minutes to render for longer reports. The timeout for chrome-pdf recipe can be set like this.
"chrome": {
"timeout": 600000
}
This will make timeout general also for the html-to-xlsx. If you want to set specific timeout just for the chrome-pdf recipe, use this config.
"extensions": {
"chrome-pdf": {
"timeout": 600000
}
}
Slow performance of pdf rendering is usually caused by intensive styling. To optimize the performance you need to find the particular style causing problems. This is difficult and there is no rule of thumb which styles are the cause. I usually remove all styles and try to add all of them step by step and check the performance during it.
To block the requests with a bad intentions jsreport has limits for input sizes. If you have a huge report input data you may also need to increase inputRequestLimit
.
"express": {
"inputRequestLimit": "200mb"
}
Bigger reports can also reach the default node.js memory limit with error 'Allocation failed - JavaScript heap out of memory'. This can be mostly fixed by increasing the limit .
Set the NODE_OPTIONS
environment variable
NODE_OPTIONS=--max-old-space-size=6096
Run jsreport
jsreport start
Child templates are great and sometimes a must. However there is performance trade off to consider, because child templates always run through the whole rendering pipeline. Don't use them if you can replace them with assets. If you can't and render many of them, try to change the templating engines evaluation strategy to http-server
or in-process
to avoid creating too many evaluation processes.
"templatingEngines": {
"strategy": "http-server"
}
Pdf utils are typically used to merge custom headers. If you render many pages, you should always select "merge whole document" option. Otherwise there will be extra header rendering for every page.
The next problem can be caused by the closed http connection during the api call on /api/report
. This is because the connection also has some timeouts when nothing is being transferred for a long time.
"extensions": {
"express": {
"renderTimeout": 600000
}
}
All of the previous settings are the jsreport server options, but the last one you may need to set is on the client side. Client rest libraries usually has default timeouts and you may need to increase it. The following code shows how to do it in c# client.
ReportingService.HttpClientTimeout = TimeSpan.FromMinutes(20);