0

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
dlemstra
  • 7,813
  • 2
  • 27
  • 43
serge
  • 366
  • 1
  • 4
  • 22

2 Answers2

3

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.

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
  • 2
    Exactly. Micro instances, unlike all the other instance classes, degrade their available CPU power substantially after just a few seconds of heavy load. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts_micro_instances.html With the uunderpowered CPU, the white screen in the browser is happening because the ELB times out after 60 seconds. – Michael - sqlbot Apr 30 '14 at 11:29
  • For anyone that might not have the ability at a point to change instances, switching to Ghostscript.NET will save alot of sweat down the road! – serge May 07 '14 at 06:24
0

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

Domin8urMind
  • 1,314
  • 8
  • 10
  • My development environment is using Windows 7. Unfortunately, I haven't got the option to upgrade. Also, I am using ASP.NET, not Windows Store Apps – serge Apr 30 '14 at 06:48
  • Also available on Windows Server 2012 R2. – Domin8urMind Apr 30 '14 at 06:57
  • OK, so how do I use it in my development environment (Win7 VS2012) ? – serge Apr 30 '14 at 07:00
  • Sorry, obviously you would need to upgrade your environment. :-/ To offer another suggestion, have you captured any other Performance counters such as [.NET Memory](http://msdn.microsoft.com/en-us/library/x2tyfybc(v=vs.110).aspx) or the other [.NET counters](http://msdn.microsoft.com/en-us/library/w8f5kw2e(v=vs.110).aspx) that are available? – Domin8urMind Apr 30 '14 at 07:12
  • No worries. I actually have not (never used these counters before). My initial thought was that since in my dev-env, eveything happens in an instant, then the live-env could possibly lack the resources. But it seems, from my understanding, that it's not the resources' fault. – serge Apr 30 '14 at 07:18