tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: tomcat jdbc pool, creating a pool of pools, single connection memory footprint
Date Fri, 01 Jun 2012 18:37:00 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ahmed,

On 5/31/12 9:33 AM, S Ahmed wrote:
>> It would be easier if all databases were hosted by a single
>> instance of MySQL -- then you could use Tomcat-pool's feature of
>> being able to provide credentials when obtaining connections from
>> the pool -- and get the right database. That way, a much smaller
>> number of connections could be maintained with roughly the same
>> semantics.
> 
> Can you expand on how I could do this?

Well, first you have to accept that the same MySQL instance (with
perhaps different databases) will be hosting all your data. If that's
not okay with you, then you can forget this suggestion (or, maybe it
just changes the suggestion slightly because you could always have N
databases and maybe 4 MySQL instances when them split across the 4...
but then you'd have to figure out which connection pool to grab before
getting a connection or you'd never get connected).

Next, you'd have to switch to tomcat-pool because commons-dbcp (the
default CP in Tomcat) does not support obtaining pooled connections
with credentials.

Next, you remove the database name from the JDBC URL (or maybe change
it to something everyone can access, like the 'test' database or
'information_schema' depending on your version of MySQL).

Then, you have your code call
DataSource.getConnection(username,password) instead of calling
DataSource.getConnection(). This gets you the right credentials for
your target database.

Finally, make sure you issue a query to set the database for the
connection:

'USE databasename;'

Then, you set your connection pool to have however many connections
you want (100?) and every client (thread) shares those connections
with every client database that runs in a particular MySQL instance.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk/JC8wACgkQ9CaO5/Lv0PBEpgCghI3t8gpE+SBSNV/pYjyLqqwq
2hwAoIY8mYqGGG+owxzsFPQ+CFa2cVeL
=Fh/Y
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message