Question

I has a Heroku R14 error on only one request in my rails app.

And I reproduce production env on my local and view the same page, no errors.

After debug against heroku log. I found the memory increased pretty faster after this request. Here is the memory log.

2013-08-15T08:28:45.104572+00:00 heroku[web.1]: source=heroku.16694287.web.1.95c77962-7288-4bf5-a912-d2db99eab511 measure=memory_total val=113.04 units=MB

2013-08-15T08:29:01.486530+00:00 app[web.1]: Started GET "/issues/98/preview" for 111.174.65.157 at 2013-08-15 08:29:01 +0000

2013-08-15T08:29:01.486530+00:00 app[web.1]: Started GET "/issues/98/preview" for 111.174.65.157 at 2013-08-15 08:29:01 +0000

2013-08-15T08:29:07.330011+00:00 heroku[web.1]: source=heroku.16694287.web.1.95c77962-7288-4bf5-a912-d2db99eab511 measure=memory_total val=220.39 units=MB

2013-08-15T08:29:29.712928+00:00 heroku[web.1]: source=heroku.16694287.web.1.95c77962-7288-4bf5-a912-d2db99eab511 measure=memory_total val=511.97 units=MB

I check the log several times and seems heroku create a new rails instance to process the reqesut and after a while, recreate a new rails instance until it exceeds the memory limit.

I recognized there are two request logs. On my local production env, it also has two logs for every request. And I also debugger the preview action, it only called once. And in development, there are no such log problem. So I think there should be some log config error in production env. But it should not related to heroku memory problem.

The preview request invoke a image render method on Prawn::Document object as

require 'open-uri'
...
# the context is an instance of Prawn:Document
unless image_path.nil?
  f = open(image_path)
  image f, fit: [400, 400]
end    

I pretty sure the bug happened on image line. If I remove the image line, the preview request works. The page will show a pdf without image. If I leave it, then page will blocked and finally memory exceed.

I debug it for one day, no more ideas.

The prawn version is 0.12.0

My rails version is 4.0

Any suggestions?

Était-ce utile?

La solution

After discuss with my team, I got the reason.

The image dimension is 1920*1080, and it seems cant solve such image with Prawn::Document.image on heroku. A 400*400 works.

But dont know why a 27k png image can eatup 400M heroku memory.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top