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