use of org.apache.commons.pool2.impl.GenericObjectPool in project cas by apereo.
the class MemcachedMonitorConfiguration method memcachedHealthIndicator.
@Bean
public HealthIndicator memcachedHealthIndicator() {
final MonitorProperties.Memcached memcached = casProperties.getMonitor().getMemcached();
final MemcachedPooledClientConnectionFactory factory = new MemcachedPooledClientConnectionFactory(memcached, memcachedMonitorTranscoder());
final ObjectPool<MemcachedClientIF> pool = new GenericObjectPool<>(factory);
return new MemcachedHealthIndicator(pool, casProperties);
}
use of org.apache.commons.pool2.impl.GenericObjectPool in project herddb by diennea.
the class BasicHerdDBDataSource method ensureClient.
protected synchronized void ensureClient() throws SQLException {
if (client == null) {
ClientConfiguration clientConfiguration = new ClientConfiguration(properties);
LOGGER.log(Level.SEVERE, "Booting HerdDB Client, url:" + url + ", properties:" + properties + " clientConfig " + clientConfiguration);
clientConfiguration.readJdbcUrl(url);
client = new HDBClient(clientConfiguration);
}
if (pool == null) {
if (properties.containsKey("maxActive")) {
this.maxActive = Integer.parseInt(properties.get("maxActive").toString());
}
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setBlockWhenExhausted(true);
config.setMaxTotal(maxActive);
config.setMaxIdle(maxActive);
config.setMinIdle(maxActive / 2);
config.setJmxNamePrefix("HerdDBClient");
pool = new GenericObjectPool<>(new ConnectionsFactory(), config);
}
}
use of org.apache.commons.pool2.impl.GenericObjectPool in project atlasdb by palantir.
the class CassandraClientPoolingContainer method createClientPool.
/**
* Pool size:
* Always keep {@link CassandraKeyValueServiceConfig#poolSize()} connections around, per host. Allow bursting
* up to {@link CassandraKeyValueServiceConfig#maxConnectionBurstSize()} connections per host under load.
*
* Borrowing from pool:
* On borrow, check if the connection is actually open. If it is not,
* immediately discard this connection from the pool, and try to take another.
* Borrow attempts against a fully in-use pool immediately throw a NoSuchElementException.
* {@code CassandraClientPool} when it sees this will:
* Follow an exponential backoff as a method of back pressure.
* Try 3 times against this host, and then give up and try against different hosts 3 additional times.
*
* In an asynchronous thread (using default values):
* Every 20-30 seconds, examine approximately a tenth of the connections in pool.
* Discard any connections in this tenth of the pool whose TCP connections are closed.
* Discard any connections in this tenth of the pool that have been idle for more than 10 minutes,
* while still keeping a minimum number of idle connections around for fast borrows.
*
* @param poolNumber number of the pool for metric registration.
*/
private GenericObjectPool<CassandraClient> createClientPool(int poolNumber) {
CassandraClientFactory cassandraClientFactory = new CassandraClientFactory(qosClient, host, config);
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMinIdle(config.poolSize());
poolConfig.setMaxIdle(config.maxConnectionBurstSize());
poolConfig.setMaxTotal(config.maxConnectionBurstSize());
// immediately throw when we try and borrow from a full pool; dealt with at higher level
poolConfig.setBlockWhenExhausted(false);
poolConfig.setMaxWaitMillis(config.socketTimeoutMillis());
// this test is free/just checks a boolean and does not block; borrow is still fast
poolConfig.setTestOnBorrow(true);
poolConfig.setMinEvictableIdleTimeMillis(TimeUnit.MILLISECONDS.convert(config.idleConnectionTimeoutSeconds(), TimeUnit.SECONDS));
// the randomness here is to prevent all of the pools for all of the hosts
// evicting all at at once, which isn't great for C*.
int timeBetweenEvictionsSeconds = config.timeBetweenConnectionEvictionRunsSeconds();
int delta = ThreadLocalRandom.current().nextInt(Math.min(timeBetweenEvictionsSeconds / 2, 10));
poolConfig.setTimeBetweenEvictionRunsMillis(TimeUnit.MILLISECONDS.convert(timeBetweenEvictionsSeconds + delta, TimeUnit.SECONDS));
poolConfig.setNumTestsPerEvictionRun(-(int) (1.0 / config.proportionConnectionsToCheckPerEvictionRun()));
poolConfig.setTestWhileIdle(true);
poolConfig.setJmxNamePrefix(CassandraLogHelper.host(host));
GenericObjectPool<CassandraClient> pool = new GenericObjectPool<>(cassandraClientFactory, poolConfig);
registerMetrics(pool, poolNumber);
return pool;
}
use of org.apache.commons.pool2.impl.GenericObjectPool in project ofbiz-framework by apache.
the class DebugManagedDataSource method getConnection.
@Override
public Connection getConnection() throws SQLException {
if (Debug.verboseOn()) {
if (super.getPool() instanceof GenericObjectPool) {
GenericObjectPool objectPool = (GenericObjectPool) super.getPool();
Debug.logVerbose("Borrowing a connection from the pool; used/idle/total: " + objectPool.getNumActive() + "/" + objectPool.getNumIdle() + "/" + (objectPool.getNumActive() + objectPool.getNumIdle()) + "; min idle/max idle/max total: " + objectPool.getMinIdle() + "/" + objectPool.getMaxIdle() + "/" + objectPool.getMaxTotal(), module);
} else {
if (Debug.verboseOn())
Debug.logVerbose("Borrowing a connection from the pool; used/idle/total: " + super.getPool().getNumActive() + "/" + super.getPool().getNumIdle() + "/" + (super.getPool().getNumActive() + super.getPool().getNumIdle()), module);
}
}
return super.getConnection();
}
use of org.apache.commons.pool2.impl.GenericObjectPool in project ofbiz-framework by apache.
the class DebugManagedDataSource method getInfo.
public Map<String, Object> getInfo() {
Map<String, Object> dataSourceInfo = new HashMap<String, Object>();
dataSourceInfo.put("poolNumActive", super.getPool().getNumActive());
dataSourceInfo.put("poolNumIdle", super.getPool().getNumIdle());
dataSourceInfo.put("poolNumTotal", (super.getPool().getNumIdle() + super.getPool().getNumActive()));
if (super.getPool() instanceof GenericObjectPool) {
GenericObjectPool objectPool = (GenericObjectPool) super.getPool();
dataSourceInfo.put("poolMaxActive", objectPool.getMaxTotal());
dataSourceInfo.put("poolMaxIdle", objectPool.getMaxIdle());
dataSourceInfo.put("poolMaxWait", objectPool.getMaxWaitMillis());
dataSourceInfo.put("poolMinEvictableIdleTimeMillis", objectPool.getMinEvictableIdleTimeMillis());
dataSourceInfo.put("poolMinIdle", objectPool.getMinIdle());
}
return dataSourceInfo;
}
Aggregations