Rails file download via send_file is slow, is X-Sendfile or similar available in puma?










2















Downloading off the public folder takes 2 seconds.

Downloading the same file using the send_file method below takes nearly a minute.



 def download
file = FileUpload.find params[:id]
file_path = Rails.root.join('private', file.name)
send_file(file_path,
x_sendfile: true,
disposition: 'attachment')
end


I have tried changing buffer size and so on but it's still extremely slow, slower than the database & send_data combination.

Apart from ditching Rails entirely, is there an simple solution to this?










share|improve this question


























    2















    Downloading off the public folder takes 2 seconds.

    Downloading the same file using the send_file method below takes nearly a minute.



     def download
    file = FileUpload.find params[:id]
    file_path = Rails.root.join('private', file.name)
    send_file(file_path,
    x_sendfile: true,
    disposition: 'attachment')
    end


    I have tried changing buffer size and so on but it's still extremely slow, slower than the database & send_data combination.

    Apart from ditching Rails entirely, is there an simple solution to this?










    share|improve this question
























      2












      2








      2








      Downloading off the public folder takes 2 seconds.

      Downloading the same file using the send_file method below takes nearly a minute.



       def download
      file = FileUpload.find params[:id]
      file_path = Rails.root.join('private', file.name)
      send_file(file_path,
      x_sendfile: true,
      disposition: 'attachment')
      end


      I have tried changing buffer size and so on but it's still extremely slow, slower than the database & send_data combination.

      Apart from ditching Rails entirely, is there an simple solution to this?










      share|improve this question














      Downloading off the public folder takes 2 seconds.

      Downloading the same file using the send_file method below takes nearly a minute.



       def download
      file = FileUpload.find params[:id]
      file_path = Rails.root.join('private', file.name)
      send_file(file_path,
      x_sendfile: true,
      disposition: 'attachment')
      end


      I have tried changing buffer size and so on but it's still extremely slow, slower than the database & send_data combination.

      Apart from ditching Rails entirely, is there an simple solution to this?







      ruby-on-rails






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 5 '17 at 13:54









      TastyCatFoodTastyCatFood

      539417




      539417






















          2 Answers
          2






          active

          oldest

          votes


















          1














          After some search I realized my question was a little silly:



          Puma is, in practice, an Application server



          To be precise, Puma calls itself a web server but rails usage wise it seems either Apache or Nginx is inserted between the user and Puma in most cases.



          Puma itself, as of now, does not seem to support either X-Sendfile nor X-Accel-Redirect. It's up to Apache or Nginx.



          Getting it work with rails5, puma, nginx in development environment



          Steps are for ubuntu 16lts, puma version 3.9.1, nginx/1.10.0 (Ubuntu), Rails 5.1.1, ruby 2.4.0p0



          sudo apt install nginx
          sudo ufw allow 'Nginx HTTP'
          sudo trash /etc/nginx/sites-enabled/defualt #renaming did not work
          sudo touch /etc/nginx/sites-available/rails.conf
          sudo ln -sf /etc/nginx/sites-available/rails.conf /etc/nginx/stes-enabled/rails.conf


          Edited: /etc/nginx/sites-available/rails.conf



          upstream uploader 
          server localhost:3000 fail_timeout=0;


          server
          listen 80;
          listen [::]:80;
          #Your public folder path
          root /home/d/WebApp/uploader/public;
          location ~ ^/assets/
          expires max;
          gzip_static on;
          gzip_vary on;
          add_header Cache-Control public;
          break;

          location /
          proxy_pass http://uploader;# http://appNameYouChooseAbove
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

          #Inform rails how to ask nginx to deliver files.
          #nginx does not take an absolute file path,
          #it needs url.
          #X-Accel-Mapping contains info needed to convert
          #an absolute file path to an url.
          proxy_set_header X-Accel-Mapping /home/d/WebApp/uploader/private=/available_only_when_redirected_here_by_upstream_server;
          #The above is used by rails to translate:
          #e.g.
          # /home/d/WebApp/uploader/private/file.zip
          # to
          # available_only_when_redirected_here_by_upstream_server/file.zip
          # When rails access the above, nginx delivers the file to the client
          proxy_set_header X-Sendfile-Type X-Accel-Redirect;


          location /available_only_when_redirected_here_by_upstream_server
          #without alias, nginx tries to open file at:
          #"root + this location + filename"
          #e.g.
          # given file file.zip
          # root of "/home/d/WebApp/uploader/public" as defined above.
          # this lociation which is "available_only_when_redirected_here_by_upstream_server"
          #
          # /home/d/WebApp/uploader/public/ava...server/file.zip
          #
          alias /home/d/WebApp/uploader/private/;
          # internal ensures this url in only available from upsteam location/application server
          internal;


          error_page 500 502 503 504 /500.html;
          error_page 404 /404.html;
          error_page 422 /422.html;
          client_max_body_size 4G;
          keepalive_timeout 10;



          Append the below to config/environment/development.rb



          config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX


          Restart servers



          bundle exec rails s Puma
          sudo service nginx restart


          P.S

          Direct access to localhost:3000 bypasses nginx; omit port number to go through nginx.



          P.P.S

          Edited Nginx config as it was not working;I don't know why download speed improved when it should not!

          "X-Accel-Mapping header missing" means X-Accel-Redirect not working.



          X-Accel-Mapping can be defined in inner context like:



          location / 
          location /static
          proxy_pass http://uploader;# http://appNameYouChooseAbove
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Accel-Mapping /...=/...;




          and redirection targets can be created as many as needed, so it's not as bad as it appears.

          Be warned, however, Nginx configuration is a wild ride. Without proxy_set_header etc, introducing inner context morphs url to root path + location form and gosh it was not very intuitive!






          share|improve this answer
































            0














            When using Heroku or similar services, sometimes it isn't possible (or convenient) to configure nginx.



            In these cases it makes sense to use an application server that supports X-Sendfile, such as iodine or agoo.



            My biased suggestion is to use the iodine server with it's static file service option in the procfile, for example:



            iodine -w 4 -t 16 -www ./public


            Since assets are compiled to ./public/assets*, than the static file requests will be directly handled by iodine without ever entering the Ruby application (the C server layer will handle them).



            * RAILS_ENV=production bin/rails assets:precompile compiles assets to ./public/assets






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44370604%2frails-file-download-via-send-file-is-slow-is-x-sendfile-or-similar-available-in%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              After some search I realized my question was a little silly:



              Puma is, in practice, an Application server



              To be precise, Puma calls itself a web server but rails usage wise it seems either Apache or Nginx is inserted between the user and Puma in most cases.



              Puma itself, as of now, does not seem to support either X-Sendfile nor X-Accel-Redirect. It's up to Apache or Nginx.



              Getting it work with rails5, puma, nginx in development environment



              Steps are for ubuntu 16lts, puma version 3.9.1, nginx/1.10.0 (Ubuntu), Rails 5.1.1, ruby 2.4.0p0



              sudo apt install nginx
              sudo ufw allow 'Nginx HTTP'
              sudo trash /etc/nginx/sites-enabled/defualt #renaming did not work
              sudo touch /etc/nginx/sites-available/rails.conf
              sudo ln -sf /etc/nginx/sites-available/rails.conf /etc/nginx/stes-enabled/rails.conf


              Edited: /etc/nginx/sites-available/rails.conf



              upstream uploader 
              server localhost:3000 fail_timeout=0;


              server
              listen 80;
              listen [::]:80;
              #Your public folder path
              root /home/d/WebApp/uploader/public;
              location ~ ^/assets/
              expires max;
              gzip_static on;
              gzip_vary on;
              add_header Cache-Control public;
              break;

              location /
              proxy_pass http://uploader;# http://appNameYouChooseAbove
              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

              #Inform rails how to ask nginx to deliver files.
              #nginx does not take an absolute file path,
              #it needs url.
              #X-Accel-Mapping contains info needed to convert
              #an absolute file path to an url.
              proxy_set_header X-Accel-Mapping /home/d/WebApp/uploader/private=/available_only_when_redirected_here_by_upstream_server;
              #The above is used by rails to translate:
              #e.g.
              # /home/d/WebApp/uploader/private/file.zip
              # to
              # available_only_when_redirected_here_by_upstream_server/file.zip
              # When rails access the above, nginx delivers the file to the client
              proxy_set_header X-Sendfile-Type X-Accel-Redirect;


              location /available_only_when_redirected_here_by_upstream_server
              #without alias, nginx tries to open file at:
              #"root + this location + filename"
              #e.g.
              # given file file.zip
              # root of "/home/d/WebApp/uploader/public" as defined above.
              # this lociation which is "available_only_when_redirected_here_by_upstream_server"
              #
              # /home/d/WebApp/uploader/public/ava...server/file.zip
              #
              alias /home/d/WebApp/uploader/private/;
              # internal ensures this url in only available from upsteam location/application server
              internal;


              error_page 500 502 503 504 /500.html;
              error_page 404 /404.html;
              error_page 422 /422.html;
              client_max_body_size 4G;
              keepalive_timeout 10;



              Append the below to config/environment/development.rb



              config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX


              Restart servers



              bundle exec rails s Puma
              sudo service nginx restart


              P.S

              Direct access to localhost:3000 bypasses nginx; omit port number to go through nginx.



              P.P.S

              Edited Nginx config as it was not working;I don't know why download speed improved when it should not!

              "X-Accel-Mapping header missing" means X-Accel-Redirect not working.



              X-Accel-Mapping can be defined in inner context like:



              location / 
              location /static
              proxy_pass http://uploader;# http://appNameYouChooseAbove
              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Accel-Mapping /...=/...;




              and redirection targets can be created as many as needed, so it's not as bad as it appears.

              Be warned, however, Nginx configuration is a wild ride. Without proxy_set_header etc, introducing inner context morphs url to root path + location form and gosh it was not very intuitive!






              share|improve this answer





























                1














                After some search I realized my question was a little silly:



                Puma is, in practice, an Application server



                To be precise, Puma calls itself a web server but rails usage wise it seems either Apache or Nginx is inserted between the user and Puma in most cases.



                Puma itself, as of now, does not seem to support either X-Sendfile nor X-Accel-Redirect. It's up to Apache or Nginx.



                Getting it work with rails5, puma, nginx in development environment



                Steps are for ubuntu 16lts, puma version 3.9.1, nginx/1.10.0 (Ubuntu), Rails 5.1.1, ruby 2.4.0p0



                sudo apt install nginx
                sudo ufw allow 'Nginx HTTP'
                sudo trash /etc/nginx/sites-enabled/defualt #renaming did not work
                sudo touch /etc/nginx/sites-available/rails.conf
                sudo ln -sf /etc/nginx/sites-available/rails.conf /etc/nginx/stes-enabled/rails.conf


                Edited: /etc/nginx/sites-available/rails.conf



                upstream uploader 
                server localhost:3000 fail_timeout=0;


                server
                listen 80;
                listen [::]:80;
                #Your public folder path
                root /home/d/WebApp/uploader/public;
                location ~ ^/assets/
                expires max;
                gzip_static on;
                gzip_vary on;
                add_header Cache-Control public;
                break;

                location /
                proxy_pass http://uploader;# http://appNameYouChooseAbove
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                #Inform rails how to ask nginx to deliver files.
                #nginx does not take an absolute file path,
                #it needs url.
                #X-Accel-Mapping contains info needed to convert
                #an absolute file path to an url.
                proxy_set_header X-Accel-Mapping /home/d/WebApp/uploader/private=/available_only_when_redirected_here_by_upstream_server;
                #The above is used by rails to translate:
                #e.g.
                # /home/d/WebApp/uploader/private/file.zip
                # to
                # available_only_when_redirected_here_by_upstream_server/file.zip
                # When rails access the above, nginx delivers the file to the client
                proxy_set_header X-Sendfile-Type X-Accel-Redirect;


                location /available_only_when_redirected_here_by_upstream_server
                #without alias, nginx tries to open file at:
                #"root + this location + filename"
                #e.g.
                # given file file.zip
                # root of "/home/d/WebApp/uploader/public" as defined above.
                # this lociation which is "available_only_when_redirected_here_by_upstream_server"
                #
                # /home/d/WebApp/uploader/public/ava...server/file.zip
                #
                alias /home/d/WebApp/uploader/private/;
                # internal ensures this url in only available from upsteam location/application server
                internal;


                error_page 500 502 503 504 /500.html;
                error_page 404 /404.html;
                error_page 422 /422.html;
                client_max_body_size 4G;
                keepalive_timeout 10;



                Append the below to config/environment/development.rb



                config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX


                Restart servers



                bundle exec rails s Puma
                sudo service nginx restart


                P.S

                Direct access to localhost:3000 bypasses nginx; omit port number to go through nginx.



                P.P.S

                Edited Nginx config as it was not working;I don't know why download speed improved when it should not!

                "X-Accel-Mapping header missing" means X-Accel-Redirect not working.



                X-Accel-Mapping can be defined in inner context like:



                location / 
                location /static
                proxy_pass http://uploader;# http://appNameYouChooseAbove
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Accel-Mapping /...=/...;




                and redirection targets can be created as many as needed, so it's not as bad as it appears.

                Be warned, however, Nginx configuration is a wild ride. Without proxy_set_header etc, introducing inner context morphs url to root path + location form and gosh it was not very intuitive!






                share|improve this answer



























                  1












                  1








                  1







                  After some search I realized my question was a little silly:



                  Puma is, in practice, an Application server



                  To be precise, Puma calls itself a web server but rails usage wise it seems either Apache or Nginx is inserted between the user and Puma in most cases.



                  Puma itself, as of now, does not seem to support either X-Sendfile nor X-Accel-Redirect. It's up to Apache or Nginx.



                  Getting it work with rails5, puma, nginx in development environment



                  Steps are for ubuntu 16lts, puma version 3.9.1, nginx/1.10.0 (Ubuntu), Rails 5.1.1, ruby 2.4.0p0



                  sudo apt install nginx
                  sudo ufw allow 'Nginx HTTP'
                  sudo trash /etc/nginx/sites-enabled/defualt #renaming did not work
                  sudo touch /etc/nginx/sites-available/rails.conf
                  sudo ln -sf /etc/nginx/sites-available/rails.conf /etc/nginx/stes-enabled/rails.conf


                  Edited: /etc/nginx/sites-available/rails.conf



                  upstream uploader 
                  server localhost:3000 fail_timeout=0;


                  server
                  listen 80;
                  listen [::]:80;
                  #Your public folder path
                  root /home/d/WebApp/uploader/public;
                  location ~ ^/assets/
                  expires max;
                  gzip_static on;
                  gzip_vary on;
                  add_header Cache-Control public;
                  break;

                  location /
                  proxy_pass http://uploader;# http://appNameYouChooseAbove
                  proxy_set_header Host $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                  #Inform rails how to ask nginx to deliver files.
                  #nginx does not take an absolute file path,
                  #it needs url.
                  #X-Accel-Mapping contains info needed to convert
                  #an absolute file path to an url.
                  proxy_set_header X-Accel-Mapping /home/d/WebApp/uploader/private=/available_only_when_redirected_here_by_upstream_server;
                  #The above is used by rails to translate:
                  #e.g.
                  # /home/d/WebApp/uploader/private/file.zip
                  # to
                  # available_only_when_redirected_here_by_upstream_server/file.zip
                  # When rails access the above, nginx delivers the file to the client
                  proxy_set_header X-Sendfile-Type X-Accel-Redirect;


                  location /available_only_when_redirected_here_by_upstream_server
                  #without alias, nginx tries to open file at:
                  #"root + this location + filename"
                  #e.g.
                  # given file file.zip
                  # root of "/home/d/WebApp/uploader/public" as defined above.
                  # this lociation which is "available_only_when_redirected_here_by_upstream_server"
                  #
                  # /home/d/WebApp/uploader/public/ava...server/file.zip
                  #
                  alias /home/d/WebApp/uploader/private/;
                  # internal ensures this url in only available from upsteam location/application server
                  internal;


                  error_page 500 502 503 504 /500.html;
                  error_page 404 /404.html;
                  error_page 422 /422.html;
                  client_max_body_size 4G;
                  keepalive_timeout 10;



                  Append the below to config/environment/development.rb



                  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX


                  Restart servers



                  bundle exec rails s Puma
                  sudo service nginx restart


                  P.S

                  Direct access to localhost:3000 bypasses nginx; omit port number to go through nginx.



                  P.P.S

                  Edited Nginx config as it was not working;I don't know why download speed improved when it should not!

                  "X-Accel-Mapping header missing" means X-Accel-Redirect not working.



                  X-Accel-Mapping can be defined in inner context like:



                  location / 
                  location /static
                  proxy_pass http://uploader;# http://appNameYouChooseAbove
                  proxy_set_header Host $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  proxy_set_header X-Accel-Mapping /...=/...;




                  and redirection targets can be created as many as needed, so it's not as bad as it appears.

                  Be warned, however, Nginx configuration is a wild ride. Without proxy_set_header etc, introducing inner context morphs url to root path + location form and gosh it was not very intuitive!






                  share|improve this answer















                  After some search I realized my question was a little silly:



                  Puma is, in practice, an Application server



                  To be precise, Puma calls itself a web server but rails usage wise it seems either Apache or Nginx is inserted between the user and Puma in most cases.



                  Puma itself, as of now, does not seem to support either X-Sendfile nor X-Accel-Redirect. It's up to Apache or Nginx.



                  Getting it work with rails5, puma, nginx in development environment



                  Steps are for ubuntu 16lts, puma version 3.9.1, nginx/1.10.0 (Ubuntu), Rails 5.1.1, ruby 2.4.0p0



                  sudo apt install nginx
                  sudo ufw allow 'Nginx HTTP'
                  sudo trash /etc/nginx/sites-enabled/defualt #renaming did not work
                  sudo touch /etc/nginx/sites-available/rails.conf
                  sudo ln -sf /etc/nginx/sites-available/rails.conf /etc/nginx/stes-enabled/rails.conf


                  Edited: /etc/nginx/sites-available/rails.conf



                  upstream uploader 
                  server localhost:3000 fail_timeout=0;


                  server
                  listen 80;
                  listen [::]:80;
                  #Your public folder path
                  root /home/d/WebApp/uploader/public;
                  location ~ ^/assets/
                  expires max;
                  gzip_static on;
                  gzip_vary on;
                  add_header Cache-Control public;
                  break;

                  location /
                  proxy_pass http://uploader;# http://appNameYouChooseAbove
                  proxy_set_header Host $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                  #Inform rails how to ask nginx to deliver files.
                  #nginx does not take an absolute file path,
                  #it needs url.
                  #X-Accel-Mapping contains info needed to convert
                  #an absolute file path to an url.
                  proxy_set_header X-Accel-Mapping /home/d/WebApp/uploader/private=/available_only_when_redirected_here_by_upstream_server;
                  #The above is used by rails to translate:
                  #e.g.
                  # /home/d/WebApp/uploader/private/file.zip
                  # to
                  # available_only_when_redirected_here_by_upstream_server/file.zip
                  # When rails access the above, nginx delivers the file to the client
                  proxy_set_header X-Sendfile-Type X-Accel-Redirect;


                  location /available_only_when_redirected_here_by_upstream_server
                  #without alias, nginx tries to open file at:
                  #"root + this location + filename"
                  #e.g.
                  # given file file.zip
                  # root of "/home/d/WebApp/uploader/public" as defined above.
                  # this lociation which is "available_only_when_redirected_here_by_upstream_server"
                  #
                  # /home/d/WebApp/uploader/public/ava...server/file.zip
                  #
                  alias /home/d/WebApp/uploader/private/;
                  # internal ensures this url in only available from upsteam location/application server
                  internal;


                  error_page 500 502 503 504 /500.html;
                  error_page 404 /404.html;
                  error_page 422 /422.html;
                  client_max_body_size 4G;
                  keepalive_timeout 10;



                  Append the below to config/environment/development.rb



                  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX


                  Restart servers



                  bundle exec rails s Puma
                  sudo service nginx restart


                  P.S

                  Direct access to localhost:3000 bypasses nginx; omit port number to go through nginx.



                  P.P.S

                  Edited Nginx config as it was not working;I don't know why download speed improved when it should not!

                  "X-Accel-Mapping header missing" means X-Accel-Redirect not working.



                  X-Accel-Mapping can be defined in inner context like:



                  location / 
                  location /static
                  proxy_pass http://uploader;# http://appNameYouChooseAbove
                  proxy_set_header Host $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  proxy_set_header X-Accel-Mapping /...=/...;




                  and redirection targets can be created as many as needed, so it's not as bad as it appears.

                  Be warned, however, Nginx configuration is a wild ride. Without proxy_set_header etc, introducing inner context morphs url to root path + location form and gosh it was not very intuitive!







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 8 '17 at 18:10

























                  answered Jun 5 '17 at 17:08









                  TastyCatFoodTastyCatFood

                  539417




                  539417























                      0














                      When using Heroku or similar services, sometimes it isn't possible (or convenient) to configure nginx.



                      In these cases it makes sense to use an application server that supports X-Sendfile, such as iodine or agoo.



                      My biased suggestion is to use the iodine server with it's static file service option in the procfile, for example:



                      iodine -w 4 -t 16 -www ./public


                      Since assets are compiled to ./public/assets*, than the static file requests will be directly handled by iodine without ever entering the Ruby application (the C server layer will handle them).



                      * RAILS_ENV=production bin/rails assets:precompile compiles assets to ./public/assets






                      share|improve this answer



























                        0














                        When using Heroku or similar services, sometimes it isn't possible (or convenient) to configure nginx.



                        In these cases it makes sense to use an application server that supports X-Sendfile, such as iodine or agoo.



                        My biased suggestion is to use the iodine server with it's static file service option in the procfile, for example:



                        iodine -w 4 -t 16 -www ./public


                        Since assets are compiled to ./public/assets*, than the static file requests will be directly handled by iodine without ever entering the Ruby application (the C server layer will handle them).



                        * RAILS_ENV=production bin/rails assets:precompile compiles assets to ./public/assets






                        share|improve this answer

























                          0












                          0








                          0







                          When using Heroku or similar services, sometimes it isn't possible (or convenient) to configure nginx.



                          In these cases it makes sense to use an application server that supports X-Sendfile, such as iodine or agoo.



                          My biased suggestion is to use the iodine server with it's static file service option in the procfile, for example:



                          iodine -w 4 -t 16 -www ./public


                          Since assets are compiled to ./public/assets*, than the static file requests will be directly handled by iodine without ever entering the Ruby application (the C server layer will handle them).



                          * RAILS_ENV=production bin/rails assets:precompile compiles assets to ./public/assets






                          share|improve this answer













                          When using Heroku or similar services, sometimes it isn't possible (or convenient) to configure nginx.



                          In these cases it makes sense to use an application server that supports X-Sendfile, such as iodine or agoo.



                          My biased suggestion is to use the iodine server with it's static file service option in the procfile, for example:



                          iodine -w 4 -t 16 -www ./public


                          Since assets are compiled to ./public/assets*, than the static file requests will be directly handled by iodine without ever entering the Ruby application (the C server layer will handle them).



                          * RAILS_ENV=production bin/rails assets:precompile compiles assets to ./public/assets







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 13 '18 at 6:05









                          MystMyst

                          12k22542




                          12k22542



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44370604%2frails-file-download-via-send-file-is-slow-is-x-sendfile-or-similar-available-in%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              Node.js Script on GitHub Pages or Amazon S3

                              Museum of Modern and Contemporary Art of Trento and Rovereto