照片上传后的服务器超时

时间:2015-07-13 03:40:45

标签: ruby-on-rails postgresql heroku amazon-s3 carrierwave

我正在使用Postgres爱好基本数据库进行Heroku的爱好计划。当我使用导入到Amazon S3的载波gem上传图像时,服务器超时。上传将会发生,但它需要一段时间才能处理。如果我上传一张或四张照片,也会出现同样的问题。

有人知道我可以做些什么来解决这个问题吗?创建照片时,由于我在整个应用程序中使用不同形状的照片,因此创建了8个不同大小的版本。

我在下面列出了日志。

Jul 12 20:31:27 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:27 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1a6fce8 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-19cl8ow>, @original_filename="1.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"1.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:27 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:27 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1a6fce8 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-19cl8ow>, @original_filename="1.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"1.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:27 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:27 +0000
Jul 12 20:31:27 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:27 +0000
Jul 12 20:31:27 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:27 +0000
Jul 12 20:31:27 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:27 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1cc5c90 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-1rfxaqg>, @original_filename="2.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"2.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:27 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1cc5c90 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-1rfxaqg>, @original_filename="2.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"2.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:27 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:27 +0000
Jul 12 20:31:27 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:27 +0000
Jul 12 20:31:27 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:27 +0000
Jul 12 20:31:27 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:27 +0000
Jul 12 20:31:27 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:27 +0000
Jul 12 20:31:27 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:28 domain app/web.1: Attempting to optimize a jpeg without jpegoptim installed. Skipping...
Jul 12 20:31:29 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:29 domain app/web.1: Attempting to optimize a jpeg without jpegoptim installed. Skipping...
Jul 12 20:31:29 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:29 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1deaf80 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-8t5ly3>, @original_filename="5.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"5.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:29 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1deaf80 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-8t5ly3>, @original_filename="5.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"5.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:29 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:29 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:30 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1e7c750 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-12sz8qi>, @original_filename="3.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"3.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:30 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1e7c750 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-12sz8qi>, @original_filename="3.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"3.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:31 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:31 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1d0c820 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-28n50x>, @original_filename="4.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"4.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:31 domain app/web.1:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"M/h0eb77xtTjaeex2yi+rOPV+N2OA/nSd6X8HA69xyg=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb9c1d0c820 @tempfile=#<Tempfile:/tmp/RackMultipart20150713-3-28n50x>, @original_filename="4.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"4.jpg\"\r\nContent-Type: image/jpeg\r\n">}}
Jul 12 20:31:31 domain app/web.1: Processing by PhotosController#create as JS
Jul 12 20:31:31 domain app/web.1: Attempting to optimize a jpeg without jpegoptim installed. Skipping...
Jul 12 20:31:34 domain app/web.1: Attempting to optimize a jpeg without jpegoptim installed. Skipping...
Jul 12 20:31:39 domain app/web.1: Attempting to optimize a jpeg without jpegoptim installed. Skipping...
Jul 12 20:31:57 domain heroku/router: at=error code=H12 desc="Request timeout" method=POST path="/photos" host=domain.com request_id=461e639a-52d9-423d-9159-425b6422dc63 fwd="73.54.214.248" dyno=web.1 connect=0ms service=30163ms status=503 bytes=0
Jul 12 20:31:57 domain heroku/router: at=error code=H12 desc="Request timeout" method=POST path="/photos" host=domain.com request_id=93120ab9-e570-45b3-b663-a8635355c0b3 fwd="73.54.214.248" dyno=web.1 connect=1ms service=30220ms status=503 bytes=0
Jul 12 20:31:57 domain heroku/router: at=error code=H12 desc="Request timeout" method=POST path="/photos" host=domain.com request_id=a754387c-96eb-419b-a35b-8d67f3451c4e fwd="73.54.214.248" dyno=web.1 connect=1ms service=30324ms status=503 bytes=0
Jul 12 20:31:57 domain heroku/router: at=error code=H12 desc="Request timeout" method=POST path="/photos" host=domain.com request_id=e17842ef-1a80-43ef-8594-bd67d924c0fd fwd="73.54.214.248" dyno=web.1 connect=1ms service=30283ms status=503 bytes=0
Jul 12 20:31:57 domain heroku/router: at=error code=H12 desc="Request timeout" method=POST path="/photos" host=domain.com request_id=a0bb9be3-49a7-4d19-a098-fa51dd59655d fwd="73.54.214.248" dyno=web.1 connect=1ms service=30257ms status=503 bytes=0
Jul 12 20:32:00 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:59 +0000
Jul 12 20:32:00 domain app/web.1: Started POST "/photos" for 73.54.214.248 at 2015-07-13 03:31:59 +0000
Jul 12 20:32:10 domain heroku/router: at=info method=POST path="/photos" host=domain.com request_id=593a9d5c-0ca0-41fe-a831-85e2ef023591 fwd="73.54.214.248" dyno=web.1 connect=1ms service=12581ms status=500 bytes=835
Jul 12 20:32:10 domain app/web.1: ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.078 seconds)):

1 个答案:

答案 0 :(得分:2)

是的,请参阅heroku/router日志,表明请求的时间超过30秒。 Heroku要求你在30秒内返回 - see this article解释一切。

我建议直接上传S3(可能是like this),然后使用后台工作程序进行下载/处理/上传。然后,您不必毫无必要地捆绑网络连接,并且您将拥有更加可扩展的解决方案。