Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does this code utilize jetty connection pooling?

 
Rj Ewing
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I missing something to utilize connection pooling from jetty? When I look at the active connections in mysql, they are constantly going up and down as connections are opened/closed. It seems that connection pooling they would go up as need (to max-connections) and no "close", but be returned to the pool. What am I missing?

I'm creating a new BcidDatabase() every time I need to fetch a connection.





jetty-env.xml
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use a connection pool (not the one in Jetty but still a well-designed connection pool as far as I can tell) it seems to do a lot of connection-closing. So perhaps what you're seeing is normal.

On the other hand there's still the nagging feeling that closing a connection and then opening a new connection is consuming resources unnecessarily. Perhaps there's a configuration option to say how long to keep a connection open after it's returned to the pool, or something like that?
 
Dave Tolls
Ranch Hand
Posts: 1904
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What connection pool are you using?
Jetty uses whatever you give it.

And that connection pool will have values for min_size, max_size etc.
So if you have a min_size of 5 and a max of 20 then you will see the number of connections go up (into the max range) and then back down.
If that's happening a lot under "normal" load then you possibly want to up your min size a bit.
If it's only at peak, then I wouldn't worry.
 
Tim Holloway
Saloon Keeper
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection pools slap a façade over the JDBC driver.

For most JDBC functions, the façade driver merely passed through to the actual driver specified in the pool definition.

The one exception is the close() method. That one returns the Connection to the Connection Pool. It does not close the actual JDBC connection.

If you do not close the connection when you are done using it (preferably as soon as possible), then you will leak connections all over the landscape and eventually empty the connection pool. If you punch past the pool connection façade and invoke the actual JDBC close() method, then the physical connection to the database will be severed and the pool connection will be damaged with unpredictable results on the next task that pulls that particular connection from the pool.

The reason for connection pools is that physical connections are expensive in terms of time and resources to establish. So rather than make-and-break for each use, it's better to recycle connections that are already established. The connection pool contains these connections.

An additional note: never store a Connection as a Session object. it's an interface, not a class, and it's not guaranteed serializable. Even if it was, you'd be robbing the pool of resources, because once checked out of the pool, it's unavailable to other users.
 
Rj Ewing
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:What connection pool are you using?
Jetty uses whatever you give it.

And that connection pool will have values for min_size, max_size etc.
So if you have a min_size of 5 and a max of 20 then you will see the number of connections go up (into the max range) and then back down.
If that's happening a lot under "normal" load then you possibly want to up your min size a bit.
If it's only at peak, then I wouldn't worry.


Hmm, I thought I was using the MySqlConnectionPool, but now I think that maybe I'm missing something. How would I "give" jetty the connection pool?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rj Ewing wrote:Hmm, I thought I was using the MySqlConnectionPool, but now I think that maybe I'm missing something. How would I "give" jetty the connection pool?


I haven't used Jetty but it looks to me like you did that here:


 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did some web searching and I came across a Jetty configuration just like the one you have. But it's in a section of the documentation headed "Non-pooling Data Sources". And then I came across a Stack Overflow answer which stated "The MysqlConnectionPoolDataSource is not a connection pool." It went on to recommend using an actual connection pool like C3P0.

I find it kind of counter-intuitive that MysqlConnectionPoolDataSource is the name for a class which doesn't do connection pooling, but anyway based on that I would say the answer to your original question is "No".
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"MysqlConnectionPoolDataSource" is a misleading class name, because it does not actually maintain a connection pool itself. It's actually the interface provided by Connector/J for use by an actual connection pooling provider like DBCP. Use Apache DBCP or c3p0 for actuall connection pooling (https://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource).

Edit: Ah, Paul you beat me to it.

 
Rj Ewing
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah, that is a bit misleading. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic