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
367 stars 66 forks source link

Is it possible to run multiple conversions in parallel? #45

Closed DmitriiGaidukov closed 3 years ago

DmitriiGaidukov commented 3 years ago

In my ASP.NET Core app, I run into a problem with the Synchronized converter that multiple web requests are queued on a single thread instead of running in parallel and/or utilizing all cores. I take it it is the expected behavior:

Use this converter in multi threaded applications and web servers. Conversion tasks are saved to blocking collection and executed on a single thread.

Is there a way to work around this limitation? For ASP.NET Core apps it's a really big issue as they are inherently multithreaded.

HakanL commented 3 years ago

I think it's a limitation in the native library, that it doesn't support multiple concurrent calls. But I may be wrong, this "feature" was in the original code before I forked it.

ognjenkurtic commented 3 years ago

@DmitriiGaidukov what error message are you getting?

DmitriiGaidukov commented 3 years ago

@ognjenkurtic no an error as such, I just noticed when multiple web requests perform conversion simultaneously, they do it one at a time, e.g. if a few web requests started doing the conversion at the same moment and for the first one it took 100 ms, then it would be 200 ms for the second, 300 ms for the third, etc. And an increase in the number of simultaneous conversions doesn't increase the load on the CPU.

HakanL commented 3 years ago

I'm pretty sure the native library is single-threaded so that's why it will serialize the requests. I'm not aware of any way to work around that.