Threading error when using `ActiveRecord with_connection do` & ActionController::Live

Warning: read ‘answer’ as ‘seems to make a difference’ I don’t see the issue happen if I change the controller block to look like: begin #… while true do t = Thread.new do #<<<<<<<<<<<<<<<<< ActiveRecord::Base.connection_pool.with_connection do |conn| #… end end t.join #<<<<<<<<<<<<<<<<< end #… rescue IOError #… But I don’t know whether this has actually … Read more

How rails database connection pool works

Purpose: Database connections are not thread safe; so ActiveRecord uses separate database connection for each thread. Limiting factor: Total database connections is limited by the database server you use (e.g Posgres: default is typically 100 or lesser), by your app server’s configuration (number of processes/threads available) and Active Record’s configuration : Connection Pool defaults to … Read more

How does pgBouncer help to speed up Django

Besides saving the overhead of connect & disconnect where this is otherwise done on each request, a connection pooler can funnel a large number of client connections down to a small number of actual database connections. In PostgreSQL, the optimal number of active database connections is usually somewhere around ((2 * core_count) + effective_spindle_count). Above … Read more

How to detect SqlServer connection leaks in a ASP.net applications?

Found this thread researching a similar problem. I came up with the following sql as a good way to debug leaky connections in SQL Server: SELECT S.spid, login_time, last_batch, status, hostname, program_name, cmd, ( select text from sys.dm_exec_sql_text(S.sql_handle) ) as last_sql FROM sys.sysprocesses S where dbid > 0 and DB_NAME(dbid) = ‘<my_database_name>’ and loginame=”<my_application_login>” order … Read more

How Jedis Pool works?

You haven’t configured the maxTotal size of the pool, and the default value is only 8. You could change the JedisFactory constructor to: public JedisFactory() { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(128); jedisPool = new JedisPool(poolConfig, RedisDBConfig.HOST, RedisDBConfig.PORT, RedisDBConfig.TIMEOUT, RedisDBConfig.PASSWORD); } Beware also of the default value of the WhenExhaustedAction (WHEN_EXHAUSTED_BLOCK), as it may not … Read more

Correct way to keep pooled connections alive (or time them out and get fresh ones) during longer inactivity for MySQL, Grails 2 app

The easiest is to configure the connection pool to specify the query to be run to test the connection before it is passed to the application: validationQuery=”select 1 as dbcp_connection_test” testOnBorrow=true This same “connection validation” query can be run on other events. I’m not sure of the defaults for these: testOnReturn=true testWhileIdle=true There are also … Read more

Difference between BasicDatasource and PoolingDatasource

BasicDataSource is, as the javadoc says, a one-stop shopping for basic needs. It has all the necessary. It creates internally a PoolableDataSource and an ObjectPool. PoolingDataSource implements the DataSource interface using a provided ObjectPool. PoolingDatasource take cares of whatever has to do with connections (casting, checking validity, setting properties, etc) and ObjectPool take cares of … Read more

How to Debug / Log Tomcat JDBC Connection Pool’s connections?

After a lot of research, I am able to find 3 ways to log & monitor database connection pool. https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html Monitoring using Spring Boot properties. Monitoring using JMX ( Java Management Extensions ) (as @nitin suggested) Monitoring using Spring Aspects. 1st Way: Monitoring using Spring Boot properties. I found below Spring boot properties which will … Read more

Connection pooling in java using HttpClient [closed]

I have spent recent days working on this so just want to share some “everyone-known” knowledges with you. First, as you are dealing with the same server, it is recommended to use a single HTTP client to execute your requests. With the help of PoolingHttpClientConnectionManager, your client can be used to execute multiple requests concurrently. … Read more