Welcome Guest Search | Active Topics | Sign In | Register

Multi-threading - safe? Options
Voicebooth Ltd
Posted: Thursday, February 1, 2018 2:32:27 AM
Rank: Member
Groups: Member

Joined: 7/17/2016
Posts: 17
Hi guys,

I had a peculiar incident in our production environment last night that we haven't been able to reproduce, but there's some suspicions it may be a multi threading problem related to EO.Pdf.

We use EO.Pdf in a Windows service to generate invoice PDFs, and in order to speed things up the service has multiple task processors which can each generate a PDF at a time. We have as many task processors as there are CPU cores on the server, so 8 in this instance.

In each thread, we run the following method before generating a PDF, to ensure the current thread had the correct settings before calling HtmlToPdf.ConvertHtml():

Code: C#
public void EnsureSettings()
{
   HtmlToPdf.Options.PageSize = PdfPageSizes.A4;
   HtmlToPdf.Options.OutputArea = new RectangleF(0, 0.5f, 8.263889f, 10.6944447f);
   HtmlToPdf.Options.BaseUrl = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configuration.Storage.Path);
   HtmlToPdf.Options.NoCache = true;
   HtmlToPdf.Options.JpegQualityLevel = 100;
   EO.Base.Runtime.EnableEOWP = true;
}


What we experienced last night was the service using up 100% CPU on every core, rendering the server pretty useless and ultimately having to kill the service to restore things to normal. This indicates each task processor started generating one invoice each, but effectively "hung" without doing much other than using up all available CPU time.

We generate the invoice using:

Code: C#
HtmlToPdf.ConvertHtml(invoiceContent, stream);
HtmlToPdf.ClearResult();


Where invoiceContent is a pre-rendered string, and stream is the output file to write to.

We are using EO.Total 2017 version 17.1.65.0

Is there anything we should be aware of when using EO.Pdf in a multi-threaded environment? Is there a danger that internally it created a race condition between the different threads, which caused the process to use up all the CPU and hang?


Regards,
Alvaro
eo_support
Posted: Thursday, February 1, 2018 8:29:16 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi,

Please try the following:

1. Update to the latest build and see if it resolves the issue for you. Your code is correct, however we do constantly receive issues report from our customers and have fixed many over time. We have also added code to handle rare scenarios (for example, recovering from low resource condition) better. So the new version might resolve the issue for you;

2. Check the page you are converting at that time. One way for CPU to hang is you have JavaScript code in your page that never stops (such as an infinite loop). So you may want to add some logs to log the HTML that you are converting in case this happens again;

3. If you do switch to the latest build and this happens again and you are able to wait for a bit, you can run Remote Debug Monitor and contact us so that we can inspect the running state of our component remotely. You do need the latest build in order to use this option (because we only maintain debug environments for recent builds). The other limitation is you can't use this option if you must restart your application right away ---- we are working on adding a debug dump feature to our Remote Debug Monitor so that in the future you will be able to capture a dump and send it to us;

Hope this helps.

Thanks!
Voicebooth Ltd
Posted: Thursday, February 1, 2018 8:34:58 AM
Rank: Member
Groups: Member

Joined: 7/17/2016
Posts: 17
The file being converted had no javascript in it, and all resources (HTML, CSS, images) were held locally on the server.

I'll give the latest version a try after some testing and see if this happens again in the future.

In the case of remote debugging, the only way to get around the 100% CPU usage (which, due to it happening on all 8 cores, had a knock on effect on all other services and responsiveness to the server) was to kill the service off, would the Remote Debug feature have worked in this instance?
eo_support
Posted: Thursday, February 1, 2018 8:44:01 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
It should still work but just very very slow. One thing you can try is to use the task manager to find out exactly which process is really eating up the CPUs as we use child processes so it can be one of the child process. If that's the case you can just kill one of the child process to free up a little bit CPU power (assuming that such action won't bring everyone else out of this high CPU state).


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.