2015-07-13 123 views
0

我在Heroku與Postgres的愛好基本的數據庫愛好計劃後超時。當我使用導入Amazon S3的載波寶石上傳圖像時,服務器超時。上傳將發生,但需要一段時間才能處理。如果我上傳一張照片或四張相同的問題。服務器上傳照片

是否有人知道我能做些什麼來解決這個問題?創建照片時,會創建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)): 
+0

你能後處理上載的方法?我可以安全地假設您不會將「上傳到S3」邏輯派發給後臺工作者嗎? – elithrar

回答

2

是的,請參閱heroku/router日誌,其中指出請求花費的時間超過30秒。 Heroku要求你在30秒內返回 - see this article解釋這一切。

我建議直接到S3上傳(或許真的like this),然後使用一個後臺工作下載/處理/上傳。那麼你並不是毫無必要地綁定了一個網絡連接,而你將擁有更多的可擴展解決方案。

+0

謝謝你的解決方案,絕對會聽從這一建議。 –