Package xbird.util

Examples of xbird.util.StopWatch


    private static void runBenchmarkWithZipfDistribution(int capacity, int round, double skew, long[] data, ReplacementAlgorithm algo) {
        ConcurrentPluggableCache<Long, Long> cache = new ConcurrentPluggableCache<Long, Long>(capacity);
        cache.setReplacementPolicy(ReplacementPolicySelector.<Long, Long> provide(capacity, algo));

        StopWatch watchdog = new StopWatch("capacity: " + capacity + ", round: " + round);
        for(int i = 0; i < round; i++) {
            long key = data[i];
            ICacheEntry<Long, Long> entry = cache.allocateEntry(key);
            entry.setValue(key);
            entry.unpin();
        }
        long miss = cache.getCacheMiss();
        double ratio = ((double) miss) / round;
        System.err.println("[Zipf (" + skew + ") - " + algo + "] read: " + round + ", miss: "
                + miss + ", miss ratio: " + ratio);
        System.err.println(watchdog.toString());
    }
View Full Code Here


    private static void runBenchmarkWithRandomDistribution(int capacity, int round, ReplacementAlgorithm algo) {
        ConcurrentPluggableCache<Long, Long> cache = new ConcurrentPluggableCache<Long, Long>(capacity);
        cache.setReplacementPolicy(ReplacementPolicySelector.<Long, Long> provide(capacity, algo));
        Random rand = new Random(76675734342L);
        StopWatch watchdog = new StopWatch("capacity: " + capacity + ", round: " + round);
        for(int i = 0; i < round; i++) {
            long key = Math.abs(rand.nextLong()) % round;
            ICacheEntry<Long, Long> entry = cache.allocateEntry(key);
            entry.setValue(key);
            entry.unpin();
        }
        System.err.println(watchdog.toString());
        long miss = cache.getCacheMiss();
        double ratio = ((double) miss) / round;
        System.err.println("[Random - " + algo + "] read: " + round + ", miss: " + miss
                + ", miss ratio: " + ratio);
    }
View Full Code Here

        boolean scanning = false;
        long scanCount = 0L;

        int scanned = 0, zipf = 0;

        StopWatch watchdog = new StopWatch("capacity: " + capacity + ", round: " + round
                + ", scanPercentage: " + percent + ", scanLength: " + scanLength);
        for(int nth = 0; nth < round; nth++) {
            final long key;
            if(scanning || scanLength != 0 && (nth % scanLength == 0 && Math.random() < percent)) {
                if(++scanCount <= scanLength) {
                    key = scanCount;
                    scanning = true;
                    scanned++;
                } else {
                    key = readNextLong(reader);
                    scanCount = 0;
                    scanning = false;
                    zipf++;
                }
            } else {
                key = readNextLong(reader);
                zipf++;
            }
            ICacheEntry<Long, Long> entry = cache.allocateEntry(key);
            entry.setValue(key);
            entry.unpin();
        }
        long miss = cache.getCacheMiss();
        long hit = round - miss;
        double hitRatio = ((double) hit) / round;
        double missRatio = ((double) miss) / round;
        System.err.println("[" + algo + " - " + filename + "] read: " + round + ", miss: " + miss
                + ", hit ratio: " + hitRatio + ", miss ratio: " + missRatio);
        System.err.println(watchdog.toString());
        System.err.println("scanned: " + scanned + ", zipf: " + zipf);
        System.err.flush();
    }
View Full Code Here

        final ConcurrentPluggableCache<Long, byte[]> cache = new ConcurrentPluggableCache<Long, byte[]>(capacity, ConcurrentCollectionProvider.<ICacheEntry<Long, byte[]>> createConcurrentMapLong(capacity));
        cache.setReplacementPolicy(ReplacementPolicySelector.<Long, byte[]> provide(capacity, algo));

        final int total = round * threads;
        final double percent = scanPercentage / 100d;
        StopWatch watchdog = new StopWatch("nthreads: " + threads + ", capacity: " + capacity
                + ", invocations: " + total + ", scanPercentage: " + percent + ", scanLength: "
                + scanLength + ", pageSize: " + pageSize);

        final FixedSegments pager = makeTempSegments(pageSize);

        final ExecutorService exec = Executors.newFixedThreadPool(threads);
        try {
            for(int i = 0; i < threads; i++) {
                final int threadId = i;
                exec.submit(new Runnable() {
                    public void run() {
                        try {
                            if(lock == null) {
                                runBenchmarkWithZipfDistributionSync(pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                            } else {
                                runBenchmarkWithZipfDistributionLock(lock, pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        } finally {
            exec.shutdown();
            try {
                exec.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                ;
            }
        }

        long miss = cache.getCacheMiss();
        long hit = total - miss;
        double hitRatio = ((double) hit) / total;
        double missRatio = ((double) miss) / total;
        System.err.println("["
                + algo
                + " - "
                + filename
                + "] synchronization: "
                + (lock == null ? "sync" : ((lock instanceof NoopLock) ? "non-blocking"
                        : "spinlock")) + ", read: " + total + ", miss: " + miss + ", hit ratio: "
                + hitRatio + ", miss ratio: " + missRatio);
        System.err.println(watchdog.toString());
        System.err.flush();

        pager.close();
    }
View Full Code Here

                throw new IllegalStateException("unexpected algorithm for here: " + algo);
        }

        final int total = round * threads;
        final double percent = scanPercentage / 100d;
        StopWatch watchdog = new StopWatch("nthreads: " + threads + ", capacity: " + capacity
                + ", invocations: " + total + ", scanPercentage: " + percent + ", scanLength: "
                + scanLength + ", pageSize: " + pageSize);

        final FixedSegments pager = makeTempSegments(pageSize);

        final ExecutorService exec = Executors.newFixedThreadPool(threads);
        try {
            for(int i = 0; i < threads; i++) {
                final int threadId = i;
                exec.submit(new Runnable() {
                    public void run() {
                        try {
                            if(lock == null) {
                                runBenchmarkWithZipfDistributionLongHashSync(pager, hash, capacity, round, percent, scanLength, dist[threadId]);
                            } else {
                                runBenchmarkWithZipfDistributionLongHashLock(lock, pager, hash, capacity, round, percent, scanLength, dist[threadId]);
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        } finally {
            exec.shutdown();
            try {
                exec.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                ;
            }
        }

        long miss = hash.getCacheMiss();
        long hit = total - miss;
        double hitRatio = ((double) hit) / total;
        double missRatio = ((double) miss) / total;
        System.err.println("["
                + algo
                + " longhash - "
                + filename
                + "] synchronization: "
                + (lock == null ? "sync" : ((lock instanceof NoopLock) ? "non-blocking"
                        : "spinlock")) + ", read: " + total + ", miss: " + miss + ", hit ratio: "
                + hitRatio + ", miss ratio: " + missRatio);
        System.err.println(watchdog.toString());
        System.err.flush();

        pager.close();
    }
View Full Code Here

        final ConcurrentPluggableCache<Long, byte[]> cache = new ConcurrentPluggableCache<Long, byte[]>(capacity);
        cache.setReplacementPolicy(ReplacementPolicySelector.<Long, byte[]> provide(capacity, algo));

        final int total = round * threads;
        final double percent = scanPercentage / 100d;
        StopWatch watchdog = new StopWatch("nthreads: " + threads + ", capacity: " + capacity
                + ", invocations: " + total + ", scanPercentage: " + percent + ", scanLength: "
                + scanLength);

        final FixedSegments pager = makeTempSegments(pageSize);

        final ExecutorService exec = Executors.newFixedThreadPool(threads);
        try {
            for(int i = 0; i < threads; i++) {
                exec.submit(new Runnable() {
                    public void run() {
                        try {
                            if(lock == null) {
                                runBenchmarkWithZipfDistributionSync(pager, cache, capacity, round, percent, scanLength, reader);
                            } else {
                                runBenchmarkWithZipfDistributionLock(lock, pager, cache, capacity, round, percent, scanLength, reader);
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        } finally {
            exec.shutdown();
            try {
                exec.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                ;
            }
        }

        long miss = cache.getCacheMiss();
        long hit = total - miss;
        double hitRatio = ((double) hit) / total;
        double missRatio = ((double) miss) / total;
        System.err.println("["
                + algo
                + " - "
                + filename
                + "] synchronization: "
                + (lock == null ? "sync" : ((lock instanceof NoopLock) ? "non-blocking"
                        : "spinlock")) + ", read: " + total + ", miss: " + miss + ", hit ratio: "
                + hitRatio + ", miss ratio: " + missRatio);
        System.err.println(watchdog.toString());
        System.err.flush();

        pager.close();
    }
View Full Code Here

                throw new IllegalStateException("unexpected algorithm for here: " + algo);
        }

        final int total = round * threads;
        final double percent = scanPercentage / 100d;
        StopWatch watchdog = new StopWatch("nthreads: " + threads + ", capacity: " + capacity
                + ", invocations: " + total + ", scanPercentage: " + percent + ", scanLength: "
                + scanLength);

        final FixedSegments pager = makeTempSegments(pageSize);

        final ExecutorService exec = Executors.newFixedThreadPool(threads);
        try {
            for(int i = 0; i < threads; i++) {
                exec.submit(new Runnable() {
                    public void run() {
                        try {
                            if(lock == null) {
                                runBenchmarkWithZipfDistributionLongHashSync(pager, hash, capacity, round, percent, scanLength, reader);
                            } else {
                                runBenchmarkWithZipfDistributionLongHashLock(lock, pager, hash, capacity, round, percent, scanLength, reader);
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        } finally {
            exec.shutdown();
            try {
                exec.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                ;
            }
        }

        long miss = hash.getCacheMiss();
        long hit = total - miss;
        double hitRatio = ((double) hit) / total;
        double missRatio = ((double) miss) / total;
        System.err.println("["
                + algo
                + " longhash - "
                + filename
                + "] synchronization: "
                + (lock == null ? "sync" : ((lock instanceof NoopLock) ? "non-blocking"
                        : "spinlock")) + ", read: " + total + ", miss: " + miss + ", hit ratio: "
                + hitRatio + ", miss ratio: " + missRatio);
        System.err.println(watchdog.toString());
        System.err.flush();

        pager.close();
    }
View Full Code Here

                out.writeBoolean(true);
                RemoteSequence remote = (RemoteSequence) result;
                remote.writeExternal(out);
            } else {
                out.writeBoolean(false);
                final StopWatch sw = new StopWatch("Elapsed time for encoding `$" + getName()
                        + '\'');
                final XQEventEncoder encoder = new XQEventEncoder(out);
                try {
                    encoder.emit(result);
                } catch (XQueryException xqe) {
View Full Code Here

        if(hasResult) {
            final boolean isRemoteSeq = in.readBoolean();
            if(isRemoteSeq) {
                this._result = RemoteSequence.readFrom(in);
            } else {
                final StopWatch sw = new StopWatch("Elapsed time for decoding `$" + getName()
                        + '\'');
                final XQEventDecoder decoder = new XQEventDecoder(in);
                try {
                    this._result = decoder.decode();
                } catch (XQueryException xqe) {
View Full Code Here

        System.gc();

        String queryStr = IOUtils.toString(new FileInputStream(queryFilePath));
        queryStr = queryStr.replace("fn:doc(\"auction.xml\")", "fn:doc('" + TARGET_FILE + "')");

        final StopWatch sw = new StopWatch("[Xbird_file] " + queryFilePath);
        final XQueryProcessor processor = new XQueryProcessor();
        // parse
        XQueryModule mod = processor.parse(queryStr, new File(queryFilePath).toURI());
        // execute              
        FastMultiByteArrayOutputStream out = new FastMultiByteArrayOutputStream();
View Full Code Here

TOP

Related Classes of xbird.util.StopWatch

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.