Rails caching on Production - ruby-on-rails

On Production I have caching switched off in config/environments/production.rb:
config.action_controller.perform_caching = false
However content is being cached and I can't seem to clear it. The log just states:
Started GET "/1234" for 12.34.56.78 at 2013-06-21 23:36:41 +0100
Processing by MyController#index as HTML
Parameters: {"product_id"=>"1234"}
Rendered my_app/index.html.erb within layouts/application (0.0ms)
Completed 200 OK in 259ms (Views: 2.1ms | ActiveRecord: 254.7ms)
What gives and how do I clear the cache?

This is not doing caching at all. And setting action_comtoller caching to false truly ensures that no caching is done.
If there was caching your response would literally say that it was loaded from cache.

Related

Rails application getting 500 error page on production

I'm migrating a working Rails 3 application from server to another type of service. Firstly I had issues with static files (e.g. application.css, application.js) not being rendered (404 status). I resolved that issue turning the config.assets.enabled to true.
Now I'm having the problem of error 500 no matter where I go in the application. I assume it's an asset problem. I don't get an error in log/production. Only something as follow:
Started GET "/" for 187.39.38.147 at 2016-06-14 12:33:05 +0000
Processing by BooksController#index as HTML
Rendered myapp/layouts/500.html (0.7ms)
Completed 404 Not Found in 16ms (Views: 10.0ms | ActiveRecord: 1.9ms)
I have no idea of how to find out what's wrong to fix that.
What can I do to find out what's wrong ?

Rails 4.2 - after upgrade, pages never load in browser (or take really long) despite server activity

I am in the process of upgrading our app from Rails 3.2 to 4.2. One of the problems I've run into is that even static pages don't seem to be loading in the browser for some reason, despite browser activity. Example: I go to localhost:3000/pricing and get this in the server:
Started GET "/pricing" for 127.0.0.1 at 2015-01-16 15:44:59 -0500
Processing by PagesController#show as HTML
Parameters: {"id"=>"pricing"}
Rendered pages/pricing.html.haml within layouts/static (9.1ms)
Rendered layouts/_head.html.haml (64.4ms)
Rendered layouts/_navbar.html.haml (4.5ms)
Rendered layouts/_alerts.html.haml (1.0ms)
Rendered pages/_nav.html.haml (5.3ms)
Rendered shared/_social_links.html.haml (1.1ms)
Rendered layouts/_footer.html.haml (6.6ms)
Completed 200 OK in 130ms (Views: 123.8ms | ActiveRecord: 0.0ms)
However, the page in the browser itself is just white, the progress circle in the tab is spinning, and nothing is showing up.
Anyone know what might be causing this?
UPDATE
The page loads normally when I set config.cache_classes = true in development.rb. But this setting is normally false in development and wasn't doing this before I upgraded.
The problem was being caused by a gem called "rails-dev-tweaks" that is no longer needed in Rails 4. Removing that gem fixed the problem.
Your request on the server side seem to have completed in 130ms so this could be a problem with your client browser. Did you try using a different browser or look at the browser console of any javacript errors?

How do I prevent logging a certain route alone in my log files in production environment

How do I prevent logging a certain route alone in my log files in production environment
Started GET "/bar" for 134.45.310.236 at 2014-00-13 06:36:23 +0000
Processing by FooController#index as HTML
Rendered text template (0.0ms)
Completed 200 OK in 2.6ms (Views: 0.5ms | ActiveRecord: 0.0ms)
Use Silencer Gem
To use it, create an initializer (like config/initializers/silencer.rb) with the contents:
require 'silencer/rails/logger'
Rails.application.configure do
config.middleware.swap(
Rails::Rack::Logger,
Silencer::Logger,
config.log_tags,
silence: ["/noisy/action.json"]
)
end
And just add your routes to the silence array

What is the difference in "Processing by Contoller#method as */*" and "Processing by BillsController#show as HTML"

All of my rails 3.2.2 ActiveRecord methods are being executed twice. I noticed that each execution is being processed differently, see the examples I grabbed from the console below...
Started GET "/api/bills/Jeremy%20Fox" for 127.0.0.1 at 2012-03-20 23:16:43 -0400
Processing by BillsController#show as HTML
Parameters: {"username"=>"Jeremy Fox"}
BillsForUsers Load (2.4ms) SELECT "bills_for_users".* FROM "bills_for_users" WHERE "bills_for_users"."billusername" = 'Jeremy Fox'
Completed 200 OK in 47ms (Views: 11.2ms | ActiveRecord: 2.4ms)
Started GET "/api/bills/Jeremy%20Fox" for 127.0.0.1 at 2012-03-20 23:16:44 -0400
Processing by BillsController#show as */*
Parameters: {"username"=>"Jeremy Fox"}
BillsForUsers Load (1.1ms) SELECT "bills_for_users".* FROM "bills_for_users" WHERE "bills_for_users"."billusername" = 'Jeremy Fox'
Completed 200 OK in 33ms (Views: 28.1ms | ActiveRecord: 1.1ms)
Can anyone explain to me why all of my ActiveRecord methods are being executed twice and/or what the difference is between Processing by BillsController#show as HTML and Processing by BillsController#show as */*?
Thanks.
It turns out the problem was actually the JSONView Chrome extension. As it states in the options menu...
Use safe method to parse HTTP response (*)
(*) : safe method forces the browser to send an extra HTTP request to get the raw HTTP content.
After spending days trying to figure out what I was doing wrong in my code, it was actually just chrome!
Hope no one else runs into this stupid issue.
-Jeremy
I've been grappling with this same issue. The HTML Validator Chrome extension is also guilty (with none of the fine print.)
In my case, I'm calling a ModestModel-backed search request, so the first hit (and rendering) was succeeding, followed by a phantom 500 as my non-DB search model was out of scope and nil on the second request.
Thanks, Jeremy!

ActiveResource adding about 1 second of overhead?

I have two simple Ruby on Rails applications with one using ActiveResource to access the other. The ActiveResource processing seems to be adding ~1000ms of overhead. These are the trace logs:
Requester:
Started GET "/documents/1/retrieve?name=LRActionItems" for 127.0.0.1 at 2011-07-28 17:24:07 -0400
Processing by DocumentsController#retrieve as
Parameters: {"name"=>"LRActionItems", "id"=>"1"}
retrieving persistent_data for id 1 - name LRActionItems
GET http://localhost:3333/field_value_collections/1/field_values/find_by_field_name.xml?field_name=LRActionItems
--> 200 OK 639 (1030.1ms)
Rendered text template (0.0ms)
Completed 200 OK in 1037ms (Views: 1.0ms | ActiveRecord: 1.0ms)
Responder:
Started GET "/field_value_collections/1/field_values/find_by_field_name.xml?field_name=LRActionItems" for 127.0.0.1 at 2011-07-28 17:24:08 -0400
Processing by FieldValuesController#find_by_field_name as XML
Parameters: {"field_name"=>"LRActionItems", "field_value_collection_id"=>"1"}
Completed 200 OK in 3ms (Views: 1.0ms | ActiveRecord: 0.0ms)
cache: [GET /field_value_collections/1/field_values/find_by_field_name.xml?field_name=ULActionItems] miss
As you can see, the responder is responding in 3ms but the requester is requiring 1037ms because the ActiveResource request requires 1030.1ms.
I am in production mode (development mode is actually just a little slower - 10-15ms)
I'm using WEBrick and have done very little customization from the projects as generated.
Is this normal performance? Is there any configuration that can make this much better?

Resources