rails trying to trouble shoot latency on my development machine - where can I see the web server request log? - ruby-on-rails

Im having a lot of latency running webrick on my development machine (localhost) .Anytime the browser makes a request, it takes the server about 8-9 seconds before it shows contents of the database, which contains just 34000 listings of text, output to the browser window.
I want to trouble shoot to find out whats happening.
Where should I start the process of troubleshooting?
I thought the first thing would be to monitor the web server logs to see requests.
But where can I find these on my development machine?
I know I can find the apache logs on my machine at
/var/log/apache2/access_log
but Rails doesnt run apache right? It runs webrick on port 3000
Please help.

When you run rails in development mode like:
rails s
..it usually runs WEBrick automatically as a foreground process and prints the type of information you're looking for to the console for each client request. You can check/tune some of the logging parameters by editing:
config/environments/development.rb
As WEBrick is the default web server, Apache has nothing to do with it unless you've configured your environment to do so. As you mentioned, the default port is 3000.
Newer versions of Rails can also log the the database query plan automatically for queries taking a long time to return.
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
You should also check your specific database for proper indexing based on the schema and queries you're trying to optimize.

Related

rails logger not running as expected

A legacy application (rails 4.2.10) was uploaded for staging purposes to a new server.
The log was populating at the start, but it all stopped at a certain point. Having to load a large database from google cloud, a browser was necessary as the link is to a page, not the object to download. VNC was installed, the file accessed and downloaded and VNC uninstalled shortly thereafter.
The last log entries are for malicious actors hitting the server targetting wordpress pages. wordpress is not installed. I cannot ascertain when they correspond to VNC installation/deactivation.
But no application page hits are registered past that point in time (quite a few days).
NGINX is the web server with the passenger nginx library. In development mode, puma 4.3.5 is invoked.
Is there any way to kickstart the Rails logger?

Rails 5.1 Running System Tests on Puma?

I was wondering if there was a way to use the Puma server (Rails default) JUST on the new Rails 5.1 system tests?
Right now on all our projects we use tiny_tds, but I was trying to experiment with 5.1 system tests with Capybara/Selenium but it fails of course because I do not have Puma installed/running.
I took a look through the documentation and didn't see anything about declaring what type of server you want to use. Were connecting to a SQL Server database so I don't know if Puma is able to do that (And that's probably why were using tiny_tds in the first place).
You're confusing database adapters and rack web servers which are very different things.
Puma (like Webrick, Thin, Unicorn etc) is a general purpose Rack web server. It sits and waits for incoming requests from vistors and dispatches them to an application (like a Rails app) by calling it with a hash containing the environment and request. The application returns an array containing the response. The server sends it back to the visitor.
tiny_tds on the other hand is a database adapter. Its used to connect the application to the database. The web server is almost completly oblivious to how the application creates a response from the request. This includes whatever databases are used.
In Rails 5 most servers don't require configuration. You just add the gem to the gemfile and run bundle install and they plug themselves in. There in no seperate installation step.
That was not the case earlier which is why Webrick - a server with the only real merit being that it does not require configuration was the default. It is now Puma which unlike Webrick is suited for production.
Using different servers in different environments is not a good idea since it violates the idea of dev/prod parity. Your dev & test environment should be as close as possible to what you are deploying to so that you can catch bugs before they end up in production. This means you should be running the same server, same database etc.
Running a seperate test server for different parts of your test suite sounds like a true fools errand - if its even possible without hacking the framework to bits.
For SQL Server there is activerecord-sqlserver-adapter which can use tiny_tds as a backend.

Rails production server (thin): pages occasionally load slower

I'm running my Rails application through thin on Windows OS.
thin start -e production
Since the number of users grew, now around 10 people using the app simultaneously, there are times when a same page takes a while longer to load.
Are there other configurations that I need to set when running the server on production?
I'm quite sure that it has to do with the server since the slow down happens on pages that normally loads fast.
The Thin webserver is not meant to production environment. Instead of this you should use a different webserver and application server like Nginx/Unicorn, Nginx/Passenger.
I would recommend Passenger to run your rails app as fast as possible in production mode.
The thin webserver is very fast for few requests, but if there are simultaneously requests, thin gets very slow.
The following document describes about how to deploy rails application in windows. I haven't done this personally but, believe the latest versions should allow that. Please check the below link to see how it can be done
http://weblog.rubyonrails.org/2006/5/11/deploying-rails-on-windows-servers/

Is one rails server per application?

I have two questions about rails server:
Do I have to start the server from within the application folder?
Is the server I started only for that application?
If they are true, this does not quite make sense to me, since why do I need to start multiple servers?
Or is there some kind of master configuration, so that one server can route to different applications? Is Capistrano for this purpose?
I'm going to assume you're talking about the rails server command, for running a local rails server to test your application, and that you're not talking about setting up a rails application on a remote server. Please mention if that is not the case.
Yes, you must execute rails server from within the root folder of your rails application.
Yes, the server you started is only for that application. It's a self-contained thing.
You should not need to start multiple servers. Even if you have multiple applications, you probably don't need to have more than one running at a time. So, you can shut down the rails server in one application (Ctrl-C) and then cd to your new application, and start a new rails server there with rails server.
If you do need to run two local rails applications at once, you can do so by running them on different ports. So, the first one, you can just execute rails server and it will make your site available at localhost:3000 (because port 3000 is the default port). The next one, you can specify a port other than 3000 - eg. rails server -p 3001 to get a rails app at localhost:3001.
Capistrano is for deploying your applications to a remote server, not for running them locally on your own computer. So, it is not relevant here. What you may be interested in is http://pow.cx/
Again, I've assumed you're talking about running your rails app locally on your own computer. If you're referring to deploying it to the internet on a server, then you can ignore this answer.

Rails environment deployment issue?

I'm trying to deploy my first Rails app here, and I've been stuck on something since last night. I'm encountering some weird behaviors I can't explain.
I'm running Rails, Apache, Phusion Passenger, and for the moment, SQLite 3. (I'll move that over to MySQL shortly.) Currently this is being hosted on a too-small EC2 slice running Ubuntu Server 11.04 (Natty).
When I visit the address of the EC2 slice in the browser, I get the default Rails 500 notice. Here's what's weird, though. When I tail /log/production.log, I see the following error:
ActionView::Template::Error (SQLite3::SQLException: no such table: offers: SELECT "offers".* FROM "offers" WHERE (code = '') ORDER BY created_at desc LIMIT 25 OFFSET 0):
So, I manually opened up the development database in SQLite3, and saw that table in there. The production database, however, does not have that table.
OK, so I'm getting errors with the production database logged in the production log. The application has to be running in production mode, right?
That is what's throwing me. First of all, it's running in development mode on my development machine, and I didn't change any of the files when I deployed it. Neither did I use any fancy deployment tools to deploy it (which may have switched something without my knowledge) - I just did a simple git push.
Furthermore, I added the following to my httdp.conf VirtualHost config:
RailsEnv development
Also, when I run rails console, I can get the following:
irb(main):002:0> Rails.env
=> "development"
So, the application really should be running in development mode, right? In fact, it seems to think (partially) that it is, right?
I'm really not sure what's happening here, and I'd really appreciate some expert advice.
Thanks everyone.
Edit - A few server reboots later, and now the thing just hangs when I try to view it in a browser. Also, Apache seems to hang when I try to restart it (hence the server reboots), related problem, or different problem altogether?
Well, this isn't a 100% satisfactory answer for me, but I did two things, and I think I got it working.
First, I re-installed the passenger Apache module. That may or may not have been necessary.
This was the big thing, though: after I had added the line to httpd.conf to pass the Rails Environment over to Passenger, I believe Apache restarted incorrectly. (Rather, I believe I've been restarting Apache incorrectly for my whole life!)
I was trying to restart Apache this way:
sudo /etc/init.d/apache2 restart
That has always worked for me (when programming PHP), but it simply wasn't working here. Apache would just stall on the restart.
This, however, works fine:
sudo apachectl restart
I'll have to ask Server Fault what the significant difference is between the two.
I hope that helps someone out.

Resources