Under Review
Last Updated: 26 Sep 2022 09:37 by ADMIN
Evgenii
Created on: 09 Sep 2022 15:02
Type: Bug Report
0
Canceling report generation continue to consume resources

Hello

I have a problem with report generating. We use HTML5 report viewer and basic implementation of ReportsControllerBase on server.
I've noticed that we have the CPU/memory recourse consumption after immediately pressing Stop Rendering button. The time of consumption recourses is the same as time without cancelling(about 18-20 second in my example)
There is log with calls of report generating. Last one with cancelling, previous without. 
(see
*** ReportProcessor.ProcessReport DONE in 00:00:16.1918150 ***
and
*** ReportProcessor.ProcessReport DONE in 00:00:16.8522950 ***)

I've investigated how cancelation is working.
The Stop Rendering button send DELETE request to ReportsControllerBase.DeleteReport endpoint. It does something and set IsDeleted flag for document.
Then DocumentCancellationController.ThrowIfCancellationRequested() is called in some specific places in app. You can see that method in log.txt, so it was called after pushing the button.

I've profiled the hot path of generation of report. See hotpath.png.
The most CPU intensive work happens in ReportProcessor.ProcessRepourtSource()...
Pay attention to rendering calls.png - the first red dot here - ReportProcessor.ProcessRepourtSource() call.
The second - where the exception and actual cancelation happens.
I'm expecting it should happen much earlier and cancellation of generation of document(and resources consumption) will finish ASAP.

By the way, I see some cancelation checks in ReportProcessor.ProcessRepourtSource() as well - see throwIfCancellation.png
But cancelation request came after these check and most intensive CPU works already started.


Is it possible to fix that?

3 comments
ADMIN
Todor
Posted on: 26 Sep 2022 09:37

Hi Evgenii,

Unfortunately, there aren't other built-in mechanisms for canceling report generation.

As a workaround, you may check the parameter values chosen by the user, for example in the renderingBegin(e, args) event handler, and decide whether to render the report or cancel it.

For example, you may trigger the stopRendering command - see viewer's commands.

On the above event, you may also change the reportSource of the viewer to a default one when you decide that the selected report with chosen parameter values will take too long.

Regards,
Todor
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Evgenii
Posted on: 19 Sep 2022 18:06
Hello Todor,

Thanks for your answer.

In my case, the report can be constructed using date interval from data picker. So if it's report for 1 day - it's pretty fast.(1 page) If it's 1 year it may take 1 minute or so.(say 11 pages)
Am I right that this cancel button can't help me in that scenario?(by design) Only one options I see - terminate whole process, but it's too much. 
Maybe we have another option to cancel report or optimize that?
ADMIN
Todor
Posted on: 19 Sep 2022 10:18

Hello Evgenii,

I noticed that this is a duplicate of the bug report you have already commented on - HTML5 report viewer cancel button does not cancel report generation on the server. Please, note that this bug was declined as the user who opened the discussion recognized an error in his implementation of the viewer.

Let me also clarify how the cancellation works:

In the case of the report viewers that use Reporting REST service, the report viewer will notify the Reporting service which internally uses the ReportProcessor class to render the report.  This happens automatically when you click on the button that cancels the rendering so you do not need to do anything additional.

Once the CancellationToken is sent to the ReportProcessor, the state of the operation will be updated. Importantly, this will take effect the next time the processor checks the state. For example, after every data item that is rendered, the processor will check for the state and if the operation is canceled, the rendering will be aborted.

If report generation is fast enough, the report may be already rendered before the cancellation token gets received.

In the attached trace log, I noticed that report processing is completed even when the cancellation token was sent. This may happen, for example, if you have only one data item (e.g. the Report itself), and its processing has been started before the report was canceled. This indeed happens in the method Process from the screenshot 'throwifcancellation.png' that accepts the data context as a parameter. If there aren't other data items, there is no place where to check for the state, hence, the processing cannot be aborted.

Note that the rendering process was canceled though. However, it took less than a second, which cannot be sensed.

Regards,
Todor
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.