Sinatra jruby activerecord application and closing connections

I am running a jruby application on sinatra and using activerecord and
after I have given the application a significant amount of traffic, i
start to run out of connections in my connection pool. It got me
thinking that since i am not in rails and i have manually configured
activerecord myself, should i add code to return the connections to
the pool at the end of each request to sinatra? My guess is that
rails does this for free, but not in sinatra and this might be the
cause of my issue.

thx.

-karl


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

That exactly what i did in an after filter. I also had to set :lock,
true

Jay

On Jul 27, 2010, at 5:52 PM, Karl B. [email protected] wrote:


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Why did you have to set lock to true?

Thx!

– Sent from my Palm Pre
On Jul 27, 2010 9:34 PM, Jay McGaffigan <[email protected]>
wrote:

That exactly what i did in an after filter. I also had to set :lock,
true

Jay

On Jul 27, 2010, at 5:52 PM, Karl B. <[email protected]n.invalid>
wrote:

> I am running a jruby application on sinatra and using activerecord
and after I have given the application a significant amount of traffic,
i start to run out of connections in my connection pool. It got me
thinking that since i am not in rails and i have manually configured
activerecord myself, should i add code to return the connections to the
pool at the end of each request to sinatra? My guess is that rails does
this for free, but not in sinatra and this might be the cause of my
issue.

>

> thx.

>

> -karl

>

>

> To unsubscribe from this list, please visit:

>

> http://xircles.codehaus.org/manage_email

>

>


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

We are using a builder template and I was setting instance variables
on my sinatra object. (I have a class that derives from Sinatra::Base

When I retrieve information from ActiveREcord I was setting it to an
instance variable on the class and invoking builder to generate some
XML. This was getting in the way of multiple requests… I think… I
was getting odd errors before setting lock to true.

Now that things are working and we are profiling the system I am going
to go back and “investigate” that decision to see what I can do.

Jay

On Tue, Jul 27, 2010 at 9:51 PM, Karl B. [email protected] wrote:

That exactly what i did in an after filter. I also had to set :lock, true

since i am not in rails and i have manually configured activerecord myself,


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Makes sense. I added this to my my Sinatra::Base class but i am still
running out of db connections:

after do
ActiveRecord::Base.clear_active_connections!
end

Any ideas?

thx!

On Jul 28, 2010, at 9:09 AM, Jay McGaffigan wrote:

– Sent from my Palm Pre

should i add code to return the connections to the pool at the end
To unsubscribe from this list, please visit:


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

hmm. I do that as well here is a snippet of my code:

#ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(db_configs[MAP_ENV])

class MapServiceApp < Sinatra::Base
use SeaChange::CausalityFilter

set :lock, true

configure do
SeaChange::Logging.init(’.’)
end

LOGGER = SeaChange::Logging.get_logger("map_service")
#LOGGER = $stdout
LOGGER.debug "Logger map_service initialized"

end

helpers do
def logger
LOGGER
end
end

after do
#close all db connections if we are using JDBC pooling closing
here will just return to the pool.
ActiveRecord::Base.clear_active_connections!
end

I guess the next question is :

What database are you using? What jdbc driver? Could that need to be
configured differently?

What app container are you running under? We war up our app and run
it in tomcat

Jay

On Wed, Jul 28, 2010 at 1:04 PM, Karl B. [email protected] wrote:

Now that things are working and we are profiling the system I am going

request to sinatra? My guess is that rails does this for free, but not
http://xircles.codehaus.org/manage_email

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I forgot to mention that I am using sql server 2000. Which uses the
jtds driver

hmm. I wonder if there is something going on at the jdbc driver
layer…

actually I am not specifying the pool size… (isn’t it 5 by default?)
here is my info:

production:
adapter : jdbcmssql
jndi : java:comp/env/jdbc/map_service_ds

Jay

On Wed, Jul 28, 2010 at 3:26 PM, Karl B. [email protected] wrote:

pool: 30

end
end

was getting odd errors before setting lock to true.

Thx!

since i am not in rails and i have manually configured activerecord

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I am using jetty_rackup, but i am using activerecord connection
pooling to mysql. Here is my database.yml

staging:
adapter: jdbcmysql
database: mydatabase
username: username
password: **********
host: 127.0.0.1
port: 3307
pool: 30

Thanks!

-karl

On Jul 28, 2010, at 2:41 PM, Jay McGaffigan wrote:

def logger

ActiveRecord::Base.clear_active_connections!

Sinatra::Base

Jay

since i am not in rails and i have manually configured
thx.


http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

the big difference is that you are using the app server’s data
source. I am going to give that a try and see if i notice anything
different.

thx

On Jul 28, 2010, at 3:59 PM, Jay McGaffigan wrote:

adapter : jdbcmssql

pooling to

#ActiveRecord::Base.logger = Logger.new(STDOUT)

What database are you using? What jdbc driver? Could that need

to go back and “investigate” that decision to see what I can do.

start
but not
http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs