Search in sources :

Example 1 with ResourcePoolConfig

use of voldemort.utils.pool.ResourcePoolConfig in project voldemort by voldemort.

the class SimpleSocketPoolTest method testClientRequestExecutorLimitSomeTimeout.

@Test
public void testClientRequestExecutorLimitSomeTimeout() throws Exception {
    // start a dummy server
    AbstractSocketService server = ServerTestUtils.getSocketService(useNio, new ClientRequestHandlerFactory(null), 7666, 50, 50, 1000);
    server.start();
    final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50, TimeUnit.MILLISECONDS).setMaxPoolSize(20);
    ClientRequestExecutorPool clientRequestExecutorPool = new ClientRequestExecutorPool(config.getMaxPoolSize(), (int) config.getTimeout(TimeUnit.MILLISECONDS), 100, 1000);
    try {
        ResourceFactory<SocketDestination, ClientRequestExecutor> factory = clientRequestExecutorPool.getFactory();
        final AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor> test = new AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor>() {

            @Override
            protected void doSomethingWithResource(SocketDestination key, ClientRequestExecutor resource) throws Exception {
                Thread.sleep(100);
                int random = (int) (Math.random() * 10);
                if (random >= 5)
                    resource.close();
            }

            @Override
            protected SocketDestination getRequestKey() throws Exception {
                return new SocketDestination("localhost", 7666, RequestFormatType.VOLDEMORT_V1);
            }
        };
        // borrow timeout >> doSomething() no timeout expected
        TestStats testStats = test.startTest(factory, config, 50, 200);
        assertEquals("We should see some timeoutRequests", true, testStats.timeoutRequests > 0);
        server.stop();
    } finally {
        clientRequestExecutorPool.close();
    }
}
Also used : SocketDestination(voldemort.store.socket.SocketDestination) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) ClientRequestHandlerFactory(voldemort.server.protocol.ClientRequestHandlerFactory) ClientRequestExecutor(voldemort.store.socket.clientrequest.ClientRequestExecutor) AbstractSocketService(voldemort.server.AbstractSocketService) TestStats(voldemort.socketpool.AbstractSocketPoolTest.TestStats) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig) Test(org.junit.Test)

Example 2 with ResourcePoolConfig

use of voldemort.utils.pool.ResourcePoolConfig 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)

Example 3 with ResourcePoolConfig

use of voldemort.utils.pool.ResourcePoolConfig in project voldemort by voldemort.

the class SimpleSocketPoolTest method testPoolLimitNoTimeout.

@Test
public void testPoolLimitNoTimeout() throws Exception {
    final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(1000, TimeUnit.MILLISECONDS).setMaxPoolSize(20);
    ResourceFactory<String, String> factory = ResourcePoolTestUtils.getBasicPoolFactory();
    final AbstractSocketPoolTest<String, String> test = new AbstractSocketPoolTest<String, String>() {

        @Override
        protected void doSomethingWithResource(String key, String resource) throws Exception {
            Thread.sleep(100);
        }

        @Override
        protected String getRequestKey() throws Exception {
            return "test-key";
        }
    };
    // borrow timeout >> doSomething() no timeout expected
    TestStats testStats = test.startTest(factory, config, 50, 200);
    assertEquals("We should see Zero timeoutRequests", 0, testStats.timeoutRequests);
}
Also used : TestStats(voldemort.socketpool.AbstractSocketPoolTest.TestStats) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig) Test(org.junit.Test)

Example 4 with ResourcePoolConfig

use of voldemort.utils.pool.ResourcePoolConfig in project voldemort by voldemort.

the class SimpleSocketPoolTest method testPoolLimitSomeTimeout.

@Test
public void testPoolLimitSomeTimeout() throws Exception {
    final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50, TimeUnit.MILLISECONDS).setMaxPoolSize(20);
    ResourceFactory<String, String> factory = ResourcePoolTestUtils.getBasicPoolFactory();
    final AbstractSocketPoolTest<String, String> test = new AbstractSocketPoolTest<String, String>() {

        @Override
        protected void doSomethingWithResource(String key, String resource) throws Exception {
            Thread.sleep(100);
        }

        @Override
        protected String getRequestKey() throws Exception {
            return "test-key";
        }
    };
    // borrow timeout >> doSomething() no timeout expected
    TestStats testStats = test.startTest(factory, config, 50, 200);
    assertEquals("We should see some timeoutRequests", true, testStats.timeoutRequests > 0);
}
Also used : TestStats(voldemort.socketpool.AbstractSocketPoolTest.TestStats) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig) Test(org.junit.Test)

Example 5 with ResourcePoolConfig

use of voldemort.utils.pool.ResourcePoolConfig in project voldemort by voldemort.

the class SimpleSocketPoolTest method testSocketPoolLimitSomeTimeout.

@Test
public void testSocketPoolLimitSomeTimeout() throws Exception {
    // start a dummy server
    AbstractSocketService server = ServerTestUtils.getSocketService(useNio, new ClientRequestHandlerFactory(null), 7666, 50, 50, 1000);
    server.start();
    final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50, TimeUnit.MILLISECONDS).setMaxPoolSize(20);
    ResourceFactory<SocketDestination, SocketAndStreams> factory = ResourcePoolTestUtils.getSocketPoolFactory();
    final AbstractSocketPoolTest<SocketDestination, SocketAndStreams> test = new AbstractSocketPoolTest<SocketDestination, SocketAndStreams>() {

        @Override
        protected void doSomethingWithResource(SocketDestination key, SocketAndStreams resource) throws Exception {
            Thread.sleep(100);
            int random = (int) (Math.random() * 10);
            if (random >= 5)
                resource.getSocket().close();
        }

        @Override
        protected SocketDestination getRequestKey() throws Exception {
            return new SocketDestination("localhost", 7666, RequestFormatType.VOLDEMORT_V1);
        }
    };
    // borrow timeout >> doSomething() no timeout expected
    TestStats testStats = test.startTest(factory, config, 50, 200);
    assertEquals("We should see some timeoutRequests", true, testStats.timeoutRequests > 0);
    server.stop();
}
Also used : SocketAndStreams(voldemort.client.protocol.admin.SocketAndStreams) SocketDestination(voldemort.store.socket.SocketDestination) ClientRequestHandlerFactory(voldemort.server.protocol.ClientRequestHandlerFactory) AbstractSocketService(voldemort.server.AbstractSocketService) TestStats(voldemort.socketpool.AbstractSocketPoolTest.TestStats) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig) Test(org.junit.Test)

Aggregations

ResourcePoolConfig (voldemort.utils.pool.ResourcePoolConfig)6 Test (org.junit.Test)5 TestStats (voldemort.socketpool.AbstractSocketPoolTest.TestStats)5 AbstractSocketService (voldemort.server.AbstractSocketService)2 ClientRequestHandlerFactory (voldemort.server.protocol.ClientRequestHandlerFactory)2 SocketDestination (voldemort.store.socket.SocketDestination)2 NumberFormat (java.text.NumberFormat)1 KeyedObjectPool (org.apache.commons.pool.KeyedObjectPool)1 GenericKeyedObjectPool (org.apache.commons.pool.impl.GenericKeyedObjectPool)1 SocketAndStreams (voldemort.client.protocol.admin.SocketAndStreams)1 ClientRequestExecutor (voldemort.store.socket.clientrequest.ClientRequestExecutor)1 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)1