HakanL / WkHtmlToPdf-DotNet

C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
GNU Lesser General Public License v3.0
378 stars 67 forks source link

Execution time increases under load #107

Closed artembrizinskij closed 1 year ago

artembrizinskij commented 1 year ago

Hi! Great project, thanks!

But I have some performance issues under load on .net6+ (windows).

If I do several conversion operations in parallel, the total execution time increases. This is probably due to the fact that I register the converter as a singleton and it becomes a shared resource, with sequential conversion operations.

If I register the converter as transient, the overall execution time is reduced, but memory blocking errors often occur.

            services.AddTransient(typeof(ITools), typeof(PdfTools));
            services.AddTransient(typeof(IConverter), typeof(SynchronizedConverter));

The problem is relevant from 4 or more running operations at the same time, otherwise everything works fast enough

Is there a way to make several operations work in parallel at once?

HakanL commented 1 year ago

The native library is only single-threaded, which is why we need the SynchronizedConverter to make sure access is done one by one. I'm not aware of any way to speed this up inside a single application/process/AppDomain.