Question

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):

  • Click on my nice and shiny Split to images button
  • Download finishes almost in an instant
  • image.Read(), where it reads the PDF takes A LOT of time to finish (sometimes between 2-8 minutes), and every time, my browser responds with a blank (white) page.
  • I leave the browser's white page as it is, and go ahead and monitor the server again. In the folder where the conversion happens, the server SLOOOWLY starts writing each 60KB image in the folder ( For a 6-page PDF with a size of 1.7MB this whole process might take anywhere from 5-15 minutes, with server being extremely sluggish at that time and also, slightly afterwards)

Test conversion #2:

  • Replaced everything mentioned on the description above, with its x64 version. Same thing.

Test conversion #3/#4:

  • Replaced Magick.NET x86/x64 Q16 with Magick.NET x86/x64 Q8

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
Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top