Database timeouts

2010-04-16 Thread Eric Anderson
I have been testing with Heroku for internal apps for a while and am
now moving into hosting commercial apps on Heroku. Unfortunately I am
running into some timeout problems with accessing the database. The
below is an example error message I have gotten (e-mail address
removed):

  A ActiveRecord::StatementInvalid occurred in user_sessions#create:

PGError: ERROR:  canceling statement due to statement timeout
  : SELECT * FROM "users" WHERE (LOWER("users".email) =
E'xxx...@hotmail.com')  LIMIT 1
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/connection_adapters/abstract_adapter.rb:219:in
`log_without_newrelic_instrumentation'

As you can see my query is quite simple. So I don't think the problem
is it being a complicated query. Also there are only about 20 users so
it is not a case of trying to look through too much data. I think
Heroku sets the database timeout to 6 seconds which seems to be plenty
of time to run such a simple query. I contacted Heroku support about
these problems and they told me that it was probably due to another
user on the shared database hogging the resources and suggested I move
to a dedicated database. But since a dedicated database STARTS at $200/
month that is not realistic for this app (and a lot of apps I
imagine).

Where this problem has REALLY bit me in ass is when the error occurs
as the app starts up. I use the Enforce Schema Rules[1] plugin to
automatically setup validations based on the database to make my app a
bit more dry. This plugin simply scans the columns and calls the
appropriate validates_X methods to mirror what is in the database.
Since it does this scanning as the object loads this means my app is
contacting the database as the app loads. If I get this timeout then
the app fails to load. What is worse is that if the user tries to hit
the app again heroku doesn't try again. I have to manually restart the
app in order for it to try again. This means my app is down until I
manually restart.

So my questions are:

1. Is there anything I can do to prevent these timeouts. Would
increasing the timeout beyond 6 seconds help? I imagine to do that I
just need to run a query at the start of a request.
2. If I get an error on startup (database or otherwise) is there a way
I can have heroku try again on the next request instead of doing a
manual restart.
3. Would it help to disable eager class loading by adding the
following to my production environment:

config.eager_load_paths = []

Disabling eager loading would cause the app to not contact the
database on startup. Would adding that cause any other problems? I
found one article that suggested disabling eager loading can help
situations like this[2] and another that says it causes random
problems in the app[3]. Or maybe I should just drop the plugin and
manually type in all the validation macros myself?

Any advice would be greatly appreciated.

1. http://agilewebdevelopment.com/plugins/enforce_schema_rules
2. 
http://pivotallabs.com/users/scott/blog/articles/693-standup-2-9-09-chaining-associatons-use-rails-error-handling-and-eager-load-paths
3. 
http://www.whatcodecraves.com/articles/2009/03/17/rails_2.2.2_chicken_and_egg_migrations_headache/

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to her...@googlegroups.com.
To unsubscribe from this group, send email to 
heroku+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.



Re: Bundler and read only file system error

2010-04-16 Thread morgoth
I just checked configuration for rails 2.3.5 app and it is the same
problem.
Put code from gist in config/preinitiazer.rb and push it to heroku.

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to her...@googlegroups.com.
To unsubscribe from this group, send email to 
heroku+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.



Bundler and read only file system error

2010-04-16 Thread morgoth
Hi.
If you are using bundler and you are on the edge with configuration
(rails3 and rails 2.3.5) you will get error on heroku saying about
read only file system.

That is because config/boot.rb has changed:
When you generate new rails3 app you will have config/boot.rb like
this:

require 'rubygems'
# Set up gems listed in the Gemfile.
if File.exist?(File.expand_path('../../Gemfile', __FILE__))
  require 'bundler'
  Bundler.setup
end

This wont work on heroku! (at least now)
Bundler wants to create .bundle/environment.rb which is prohibited.

So you need to use old style of config/boot.rb:
http://gist.github.com/368681

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to her...@googlegroups.com.
To unsubscribe from this group, send email to 
heroku+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.



Re: Howto: automate DB backups

2010-04-16 Thread Trevor Turk
On Apr 16, 6:20 am, kobi  wrote:
> One offtopic question: do you store your backups unencrypted?
> If not what encrypting gems/libs you are using on Heroku?

I'm just using the private bucket and storing the database backups
there unencrypted. I think the private bucket is enough protection for
my case. If you feel something else is necessary and produce some
code, please do share, though!

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to her...@googlegroups.com.
To unsubscribe from this group, send email to 
heroku+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.



Re: Howto: automate DB backups

2010-04-16 Thread kobi
I've just added Trevor's backup solution to my app on Heroku and works
fine ...

One offtopic question: do you store your backups unencrypted?
If not what encrypting gems/libs you are using on Heroku?

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to her...@googlegroups.com.
To unsubscribe from this group, send email to 
heroku+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.