Search in sources :

Example 91 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project chao-cloud by chaojunzi.

the class RedisDynamicConfig method buildPoolConfig.

/**
 * 构造对象池
 *
 * @param lettuce {@link Lettuce}
 * @return {@link GenericObjectPoolConfig}
 */
@SuppressWarnings("rawtypes")
private GenericObjectPoolConfig buildPoolConfig(Lettuce lettuce) {
    Pool pool = lettuce.getPool();
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    if (pool != null) {
        poolConfig.setMaxTotal(pool.getMaxActive());
        poolConfig.setMaxIdle(pool.getMaxIdle());
        poolConfig.setMaxWaitMillis(pool.getMaxWait().toMillis());
        poolConfig.setMinIdle(pool.getMinIdle());
    }
    poolConfig.setEvictorShutdownTimeoutMillis(lettuce.getShutdownTimeout().toMillis());
    return poolConfig;
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) Pool(org.springframework.boot.autoconfigure.data.redis.RedisProperties.Pool)

Example 92 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project hazelcast-simulator by hazelcast.

the class Jedis3Driver method startDriverInstance.

@Override
public void startDriverInstance() throws Exception {
    Set<HostAndPort> addresses = getAddresses();
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(100);
    if (get("REDIS_CLUSTER_PASSWORD") != null) {
        this.client = new JedisCluster(addresses, 30000, 30000, 3, get("REDIS_CLUSTER_PASSWORD"), poolConfig);
    } else {
        this.client = new JedisCluster(addresses, poolConfig);
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisCluster(redis.clients.jedis.JedisCluster)

Example 93 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project x-pipe by ctripcorp.

the class XpipeNettyClientPool method createDefaultPoolConfig.

private static GenericObjectPoolConfig createDefaultPoolConfig() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setJmxEnabled(false);
    return config;
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig)

Example 94 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project cicada by aquariusStudio.

the class SwtWebAccessorService method createObjectPool.

/**
 * Use pool to manager swt browser resource.
 */
private void createObjectPool() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMinEvictableIdleTimeMillis(-1);
    config.setMaxTotal(20);
    PooledObjectFactory<SwtWebAccessor> pooledObjectFactory = new BasePooledObjectFactory<SwtWebAccessor>() {

        @Override
        public SwtWebAccessor create() throws Exception {
            ObjectHolder<SwtWebAccessor> objectHolder = new ObjectHolder<>();
            SwtWebAccessorService.this.display.syncExec(new Runnable() {

                @Override
                public void run() {
                    Browser browser = createBrowserTabItem();
                    BrowserUtil.initialize(browser);
                    SwtWebAccessor webAccessor = new SwtWebAccessor(browser, SwtWebAccessorService.this);
                    objectHolder.setValue(webAccessor);
                }

                /**
                 * @return
                 */
                private Browser createBrowserTabItem() {
                    TabItem item = new TabItem(SwtWebAccessorService.this.parentTab, SWT.NONE);
                    Composite parent = new Composite(SwtWebAccessorService.this.parentTab, SWT.None);
                    GridLayout gridLayout = new GridLayout(2, false);
                    parent.setLayout(gridLayout);
                    Text urlText = new Text(parent, SWT.FLAT);
                    urlText.setEditable(false);
                    urlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                    Button copyButton = new Button(parent, SWT.PUSH);
                    copyButton.setLayoutData(new GridData());
                    copyButton.setText(Messages.ActionCopy);
                    copyButton.addSelectionListener(new SelectionAdapter() {

                        /**
                         * {@inheritDoc}
                         */
                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            ClipboardUtil.setClipboardString(urlText.getText());
                        }
                    });
                    Browser browser = new Browser(parent, WorkbenchActivator.getDefault().getBrowserStyle());
                    browser.addLocationListener(new LocationAdapter() {

                        @Override
                        public void changing(LocationEvent event) {
                            urlText.setText(browser.getUrl());
                        }
                    });
                    GridData gridData = new GridData(GridData.FILL_BOTH);
                    gridData.horizontalSpan = 2;
                    browser.setLayoutData(gridData);
                    item.setText(" " + SwtWebAccessorService.this.parentTab.getItemCount() + " ");
                    item.setControl(parent);
                    return browser;
                }
            });
            return objectHolder.getValue();
        }

        @Override
        public PooledObject<SwtWebAccessor> wrap(SwtWebAccessor webAccessor) {
            return new DefaultPooledObject<SwtWebAccessor>(webAccessor);
        }

        /**
         * {@inheritDoc}}
         */
        @Override
        public void passivateObject(PooledObject<SwtWebAccessor> pooledObject) throws Exception {
            pooledObject.getObject().get(AboutBlank, DefaultProcessMonitor.createInstance());
        }
    };
    this.webAccessorPool = new GenericObjectPool<>(pooledObjectFactory, config);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) ObjectHolder(org.aquarius.util.ObjectHolder) TabItem(org.eclipse.swt.widgets.TabItem) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) GridLayout(org.eclipse.swt.layout.GridLayout) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) Button(org.eclipse.swt.widgets.Button) PooledObject(org.apache.commons.pool2.PooledObject) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) BasePooledObjectFactory(org.apache.commons.pool2.BasePooledObjectFactory) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 95 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig 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.
 */
private GenericObjectPool<CassandraClient> createClientPool() {
    CassandraClientConfig clientConfig = CassandraClientConfig.of(config);
    CassandraClientFactory cassandraClientFactory = new CassandraClientFactory(metricsManager, proxy, clientConfig);
    GenericObjectPoolConfig<CassandraClient> 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);
    // this test is free/just checks a boolean and does not block; borrow is still fast
    poolConfig.setTestOnBorrow(true);
    poolConfig.setSoftMinEvictableIdleTimeMillis(TimeUnit.MILLISECONDS.convert(Duration.ofSeconds(config.idleConnectionTimeoutSeconds())));
    poolConfig.setMinEvictableIdleTimeMillis(Long.MAX_VALUE);
    // 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(Duration.ofSeconds(timeBetweenEvictionsSeconds + delta)));
    poolConfig.setNumTestsPerEvictionRun(-(int) (1.0 / config.proportionConnectionsToCheckPerEvictionRun()));
    poolConfig.setTestWhileIdle(true);
    poolConfig.setJmxNamePrefix(proxy.getHostString());
    poolConfig.setEvictionPolicy(new DefaultEvictionPolicy<>());
    GenericObjectPool<CassandraClient> pool = new GenericObjectPool<>(cassandraClientFactory, poolConfig);
    pool.setSwallowedExceptionListener(exception -> log.info("Swallowed exception within object pool", exception));
    registerMetrics(pool);
    log.info("Creating a Cassandra client pool for {} with the configuration {}", SafeArg.of("cassandraHost", cassandraServer.cassandraHostName()), SafeArg.of("proxy", proxy), SafeArg.of("poolConfig", poolConfig));
    return pool;
}
Also used : CassandraClientConfig(com.palantir.atlasdb.keyvalue.cassandra.CassandraClientFactory.CassandraClientConfig) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool)

Aggregations

GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)222 Test (org.junit.Test)82 Jedis (redis.clients.jedis.Jedis)44 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)43 ShardedJedis (redis.clients.jedis.ShardedJedis)41 JedisPool (redis.clients.jedis.JedisPool)37 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)32 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)21 Bean (org.springframework.context.annotation.Bean)20 ArrayList (java.util.ArrayList)17 JedisShardInfo (redis.clients.jedis.JedisShardInfo)17 Test (org.junit.jupiter.api.Test)15 URI (java.net.URI)12 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)12 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)12 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)11 IOException (java.io.IOException)10 Test (org.testng.annotations.Test)10 PooledObject (org.apache.commons.pool2.PooledObject)9 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)9