I have 2 running environments of same rails app. one is development and second one is say staging. when i try to run my app on development environment then it runs good without any exception. but when i try to run same app on staging, then it throws an exception of Request-URI too large error. i run this app using webrick on both development and staging.
It seems to be that your request uri is longer than 2083 chars. This is the max uri size of the webrick. But to replace webrick with thin will help.
sudo gem install thin
and
thin start
Webrick can't handle URI's longer than MAX_URI_LENGTH = 2083 (according to this). And it's not really supposed to be run in production (some people say)
Try using thin. gem 'thin' in your Gemfile, installing and then rails s
Related
I am inheriting a code base where the tests have been abandoned for a little over a year. I am trying to clean up the test suite as much as possible but I am having a difficult time teasing out my integration tests with 1. Capybara 2. Puma, 3. Selenium, 4. Starting the Rails Server with rails s.
Here is my initial setup and problem with the Rails 4.2 app. So without doing anything from the get go, when I execute rails testing, I get the following error:
Capybara is unable to load puma for its server, please add puma to your project or specify a different server via something like Capybara.server = :webrick. (LoadError).
I want to point out that in a separate file named start-dev, I have the following in its contents:
rails s -b 0.0.0.0
When I execute this comand with ./start-dev, I am able to view my development app with this url defined in my /etc/hosts 127.0.0.1 secure.ssl.local
Now here is where I start to run into trouble, Through reading some github forums regarding capybara and puma, I start by adding puma into my Gemfile and bundle install but now I am unable to see my development app through the browser at secure.ssl.local.
This is the erorr I get:
/usr/lib/ruby/2.6.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "tcp://0.0.0.0\r:3000" (URI::InvalidURIError)
I noticed that in the start up though, when I execute ./start-dev which if you remeber has rails s -b 0.0.0.0, I see this:
Booting Puma rails 4.2.11.1 application starting in development on https://0.0.0.0:3000
So I am confused by this error. Is Puma blocking my port of 3000 meaning that I have to change the port of Puma? And what makes this even more confusing is that instead of running ./start-dev in the terminal and I simply run rails s -b 0.0.0.0 it magically works except it only works if I navigate to localhost:3000 and not secure.ssl.localhost. This is important because on secure.ssl.localhost I have and need a certificate and localhost I don't.
And finally to add one more layer of confusion, when I run the tests with the puma gem installed and run rake test I get this with Puma:
Capybara starting Puma...
* Version 4.2.1 , codename: Distant Airhorns
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:36608
And the test takes ages to load. There is a lot going on but I guess my question can be summarised by the following? When I install puma into my rails application, do I need to specify it on a specific port so it does not conflict with my app? Without puma, my tests can't run and my ./start-dev file works. With puma, my tests are kind of working but my ./start-dev file isn't anymore. Surely there must be a standard to configure puma. Thank you.
Install puma only for test environment by putting it into test group:
group :test do
gem "puma"
end
Or do as Capybara proposes and put Capybara.server = :webrick into your spec/rails_helper.rb
FYI: Rails uses puma as default web server if puma is installed
If two web servers (say puma and unicorn) are specified
in the Gemfile, which one gets precedence?
I tried doing this myself but realized I was on windows with not much ruby support.
Long Answer with example:
you created app with rails 5.0.0, you get puma webserver by default.
you install unicorn gem. and you start the server by rails server still your server is puma. why ? because config/puma.rb file which generated with rails new application-name .
To start unicorn server you have to created one file for unicorn in config folder.
To start unicorn server you have to execute command like this unicorn -c config/unicorn.rb in your terminal.
I think this is the answer of your question.
Short answer:
You have tell rails explicitly which webserver you have to run. Rails will not decide which to run (in case of multiple web server).
I hope this clear your doubts.
Cheers
I have a Rails app hosted on Heroku and I want to add Server Sent Events functionalities, but I can't find any documentation or blog post specific for Heroku.
As not all servers (e.g. WEBrick) support ActionController::Live I was wondering what is the default server on Heroku and whether is possible to configure the environment (i.e. change server) to support SSEs.
Any further advice about the server to use and how to configure would be greatly appreciated.
I think my answer is not so widely helpfull, but you can try.
For the first thing:
create Procfile in rails root within the following content:
web: bundle exec rails server puma -p $PORT -e $RACK_ENV
then add to Gemfile:
gem 'puma'
In above you can switch to thin, but consider link below (and many more details)
http://tenderlovemaking.com/2012/07/30/is-it-live.html
Heroku wouldn't necessarily be the issue here - it's an environment which allows your app to run (on Amazon EC2 I think)
Multi-Threaded Servers
The thing you've got to look for is the server software you use to run your app. Heroku basically takes your server gem & allows it to run with their processors, and other computing power; so it's really whether their platform can play ball with the right server
You're really looking for multi-threaded servers, which you can find here Is puma the ONLY multi-threaded rails 4 http server?
Puma
Rainbows! supports multiple concurrency models, including multithreading
Zbatery - Rack HTTP server without a fork stuck in it
Phusion Passenger 4 has supported multithreading since its beta stages
Thin does have a threaded mode which can be enabled by passing
--threaded or by setting threaded: true in the appropriate configuration file (e.g. bundle exec thin start --threaded)
Net::HTTP::Server, despite the lack of advertising, supports
multithreading; very minimalist
I am using rails 2.3.9, rubygems 1.8.24, ruby 1.9.3 and Windows 7 ultimate 64-bit
I just installed nginx as my web server through passenger. Now I want to run nginx as my default server such that when i run ruby script/server, it runs instead of the default WeBrick. Is there any way to do this? Thanks a million.
Nginx doesn't work the way you described. Once it is started, you won't need to run script/server, the rails app will be run at the same time when the Nginx/Apache started.
So, just deploy your rails app following the 'Passenger' manual( in development mode), and you will get your app always running.
so, as conclusion, we can tell that, when deploying a Rails app, Nginx and Apache is in the same group( work together with Passenger), and Mongrel/Webrick/Thin is another group(script/server approach).
You may want to take a look at Foreman.
Windows 7, Rails 3 here. I local/development mode, rails server does not handle multiple request at the same time. The process crash and the cmd prompt comes in front.
I've noticed this behaviour when :
having too much ajax request, too close from one another
loading a simple page on 2 browsers
Is there a way workaround that ? Change the local server (default is webrick) ? How is that done ?
Thanks.
I don't know if this still needs an answer but I did this by adding gem 'puma' to the Gemfile then you'll need to add config.threadsafe! to either your config/application.rb or the environment file you're running on (like config/environments/development.rb.
Sometimes you might not want threadsafe on so I so did this in my development.rb:
if ENV["THREADS"]
config.threadsafe!
end
Now (with what I did in my development.rb) I can do rails s Puma and it will run with a max of 16 threads and can handle multiple requests. You can also up the thread pool and configure more with Puma, docs are here
Update
Note that the use of config.threadsafe! is not needed in Rails 4+ and is deprecated I believe.
You need to install the mongrel gem and this specify which server you want to use when you rails s
I don't know how you guys do it on win systems. Why not run a virtual Unix box? isn't rails just much easier with it? So with Unix it would be something like:
Install mongrel gem:
gem install mongrel
Then specify which server you want to run:
rails server mongrel