-
Notifications
You must be signed in to change notification settings - Fork 211
Closing Datasource connection when calling Base.close #996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
looks like you are starving your app of database connections. Having hundreds of connections to DB open at any given time is a bad idea, unless you are actually using them all. In any case, I suggest to source connections from the pool not when your user connects but when that user actually needs a connection. If you have a good architecture, you probably have such places. When you need a connection, do not open a new one, but rather request an instance of |
Thanks for the link, this seems to work perfectly! This might be a little off-topic but, just wondering would it be okay to open/close the connection from/to the pool when doing constant action several times? For example if a user would do x action 100+ times it would update the data on the spot (get connection from pool, update, then close conn) all within a couple of seconds/minutes? I just recently ported from hibernate -> activejdbc so I apologize for these questions! Otherwise, thanks again, I appreciate it! |
@imtigeroo no problem asking questions! generally speaking, if you want to use a connection from a pool for a very short time, even for running many requests in seconds, it is fine. However, holding on to a connection when you do not need it (minutes) is a very bad idea, and will not scale. This has nothing to do with ActiveJDBC, just common logic. If you pick a connection from a pool, than this connection is not available for other threads, so you may get exceptions from a pool telling that pool is exhausted, or your other threads will be blocked on the pool waiting for connections to be returned by other threads. Congrats on porting from Hibernate, how was your experience and what is your perception of ActiveJDBC so far? |
I'm currently using HikariCP for connection pooling, since Base.open needs to be called or attached to every thread that access the DB I have attached it to my Channel Handlers in my Netty Socket implementation (NIO / NIO-EventLoopGroup thread). So when a user connects it opens a connection per user (we can have hundreds connected at a time) and when a user goes inactive, I close the connection via Base.close.
However, the connection pool never closes so after 30 connections, i'm not able to connect to the DB using Base.open as it reports that
too many connections are open
and it gives up trying to connect to the DB after 3 attempts.Is there a way to have one single instance of
Base.open
and have be shared throughout my Netty NIO threads? I'm not sure how to avoid this error where it fails to connect due to too many connections even when calling Base.close.Thank you.
The text was updated successfully, but these errors were encountered: