Package xbird.util.datetime

Examples of xbird.util.datetime.StopWatch


                throw new IllegalStateException("create collection failed: " + colpath, e);
            }
            session.setContextCollection(col);
        }
        String[] cmdArgs = arguments.toArray(new String[arguments.size()]);
        StopWatch sw = new StopWatch();
        boolean success = false;
        try {
            success = executeCommand(cmdArgs);
        } catch (CommandException e) {
            LOG.error("command failed: " + Arrays.toString(cmdArgs), e);
View Full Code Here


        OperatingSystemMXBean mx = ManagementFactory.getOperatingSystemMXBean();
        final com.sun.management.OperatingSystemMXBean sunmx = (com.sun.management.OperatingSystemMXBean) mx;
        long startCpuTime = sunmx.getProcessCpuTime();

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

        final Segments pager = makeTempSegments(pageSize);
        final Status[] stats = new Status[threads];

        final boolean isGCLOCK = (algo == ReplacementAlgorithm.GClock);

        _start = _stop = false;
        final Thread[] thrs = new Thread[threads];
        for(int i = 0; i < threads; i++) {
            final Status stat = new Status();
            final int thrdnum = i;
            stats[i] = stat;
            thrs[i] = new Thread() {
                public void run() {
                    while(!_start) {
                        // Spin till Time To Go
                        try {
                            Thread.sleep(1);
                        } catch (Exception e) {
                        }
                    }
                    try {
                        if(lock == null) {
                            throw new IllegalStateException();
                        } else {
                            if(isGCLOCK) {
                                runBenchmarkWithZipfDistributionLockForGCLOCK(thrdnum, stat, lock, pager, cache, capacity, round, percent, scanLength, dist);
                            } else {
                                switch(algo) {
                                    case BpFullTwoQueue:
                                    case BpLRU:
                                        //runBenchmarkWithZipfDistributionLazySync(thrdnum, stat, lock, pager, cache, capacity, round, percent, scanLength, dist);
                                        runBenchmarkWithZipfDistributionLazySync2(thrdnum, stat, lock, pager, cache, capacity, round, percent, scanLength, dist);
                                        break;
                                    default:
                                        runBenchmarkWithZipfDistributionLock(thrdnum, stat, lock, pager, cache, capacity, round, percent, scanLength, dist);
                                        break;
                                }
                            }
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            };
        }
        PerfmonService perfmon = new PerfmonService(3000);
        if(enableStat) {
            perfmon.start();
        }
        // Run threads
        for(int i = 0; i < threads; i++) {
            thrs[i].start();
        }
        _start = true;
        try {
            Thread.sleep(TIME_TO_EST);
        } catch (InterruptedException e) {
        }
        _stop = true;
        for(int i = 0; i < threads; i++) {
            thrs[i].join();
        }
        if(enableStat) {
            perfmon.stop();
        }
        long elapsedCpuTime = sunmx.getProcessCpuTime() - startCpuTime;

        long numOps = 0L, cacheMisses = 0L, elapsed = 0L;
        int ioContention = 0;
        for(int i = 0; i < threads; i++) {
            numOps += stats[i].ops;
            cacheMisses += stats[i].miss;
            elapsed += stats[i].mills;
            ioContention += stats[i].iocontention;
        }
        long avgElapsedInSec = (elapsed / threads) / 1000L;
        long opsPerSec = numOps / avgElapsedInSec;

        long hit = numOps - cacheMisses;
        double hitRatio = ((double) hit) / numOps;
        double missRatio = ((double) cacheMisses) / numOps;
        System.err.println("["
                + algo
                + ((algo == ReplacementAlgorithm.NbGClock || algo == ReplacementAlgorithm.NbGClockK) ? ", counter type: "
                        + System.getProperty("xbird.counter", "striped")
                        : "")
                + " - "
                + filename
                + "] synchronization: "
                + (useRWlock ? "rwlock" : (lock == null ? "sync"
                        : ((lock instanceof NoopLock) ? "non-blocking"
                                : lock.getClass().getSimpleName()))) + ", read: " + numOps
                + ", miss: " + cacheMisses + ", hit ratio: " + hitRatio + ", miss ratio: "
                + missRatio + ", io contention: " + ioContention);
        System.err.println(watchdog.toString());
        System.err.println("number of ops: " + numOps + ", average number of ops per second: "
                + opsPerSec);
        System.err.println("Elapsed cpu time: " + DateTimeFormatter.formatNanoTime(elapsedCpuTime));
        System.err.flush();
View Full Code Here

            throws IOException, InterruptedException {
        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 double percent = scanPercentage / 100d;
        StopWatch watchdog = new StopWatch("nthreads: " + threads + ", capacity: " + capacity
                + ", scanPercentage: " + percent + ", scanLength: " + scanLength + ", pageSize: "
                + pageSize);

        final FixedSegments pager = makeTempSegments(pageSize);
        final Status[] stats = new Status[threads];

        final ReadWriteLock rwlock = new FairReadWriteLock();//new ReentrantReadWriteLock();

        _start = _stop = false;
        final Thread[] thrs = new Thread[threads];
        for(int i = 0; i < threads; i++) {
            final int threadId = i;
            final Status stat = new Status();
            stats[i] = stat;
            thrs[i] = new Thread() {
                public void run() {
                    while(!_start) {
                        // Spin till Time To Go
                        try {
                            Thread.sleep(1);
                        } catch (Exception e) {
                        }
                    }
                    try {
                        if(lock == null) {
                            if(useRWlock) {
                                runBenchmarkWithZipfDistributionReadWriteLock(rwlock, stat, pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                            } else {
                                runBenchmarkWithZipfDistributionSync(stat, pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                            }
                        } else {
                            runBenchmarkWithZipfDistributionLock(stat, lock, pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            };
        }
        // Run threads
        for(int i = 0; i < threads; i++) {
            thrs[i].start();
        }
        _start = true;
        try {
            Thread.sleep(TIME_TO_EST);
        } catch (InterruptedException e) {
        }
        _stop = true;
        for(int i = 0; i < threads; i++) {
            thrs[i].join();
        }

        long numOps = 0L, cacheMisses = 0L, elapsed = 0L, execInterval = 0L, durationHold = 0L;
        for(int i = 0; i < threads; i++) {
            numOps += stats[i].ops;
            cacheMisses += stats[i].miss;
            elapsed += stats[i].mills;
            execInterval += stats[i].execInterval;
            durationHold += stats[i].durationHold;
        }
        long avgElapsedInSec = (elapsed / threads) / 1000L;
        long opsPerSec = numOps / avgElapsedInSec;

        long hit = numOps - cacheMisses;
        double hitRatio = ((double) hit) / numOps;
        double missRatio = ((double) cacheMisses) / numOps;
        System.err.println("["
                + algo
                + " - "
                + filename
                + "] synchronization: "
                + (lock == null ? (useRWlock ? "readWrite" : "sync")
                        : ((lock instanceof NoopLock) ? "non-blocking" : "spinlock")) + ", read: "
                + numOps + ", miss: " + cacheMisses + ", hit ratio: " + hitRatio + ", miss ratio: "
                + missRatio);
        System.err.println(watchdog.toString());
        System.err.println("number of ops: " + numOps + ", average number of ops per second: "
                + opsPerSec + ", total execution interval(msec): " + execInterval
                + ", total duration hold(msec): " + durationHold);
        System.err.flush();
View Full Code Here

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

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

        final FixedSegments pager = makeTempSegments(pageSize);
        final Status[] stats = new Status[threads];

        _start = _stop = false;
        final Thread[] thrs = new Thread[threads];
        for(int i = 0; i < threads; i++) {
            final int threadId = i;
            final Status stat = new Status();
            stats[i] = stat;
            thrs[i] = new Thread() {
                public void run() {
                    while(!_start) {
                        // Spin till Time To Go
                        try {
                            Thread.sleep(1);
                        } catch (Exception e) {
                        }
                    }
                    try {
                        if(lock == null) {
                            runBenchmarkWithZipfDistributionLongHashSync(stat, pager, hash, capacity, round, percent, scanLength, dist[threadId]);
                        } else {
                            runBenchmarkWithZipfDistributionLongHashLock(stat, lock, pager, hash, capacity, round, percent, scanLength, dist[threadId]);
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            };
        }
        // Run threads
        for(int i = 0; i < threads; i++) {
            thrs[i].start();
        }
        _start = true;
        try {
            Thread.sleep(TIME_TO_EST);
        } catch (InterruptedException e) {
        }
        _stop = true;
        for(int i = 0; i < threads; i++) {
            thrs[i].join();
        }

        long numOps = 0L, cacheMisses = 0L, elapsed = 0L;
        for(int i = 0; i < threads; i++) {
            numOps += stats[i].ops;
            cacheMisses += stats[i].miss;
            elapsed += stats[i].mills;
        }
        long avgElapsedInSec = (elapsed / threads) / 1000;
        long opsPerSec = numOps / avgElapsedInSec;

        long hit = numOps - cacheMisses;
        double hitRatio = ((double) hit) / numOps;
        double missRatio = ((double) cacheMisses) / numOps;
        System.err.println("["
                + algo
                + " longhash - "
                + filename
                + "] synchronization: "
                + (lock == null ? "sync" : ((lock instanceof NoopLock) ? "non-blocking"
                        : "spinlock")) + ", read: " + numOps + ", miss: " + cacheMisses
                + ", hit ratio: " + hitRatio + ", miss ratio: " + missRatio);
        System.err.println(watchdog.toString());
        System.err.println("number of ops: " + numOps + ", average number of ops per second: "
                + opsPerSec);
        System.err.flush();

        pager.close();
View Full Code Here

        }
        throw new CommandException("Illegal argument: " + Arrays.toString(args));
    }

    protected void run(String[] args) {
        final StopWatch sw = new StopWatch();
        boolean success = false;
        try {
            String[] cmds = parseOptions(args);
            success = executeCommand(cmds);
        } catch (Throwable e) {
View Full Code Here

                        int nth = counter.getAndIncrement();
                        String testfilename = tests[nth];
                        String test = FileUtils.basename(testfilename) + "#" + nth;
                        //String[] args = new String[] { "-q", testfilename, "-o", OUTPUT_DEST + test };
                        String[] args = new String[] { "-q", testfilename, "-o", "/dev/null" };
                        StopWatch sw = new StopWatch("elapsed time of " + test);
                        try {
                            new InteractiveShell().run(args);
                        } catch (XQueryException e) {
                            Assert.fail("failed " + test, e);
                        }
View Full Code Here

        System.gc();
        int gcBefore = SystemUtils.countGC();
        long free = SystemUtils.getHeapFreeMemory();
        StringBuilder stdbuf = new StringBuilder(256);
        stdbuf.append(" - free(init): " + StringUtils.displayBytesSize(free));
        final StopWatch sw = new StopWatch("[Xbird] " + queryFile);
        queryFile = XMARK_HOME + '/' + queryFile;
        final XQueryProcessor processor = new XQueryProcessor();
        XQueryModule mod = processor.parse(new FileInputStream(queryFile), new File(queryFile).toURI());
        Sequence result = processor.execute(mod);
        StringWriter res_sw = new StringWriter();
        final Serializer ser = new SAXSerializer(new SAXWriter(res_sw), res_sw);
        ser.emit(result);
        String swresult = sw.toString();
        long used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(before GC): " + StringUtils.displayBytesSize(used));
        if(RUN_ONLY) {
            res_sw.close();
            res_sw = null;
View Full Code Here

        System.gc();
        int gcBefore = SystemUtils.countGC();
        long free = SystemUtils.getHeapFreeMemory();
        StringBuilder stdbuf = new StringBuilder(256);
        stdbuf.append(" - free(init): " + StringUtils.displayBytesSize(free));
        final StopWatch sw = new StopWatch("[Saxon] " + queryFile);
        queryFile = XMARK_HOME + '/' + queryFile;
        final Configuration config = new Configuration();
        config.setHostLanguage(Configuration.XQUERY);
        final StaticQueryContext staticContext = new StaticQueryContext(config);
        staticContext.setBaseURI(new File(queryFile).toURI().toString());
        XQueryExpression exp = staticContext.compileQuery(IOUtils.toString(new FileInputStream(queryFile)));
        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        StringWriter res_sw = new StringWriter();
        Properties props = new Properties();
        //props.setProperty(OutputKeys.METHOD, "text");
        props.setProperty(SaxonOutputKeys.WRAP, "no");
        props.setProperty(OutputKeys.INDENT, "no");
        props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        exp.run(dynamicContext, new StreamResult(res_sw), props);
        String swresult = sw.toString();
        long used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(before GC): " + StringUtils.displayBytesSize(used));
        if(RUN_ONLY) {
            res_sw.close();
            res_sw = null;
View Full Code Here

        System.gc();
        int gcBefore = SystemUtils.countGC();
        long free = SystemUtils.getHeapFreeMemory();
        StringBuilder stdbuf = new StringBuilder(256);
        stdbuf.append(" - free(init): " + StringUtils.displayBytesSize(free));
        final StopWatch sw = new StopWatch("[Xbird] " + queryFile);
        queryFile = XMARK_HOME + '/' + queryFile;

        XQEngine engine = new XQEngineClient("//" + bindHost + ":1099/xbird/srv-01");
        QueryRequest request1 = new QueryRequest(IOUtils.toString(new FileInputStream(queryFile)), ReturnType.REMOTE_SEQUENCE);
        request1.setBaseUri(new File(queryFile).toURI());
        Object result1 = engine.execute(request1);
        RemoteSequence remoteSequence = (RemoteSequence) result1;

        StringWriter res_sw = new StringWriter();
        Serializer ser = new SAXSerializer(new SAXWriter(res_sw), res_sw);
        ser.emit(remoteSequence);
        String swresult = sw.toString();
        long used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(before GC): " + StringUtils.displayBytesSize(used));
        System.gc();
        used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(after GC): " + StringUtils.displayBytesSize(used));
View Full Code Here

        System.gc();
        int gcBefore = SystemUtils.countGC();
        long free = SystemUtils.getHeapFreeMemory();
        StringBuilder stdbuf = new StringBuilder(256);
        stdbuf.append(" - free(init): " + StringUtils.displayBytesSize(free));
        StopWatch sw = new StopWatch("[Saxon] " + queryFile);
        queryFile = XMARK_HOME + '/' + queryFile;
        Configuration config = new Configuration();
        config.setHostLanguage(Configuration.XQUERY);
        StaticQueryContext staticContext = new StaticQueryContext(config);
        staticContext.setBaseURI(new File(queryFile).toURI().toString());
        XQueryExpression exp = staticContext.compileQuery(IOUtils.toString(new FileInputStream(queryFile)));
        DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        StringWriter res_sw = new StringWriter();
        Properties props = new Properties();
        //props.setProperty(OutputKeys.METHOD, "text");
        props.setProperty(SaxonOutputKeys.WRAP, "no");
        props.setProperty(OutputKeys.INDENT, "no");
        props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        exp.run(dynamicContext, new StreamResult(res_sw), props);
        String swresult = sw.toString();
        long used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(before GC): " + StringUtils.displayBytesSize(used));
        System.gc();
        used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(after GC): " + StringUtils.displayBytesSize(used));
View Full Code Here

TOP

Related Classes of xbird.util.datetime.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.