WebSphere Tutorial · WebSphere Liberty · Lesson 9 of 23
Data Sources and Connection Pools
Configuring JDBC data sources in Liberty, how connection pools work, and how to size them.
A Liberty data source
<featureManager><feature>jdbc-4.3</feature></featureManager>
<library id="pgLib"><fileset dir="${shared.resource.dir}/jdbc" includes="postgresql-*.jar"/></library>
<dataSource id="ordersDS" jndiName="jdbc/orders">
<jdbcDriver libraryRef="pgLib"/>
<properties.postgresql serverName="${db.host}" databaseName="orders" user="${env.DB_USER}" password="${env.DB_PASSWORD}"/>
<connectionManager maxPoolSize="30" minPoolSize="2" connectionTimeout="10s" maxIdleTime="10m" agedTimeout="30m"/>
</dataSource>
How the pool works
Opening a database connection is slow, so the server keeps a pool. A request borrows a connection, uses it and
returns it. When all are in use, the next request waits up to the connection timeout, then fails (traditional
WAS logs J2CA0045E). Liberty's defaults are a maximum of 50 connections and a 30-second timeout; traditional WAS
defaults to a maximum of 10 and 180 seconds.
Sizing
- The total across servers (max pool × servers) must stay below the database's connection limit.
- Bigger isn't faster: a database with too many active connections slows down.
- Short timeouts fail fast instead of letting requests pile up.
import math
def pool_needed(requests_per_s, query_ms, held_extra_ms=0):
in_use = requests_per_s * (query_ms + held_extra_ms) / 1000 # Little's law: average connections busy
return math.ceil(in_use * 1.3) # 30% headroom
print("fast queries, released promptly:", pool_needed(200, 20), "connections")
print("same load, slow query (400 ms): ", pool_needed(200, 400), "connections")
print("connection held during a 1s HTTP call:", pool_needed(200, 20, 1000), "connections")
servers, max_pool, db_limit = 6, 50, 200
total = servers * max_pool
print(f"{servers} servers x maxPoolSize {max_pool} = {total} possible connections vs database limit {db_limit}"
f" -> {'TOO MANY' if total > db_limit else 'ok'}")
Output
fast queries, released promptly: 6 connections same load, slow query (400 ms): 104 connections connection held during a 1s HTTP call: 266 connections 6 servers x maxPoolSize 50 = 300 possible connections vs database limit 200 -> TOO MANY
Test yourself
Six servers each have maxPoolSize 50. The database allows 200 connections. What's wrong?
NothingThe servers could open 300 connections, more than the database allowsThe pool is too smallLiberty ignores maxPoolSize
Show answer
Answer: The servers could open 300 connections, more than the database allows
Pool sizes multiply by the number of servers.