Hi, I'm using Magick.NET-Q8-AnyCPU v7.3.0 with Ghostscript for converting pdf and eps files to png in an Azure Function.
Everything works ok, but performance is very slow.
For comparison image conversion that runs in an ASP.Net Core application on .NET47 inside Azure App Service takes about 10 second to process an eps file.
Same file takes sabout 45 seconds to convert when hosted as Azure Function.
Azure Function CPU utilization is only about 3% when conversion is running. (Application Insights monitoring)
How can this be a such a difference?
There is a performance penalty when the application starts because of initialization but I don't think that should take 35 seconds. Is there an "always on" feature that would allow you to keep the pool running?
Do you know the amount of memory that your function can use? It is possible that it will swap to disk. You could enable debugging logging and write that to the function log to get more info.
Always on is set to ON. It's not due to app start because its still slow after app warmup. We are logging how long each function step takes, and the actual conversion is cca 45 seconds.
Amount of available memory should be cca 1GB.
If we output Magick.NET logging to Azure Function log and paste it here, would that help?
That should give us both some insight on the part that is causing the slowdown. Might be better to add a link to a file in case the log gets to big.
ImageMagick log events (I've set level to all)
log-magick.log
Setting the LogLevel to All is not sufficient to get all the logging. I will make sure this gets changed in the next release to fix the confusion. This always confuses me also. I will rename All to Detailed and change All to Detailed | Trace.
Without seeing the rest it looks like it is slow inside the Ghostscript part that reads the EPS file. Can you add another file with more info? You will need to change your log level to All | Trace to get more info.
All | Trace
log-magick.log
There are two lines in the log that have a huge difference:
Trace: 2018-02-02T10:23:25+00:00 2:46.266 8.031u 7.0.7 Trace w3wp.exe[1260]: delegate.c/GetDelegateCommands/1122/Trace
...
Resource: 2018-02-02T10:24:12+00:00 3:33.250 9.984u 7.0.7 Resource w3wp.exe[1260]: resource.c/RelinquishUniqueFileResource/1141/Resource
D:/home/site/wwwroot/magick-temp/magick-1260Sx3O3dmLn75E
I looked in the ImageMagick source code to see what happens there and it looks like it takes around 47 seconds to read the file with Ghostscript. How are you telling Magick.NET where it can find the Ghostscript files and which files did you upload?
Hi Dirk, I just resolved the issue. Thanks for helping me debug.
The problem was with setting temp directory (which ghostscript also uses). In Azure function I've set a working directory inside app bin folder. The problem with this is that Function apps wwwroot folders are actually persisted in Azure Storage blobs, they use network folder sharing to give the instance access to it's files so while ghostsript reads/writes to temp files it takes long because of network latency.
Setting Magick temp folder to d:\local\magick-temp resolved the issue, but you must create this folder each time function starts because it will disappear when it completes
Happy to hear that you could resolve your issue. And thanks for coming back to share what caused the slowdown.
@dlemstra is there any documentation on how to use Magick in a Azure function? The installation said everything is fine, but it shows an error it cant find it? Adding the very short project.json file as a *.txt.
project.txt
@Roesler It is probably better to open a new issue instead of hijacking this one. And if you are lucky @mario-mestrovic can give you some instructions.
@Roesler It is probably better to open a new issue instead of hijacking this one. And if you are lucky @mario-mestrovic can give you some instructions.
@dlemstra Thank you for quick answer. Created new issue: #369
Couldn't find a more suitable thread so posting on this one. Was wondering if there was any documentation on how to get this working in .NET on Azure?