serge
serge

Reputation: 366

Terrible performance when converting PDF to Images

I have assigned the task to convert individual PDF pages to JPEGs.

Using Magick.NET, I was able to get very decent conversion speed on any local computer I ran my project on.

My live environment is under Amazon's Elastic Beanstalk, using an EC2 instance. It is a t1.micro instance with 615MB RAM and ~1.83GHz worth of CPU.

When my project was deployed, I was using Magick.NET x86 Q16, Ghostscript x86, and Visual C++ Redistributable VS2012 x86 both on my computer and on the server.

The code downloads the PDF from the S3 Bucket and saves it locally, hence the conversion also happens locally.

This is where it start to get weird.

Time for test conversion #1 (I also have an RDP window open to the server for monitoring):

Test conversion #2:

Test conversion #3/#4:

Same thing again.

During each conversion the CPU is at 100% and memory around 70%

My code is as follows:

Dim response As GetObjectResponse = client.GetObject(req)

Try

    Using response
        Dim dest As String = Path.Combine(Server.MapPath("~/S3"), EnvName)

        If Not File.Exists(dest) Then
            response.WriteResponseStreamToFile(dest)
        End If
    End Using

    Dim settings As New MagickReadSettings
    settings.Density = New MagickGeometry(300, 300)

    Dim images As New MagickImageCollection

    Using images
        images.Read(Server.MapPath("~/S3/" & EnvName & ""), settings)

        Dim pageCount As Integer = 1

        For Each img As MagickImage In images

            img.Resize(700, 900)
            img.Format = MagickFormat.Jpeg
            img.Trim()
            img.Write("~/S3/" & EnvName & "_Page_" & pageCount & ".jpeg")

            Literal1.Text &= "Page " & pageCount & " is done" 'For debugging purposes
            pageCount += 1
        Next

        Literal1.Text &= "Success"
    End Using

Catch ex As Exception
    Literal1.Text = ex.ToString
End Try

Upvotes: 0

Views: 526

Answers (2)

E.J. Brennan
E.J. Brennan

Reputation: 46879

T1 micro instances are the equivalent power of a very low end laptop that you buy at walmart (almost) - not to say that they are not very useful for a lot of things, but hi powered, cpu intensive processing in a Windows environment is not one of them.

Easiest thing to do is spin up a more appropriately sized instance and see if your problem magically goes away.

Upvotes: 3

Domin8urMind
Domin8urMind

Reputation: 1314

You might want to switch to using the new PDF API's that come with windows. Reliable and fast.

http://msdn.microsoft.com/en-US/library/windows/apps/windows.data.pdf.aspx

Upvotes: 0

Related Questions