i have web app running on GF 3.1.1 using MYSQL connection pool. When i check connections to DB using : "show processlist;" i can see everytime that only one connection is used. Why is this happening? There are a lot of threads that do something with DB. Please can someone answer my question?
Thank you very much.
You're connection pool is a pool of available connections. You might have 32 connections available but that doesn't mean it will connect them all. It will manage the connections for you. As demand increases the number of open connections will increase till your max is reached. Likewise as demand decreases your open connections will decrease down to your minimum.
Assuming your queries are fast GF is probably deciding that 1 connection is all that's needed.
Having said all that, the default min connection is 8 so log into your Admin console and look at your connection pool settings. The number of open connections should be at least what the min is set too.
Related
I have Django RestFrameWork application in which we are using sqlalchemy library for MySql connection.
engine = create_engine('mysql+mysqldb://username:password#hostaddress/'
'DBname', pool_recycle=1800,
connect_args={'connect_timeout': 1800}, pool_size=10, max_overflow=10, pool_pre_ping=True)
connection = engine.connect()
As the API usage increases the Mysql is creating new connections and count of threads_connected keeps growing. After reaching max value it is throwing Too many connections error. In show processList many process will be in sleep mode. If we restart the app all the connections will be reset. The following chart indicates no.of connections v/s time. How to fix this issue.
You must close connections after you've finished using them because if you don't, the connection stays open until the webserver closes it which might take a lot of time.
The best practice would be using a connection pool. Because opening and closing connections are too heavy and decreases performance. Even if you're using a connection pool you must let the connection go after you've used it.
for some reason when I open a connection the the Percona MySQL database on my HostGator website, after fetching the query, it will disconnect/ close the connection about 10 seconds later.
I typically wouldn't care, but HeidiSQL freezes up, preventing exporting or sorting the returned rows with it's UI unless I connect again.
Any thoughts on making the connection last longer? is it something I can do myself, or will it require a dedicated server or some upgrade? (I'm currently on a shared one). Thanks!
Sounds like it may be the "wait" timeout on the MySQL connection.
SHOW VARIABLES LIKE 'wait_timeout'
That's the amount of time (in seconds) that MySQL will leave the session (the database connection) open while it's idle, waiting for another statement to be issued. After this amount of time expires, MySQL can close the connection.
You should be able to change this for a session, to change the timeout to 5 minutes
SET wait_timeout = 300
Verify the setting with the SHOW VARIABLES statement again.
NOTE: This is per connection. It only affects the current session. Every new connection will inherit their own wait_timeout value from the global setting.
(This is only a guess. There's insufficient information in the question to make a precise diagnosis. It could be something other than MySQL server that's closing the database connection, e.g. it could be your connection pool settings (if you are using a connection pool).
i am using Glassfish 3 & mysql5.6.11.
i have created JDBC connection pool in glassfish.
Initial and Minimum Pool Size: - 8
Maximum Pool Size: -30
Pool Resize Quantity:- 10
Idle Timeout: - 60 (second).
Max Wait Time:- 2500 (millisecond).
with this parameter i have created pool setting.
i have set pool resize quantity value.
when no of connections increase, it does not release after idle time-out.
next time when i hit url it again increase no of connection, it does not reuse already open connection.
i am getting exception
java.sql.SQLException: Error in allocating a connection. Cause: In-use connections equal max-pool-size and expired max-wait-time. Cannot allocate more connections.
i am using show processlist in mysql to show open connection.
if any one knows the solution of this problem, please share your idea with me.
i need help from any one.
Idle timeout is just the time that unused connections in the pool will remain in the pool before they are closed/recycled. That problem you are having is most likely that you are not closing your connections after use.
Fix your code to close connections when you are done with them, closing a connection will release it back to the connection pool so they are available for reuse.
Some connection pools have additional timeouts for the time a connection can be used, forcing the connection back in the pool after that time. Which to the user of that connection will look as if the connection has been closed. I don't think the glassfish pool has this option though.
I am using Hibernate with c3p0 as pooling provider. I have set its max size as 50 only. Now, I performed load testing of my application with 1000 concurrent threads accessing database continuously and with mysql max_connections as 2000. I am getting proper responses from the application but sometimes I face socket exception error.
So, first thing is if my pooling size is 50 only, how 1000 connections are managed by hibernate ? Does it mean that 50 connections are being taken from the pool and rest of the connections are created? Also, why I must be getting socket exception like connection reset exception?
if you've set things up properly and c3p0's maxPoolSize is 50, then if 1000 clients hit the pool, 50 will get Connections initially and the rest will wait() briefly until Connections are returned by the first cohort. the pool's job, in collaboration with your application which should hold Connections as briefly as possible, is to ensure that a limited number of Connections are efficiently shared.
if you are seeing occasional connection reset / socket exception, you probably ought to configure some Connection testing:
http://www.mchange.com/projects/c3p0/index.html#configuring_connection_testing
the latest prerelease version has some more direct advice about connection testing; you can download that or read the html source starting here:
https://github.com/swaldman/c3p0/blob/master/src/doc/index.html#L1071
It's usually set to 60 seconds.
But I think con pool will hold the connection, so is there any conflict? Thank you.
Here is the answer from Glassfish Wiki:
idle-timeout-in-seconds
maximum time in seconds, that a connection can remain idle in
the pool. After this time, the pool implementation can close
this connection. ====>Note that this does not control connection
timeouts enforced at the database server side<====. Adminsitrators
are advised to keep this timeout shorter than the EIS
connection timeout (if such timeouts are configured on the
specific EIS), to prevent accumulation of unusable connection
in Application Server.