Search in sources :

Example 1 with GenericKeyedObjectPool

use of org.apache.commons.pool.impl.GenericKeyedObjectPool in project jmxtrans by jmxtrans.

the class JmxTransModule method getObjectPool.

private <K, V> GenericKeyedObjectPool<K, V> getObjectPool(KeyedPoolableObjectFactory<K, V> factory, String poolName) {
    GenericKeyedObjectPool<K, V> pool = new GenericKeyedObjectPool<>(factory);
    pool.setTestOnBorrow(true);
    pool.setMaxActive(-1);
    pool.setMaxIdle(-1);
    pool.setTimeBetweenEvictionRunsMillis(MILLISECONDS.convert(5, MINUTES));
    pool.setMinEvictableIdleTimeMillis(MILLISECONDS.convert(5, MINUTES));
    try {
        ManagedGenericKeyedObjectPool mbean = new ManagedGenericKeyedObjectPool(pool, poolName);
        ManagementFactory.getPlatformMBeanServer().registerMBean(mbean, mbean.getObjectName());
    } catch (Exception e) {
        log.error("Could not register mbean for pool [{}]", poolName, e);
    }
    return pool;
}
Also used : ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) GenericKeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool) ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with GenericKeyedObjectPool

use of org.apache.commons.pool.impl.GenericKeyedObjectPool in project jmxtrans by jmxtrans.

the class JmxTransModule method getObjectPool.

private <K, V> GenericKeyedObjectPool<K, V> getObjectPool(KeyedPoolableObjectFactory<K, V> factory, String poolName, long maxWaitMillis) {
    GenericKeyedObjectPool<K, V> pool = new GenericKeyedObjectPool<>(factory);
    pool.setTestOnBorrow(true);
    pool.setMaxActive(-1);
    pool.setMaxIdle(-1);
    pool.setTimeBetweenEvictionRunsMillis(MILLISECONDS.convert(5, MINUTES));
    pool.setMinEvictableIdleTimeMillis(MILLISECONDS.convert(5, MINUTES));
    pool.setMaxWait(maxWaitMillis);
    pool.setTestOnReturn(true);
    pool.setTestOnBorrow(true);
    try {
        ManagedGenericKeyedObjectPool mbean = new ManagedGenericKeyedObjectPool(pool, poolName);
        ManagementFactory.getPlatformMBeanServer().registerMBean(mbean, mbean.getObjectName());
    } catch (Exception e) {
        log.error("Could not register mbean for pool [{}]", poolName, e);
    }
    return pool;
}
Also used : ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) GenericKeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool) ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 3 with GenericKeyedObjectPool

use of org.apache.commons.pool.impl.GenericKeyedObjectPool in project jmxtrans by jmxtrans.

the class StatsDWriter method start.

@Override
public void start() throws LifecycleException {
    try {
        pool = new GenericKeyedObjectPool<>(new DatagramSocketFactory());
        pool.setTestOnBorrow(true);
        pool.setMaxActive(-1);
        pool.setMaxIdle(-1);
        pool.setTimeBetweenEvictionRunsMillis(MILLISECONDS.convert(5, MINUTES));
        pool.setMinEvictableIdleTimeMillis(MILLISECONDS.convert(5, MINUTES));
        this.mbean = new ManagedGenericKeyedObjectPool((GenericKeyedObjectPool) pool, "StatsdConnectionPool");
        ManagementFactory.getPlatformMBeanServer().registerMBean(this.mbean, this.mbean.getObjectName());
    } catch (Exception e) {
        throw new LifecycleException(e);
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) GenericKeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool) DatagramSocketFactory(com.googlecode.jmxtrans.connections.DatagramSocketFactory) ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) ValidationException(com.googlecode.jmxtrans.model.ValidationException) IOException(java.io.IOException) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException)

Example 4 with GenericKeyedObjectPool

use of org.apache.commons.pool.impl.GenericKeyedObjectPool in project otter by alibaba.

the class CommunicationConnectionPoolFactory method initial.

public void initial() {
    if (factory == null) {
        throw new IllegalArgumentException("factory is null!");
    }
    // 创建链接池对象
    pool = new GenericKeyedObjectPool();
    pool.setMaxActive(maxActive);
    pool.setMaxIdle(maxActive);
    pool.setMinIdle(0);
    // 60s
    pool.setMaxWait(60 * 1000);
    pool.setTestOnBorrow(false);
    pool.setTestOnReturn(false);
    pool.setTimeBetweenEvictionRunsMillis(10 * 1000);
    pool.setNumTestsPerEvictionRun(maxActive * 2);
    pool.setMinEvictableIdleTimeMillis(30 * 60 * 1000);
    pool.setTestWhileIdle(true);
    // 设置连接池管理对象
    pool.setFactory(new CommunicationConnectionPoolableFactory(factory));
}
Also used : GenericKeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool)

Example 5 with GenericKeyedObjectPool

use of org.apache.commons.pool.impl.GenericKeyedObjectPool in project voldemort by voldemort.

the class ResourcePoolPerfTest method main.

public static void main(String[] args) throws Exception {
    final int numKeys = 10;
    final int numThreads = 10;
    final int numRequests = 10000000;
    NumberFormat format = NumberFormat.getInstance();
    format.setMaximumFractionDigits(2);
    for (int poolSize : new int[] { 1, 5, 10 }) {
        System.out.println("Perf test for voldemort pool with numThreads = " + numThreads + ", poolSize = " + poolSize + ":");
        final KeyedResourcePool<Integer, String> pool = KeyedResourcePool.create(new StringResourceFactory(), new ResourcePoolConfig().setMaxPoolSize(poolSize).setIsFair(true));
        PerformanceTest test = new PerformanceTest() {

            @Override
            public void doOperation(int id) throws Exception {
                Integer key = id % numKeys;
                String s = pool.checkout(key);
                pool.checkin(key, s);
            }
        };
        test.run(numRequests, numThreads);
        test.printStats();
        System.out.println();
    }
    System.out.println("--------------------------------------");
    System.out.println();
    for (int poolSize : new int[] { 1, 5, 10 }) {
        System.out.println("Perf test for commons pool with numThreads = " + numThreads + ", poolSize = " + poolSize + ":");
        GenericKeyedObjectPool.Config config = new GenericKeyedObjectPool.Config();
        config.maxActive = poolSize;
        config.testOnBorrow = true;
        config.whenExhaustedAction = GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK;
        config.maxWait = 10000;
        StringPoolableObjectFactory objFactory = new StringPoolableObjectFactory();
        final KeyedObjectPool pool = new GenericKeyedObjectPool(objFactory, config);
        PerformanceTest test = new PerformanceTest() {

            @Override
            public void doOperation(int id) throws Exception {
                Integer key = id % numKeys;
                String s = (String) pool.borrowObject(key);
                pool.returnObject(key, s);
            }
        };
        test.run(numRequests, numThreads);
        test.printStats();
        System.out.println();
    }
}
Also used : GenericKeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig) KeyedObjectPool(org.apache.commons.pool.KeyedObjectPool) GenericKeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool) NumberFormat(java.text.NumberFormat) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig)

Aggregations

GenericKeyedObjectPool (org.apache.commons.pool.impl.GenericKeyedObjectPool)5 ManagedGenericKeyedObjectPool (com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool)3 IOException (java.io.IOException)2 DatagramSocketFactory (com.googlecode.jmxtrans.connections.DatagramSocketFactory)1 LifecycleException (com.googlecode.jmxtrans.exceptions.LifecycleException)1 ValidationException (com.googlecode.jmxtrans.model.ValidationException)1 FileNotFoundException (java.io.FileNotFoundException)1 NumberFormat (java.text.NumberFormat)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 KeyedObjectPool (org.apache.commons.pool.KeyedObjectPool)1 SchedulerException (org.quartz.SchedulerException)1 ResourcePoolConfig (voldemort.utils.pool.ResourcePoolConfig)1