Package org.menagerie.util

Examples of org.menagerie.util.TimingAccumulator


        */

        final UnsafeOperator operator = new UnsafeOperator();
        final CyclicBarrier startLatch = new CyclicBarrier(concurrency+1);
        final CyclicBarrier endLatch = new CyclicBarrier(concurrency+1);
        final TimingAccumulator timer = new TimingAccumulator();
        for(int i=0;i<concurrency;i++){
            testService.submit(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    try {
                        startLatch.await();
                    } catch (InterruptedException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    } catch (BrokenBarrierException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    }
                    ZooKeeper zk = newZooKeeper();
                    try{
                        ZkSessionManager zksm = new BaseZkSessionManager(zk);
                        Lock guard = new ReentrantZkLock2(baseLockPath,zksm);
                        long totalStart = System.currentTimeMillis();
                        for(int i=0;i<MAX_LOCK_ATTEMPTS;i++){
                            timer.addTiming(guardedWork(guard,operator));
                        }
                        long totalEnd = System.currentTimeMillis();
                        long totalTime = totalEnd-totalStart;
                        float totalTimeSec = totalTime/1000f;
                        int ops = MAX_LOCK_ATTEMPTS;
                        float opsPerSec = ops/totalTimeSec;
                        System.out.printf("%d - total time taken: %d ms \t total Operations performed: %d \t Ops/sec: %f%n",Thread.currentThread().getId(),totalTime,ops,opsPerSec);
                    }finally{
                        zk.close();
                    }

                    //enter the stop latch
                    try {
                        endLatch.await();
                    } catch (InterruptedException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    } catch (BrokenBarrierException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    }
                    return null;
                }
            });
        }

        //start the test
        startLatch.await();

        //enter the end latch to wait on things finishing
        endLatch.await();

        int numberOfOperations = MAX_LOCK_ATTEMPTS*concurrency;
        assertEquals("Incorrect incrementing!",numberOfOperations,operator.getValue());
        timer.printResults();

    }
View Full Code Here


         at the end checking that our total is what it should be
        */
        final UnsafeOperator operator = new UnsafeOperator();
        final CyclicBarrier startLatch = new CyclicBarrier(concurrency+1);
        final CyclicBarrier endLatch = new CyclicBarrier(concurrency+1);
        final TimingAccumulator timer = new TimingAccumulator();
        for(int i=0;i<concurrency;i++){
            testService.submit(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    try {
                        startLatch.await();
                    } catch (InterruptedException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    } catch (BrokenBarrierException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    }
                    Lock guard = new ReentrantZkLock2(baseLockPath,zkSessionManager);
                    long totalStart = System.currentTimeMillis();
                    for(int i=0;i<MAX_LOCK_ATTEMPTS;i++){
                        timer.addTiming(guardedWork(guard,operator));
                    }
                    long totalEnd = System.currentTimeMillis();
                    long totalTime = totalEnd-totalStart;
                    float totalTimeSec = totalTime/1000f;
                    float opsPerSec = MAX_LOCK_ATTEMPTS/totalTimeSec;
                    System.out.printf("%d - total time taken: %d ms \t total Operations performed: %d \t Ops/sec: %f%n",Thread.currentThread().getId(),totalTime,MAX_LOCK_ATTEMPTS,opsPerSec);


                    //enter the stop latch
                    try {
                        endLatch.await();
                    } catch (InterruptedException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    } catch (BrokenBarrierException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    }
                    return null;
                }
            });
        }

        //start the test
        startLatch.await();

        //enter the end latch to wait on things finishing
        endLatch.await();

        int numberOfOperations = MAX_LOCK_ATTEMPTS*concurrency;
        assertEquals("Incorrect incrementing!",numberOfOperations,operator.getValue());
        timer.printResults();

    }
View Full Code Here

        final UnsafeOperator operator = new UnsafeOperator();
        final CyclicBarrier startLatch = new CyclicBarrier(concurrency+1);
        final CyclicBarrier endLatch = new CyclicBarrier(concurrency+1);
        final Lock guard = new ReentrantZkLock2(baseLockPath,zkSessionManager);
        final TimingAccumulator timer = new TimingAccumulator();
        for(int i=0;i<concurrency;i++){
            testService.submit(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    //enter the start latch
                    try {
                        startLatch.await();
                    } catch (InterruptedException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    } catch (BrokenBarrierException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    }

                    long totalStart = System.currentTimeMillis();
                    for(int i=0;i<MAX_LOCK_ATTEMPTS;i++){
                        timer.addTiming(guardedWork(guard,operator));
                    }
                    long totalEnd = System.currentTimeMillis();

                    long totalTime = totalEnd-totalStart;
                    float totalTimeSec = totalTime/1000f;
                    float opsPerSec = MAX_LOCK_ATTEMPTS/totalTimeSec;
                    System.out.printf("%d - total time taken: %d ms \t total Operations performed: %d \t Ops/sec: %f%n",Thread.currentThread().getId(),totalTime,MAX_LOCK_ATTEMPTS,opsPerSec);


                    //enter the stop latch
                    try {
                        endLatch.await();
                    } catch (InterruptedException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    } catch (BrokenBarrierException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    }
                    return null;
                }
            });
        }

        //start the test
        startLatch.await();

        //enter the end latch to wait on things finishing
        endLatch.await();

        int numberOfOperations = MAX_LOCK_ATTEMPTS*concurrency;
        assertEquals("Incorrect incrementing!",numberOfOperations,operator.getValue());
        timer.printResults();
    }
View Full Code Here

TOP

Related Classes of org.menagerie.util.TimingAccumulator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.