Package org.h2.util

Examples of org.h2.util.Profiler


       
        // to test with more nodes, use:
        // int count = 1000000;
        int count = 10;
       
        Profiler prof = null;
        String nodeType = "oak:Unstructured";
        if (session.getRootNode().hasNode("many")) {
            session.getRootNode().getNode("many").remove();
            session.save();
        }
        Node many = session.getRootNode().addNode("many", nodeType);
        for (int i = 0; i < count; i++) {
            Node n = many.addNode("test" + i, nodeType);
            n.setProperty("prop", i);
            if (i % 100 == 0) {
                session.save();
            }
            long now = System.currentTimeMillis();
            if (now - last > 5000) {
                int opsPerSecond = (int) (i * 1000 / (now - start));
                System.out.println(i + " ops; " + opsPerSecond + " op/s");
                last = now;
                if (prof != null) {
                    System.out.println(prof.getTop(5));
                }
                if (opsPerSecond < 1000 && i % 100 == 0) {
                    prof = new Profiler();
                    prof.startCollecting();
                }
            }
        }
       
        start = System.currentTimeMillis();
        last = start;

        for (int i = 0; i < count; i++) {
            Node n = many.getNode("test" + i);
            long x = n.getProperty("prop").getValue().getLong();
            assertEquals(i, x);
            long now = System.currentTimeMillis();
            if (now - last > 5000) {
                int opsPerSecond = (int) (i * 1000 / (now - start));
                System.out.println(i + " read ops; " + opsPerSecond + " op/s");
                last = now;
                if (prof != null) {
                    System.out.println(prof.getTop(5));
                }
                if (opsPerSecond < 1000 && i % 100 == 0) {
                    prof = new Profiler();
                    prof.startCollecting();
                }
            }
        }
    }
View Full Code Here


        session.put("user", user);
        boolean isH2 = url.startsWith("jdbc:h2:");
        try {
            long start = System.currentTimeMillis();
            String profOpen = "", profClose = "";
            Profiler prof = new Profiler();
            prof.startCollecting();
            Connection conn;
            try {
                conn = server.getConnection(driver, url, user, password);
            } finally {
                prof.stopCollecting();
                profOpen = prof.getTop(3);
            }
            prof = new Profiler();
            prof.startCollecting();
            try {
                JdbcUtils.closeSilently(conn);
            } finally {
                prof.stopCollecting();
                profClose = prof.getTop(3);
            }
            long time = System.currentTimeMillis() - start;
            String success;
            if (time > 1000) {
                success = "<a class=\"error\" href=\"#\" " +
View Full Code Here

                return StringUtils.convertBytesToHex(SHA256.getKeyPasswordHash(p[0], p[1].toCharArray()));
            } else if (isBuiltIn(sql, "@prof_start")) {
                if (profiler != null) {
                    profiler.stopCollecting();
                }
                profiler = new Profiler();
                profiler.startCollecting();
                return "Ok";
            } else if (isBuiltIn(sql, "@sleep")) {
                String s = sql.substring("@sleep".length()).trim();
                int sleep = 1;
View Full Code Here

       
        // to test with more nodes, use:
        // int count = 1000000;
        int count = 10;
       
        Profiler prof = null;
        String nodeType = "oak:unstructured";
        if (session.getRootNode().hasNode("many")) {
            session.getRootNode().getNode("many").remove();
            session.save();
        }
        Node many = session.getRootNode().addNode("many", nodeType);
        for (int i = 0; i < count; i++) {
            Node n = many.addNode("test" + i, nodeType);
            n.setProperty("prop", i);
            if (i % 100 == 0) {
                session.save();
            }
            long now = System.currentTimeMillis();
            if (now - last > 5000) {
                int opsPerSecond = (int) (i * 1000 / (now - start));
                System.out.println(i + " ops; " + opsPerSecond + " op/s");
                last = now;
                if (prof != null) {
                    System.out.println(prof.getTop(5));
                }
                if (opsPerSecond < 1000 && i % 100 == 0) {
                    prof = new Profiler();
                    prof.startCollecting();
                }
            }
        }
       
        start = System.currentTimeMillis();
        last = start;

        for (int i = 0; i < count; i++) {
            Node n = many.getNode("test" + i);
            long x = n.getProperty("prop").getValue().getLong();
            assertEquals(i, x);
            long now = System.currentTimeMillis();
            if (now - last > 5000) {
                int opsPerSecond = (int) (i * 1000 / (now - start));
                System.out.println(i + " read ops; " + opsPerSecond + " op/s");
                last = now;
                if (prof != null) {
                    System.out.println(prof.getTop(5));
                }
                if (opsPerSecond < 1000 && i % 100 == 0) {
                    prof = new Profiler();
                    prof.startCollecting();
                }
            }
        }
    }
View Full Code Here

    public static void run(String message, final Task task, int threadCount, int millis) throws Exception {
        final AtomicBoolean stopped = new AtomicBoolean();
        final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
        ArrayList<Thread> threads = new ArrayList<Thread>();
        final AtomicInteger counter = new AtomicInteger();
        Profiler p = new Profiler();
        if (PROFILE) {
            p.interval = 1;
            p.startCollecting();
        }
        for (int i = 0; i < threadCount; i++) {
            Thread t = new Thread("Task " + i) {
                public void run() {
                    while (!stopped.get()) {
                        try {
                            task.call();
                            counter.incrementAndGet();
                        } catch (Error e) {
                            exception.set(e);
                            stopped.set(true);
                        } catch (Exception e) {
                            exception.set(e);
                            stopped.set(true);
                        }
                    }
                }
            };
            if (threadCount == 1) {
                long stop = millis + System.currentTimeMillis();
                while (System.currentTimeMillis() < stop) {
                    task.call();
                    counter.incrementAndGet();
                }
                millis = 0;
            } else {
                t.start();
                threads.add(t);
            }
        }
        Throwable e = null;
        while (e == null && millis > 0) {
            Thread.sleep(10);
            millis -= 10;
            e = exception.get();
        }
        stopped.set(true);
        for (Thread t : threads) {
            t.join();
        }
        if (e != null) {
            if (e instanceof Exception) {
                throw (Exception) e;
            }
            throw (Error) e;
        }
        if (PROFILE) {
            System.out.println(p.getTop(5));
        }

    }
View Full Code Here

        session.put("user", user);
        boolean isH2 = url.startsWith("jdbc:h2:");
        try {
            long start = System.currentTimeMillis();
            String profOpen = "", profClose = "";
            Profiler prof = new Profiler();
            prof.startCollecting();
            Connection conn;
            try {
                conn = server.getConnection(driver, url, user, password);
            } finally {
                prof.stopCollecting();
                profOpen = prof.getTop(3);
            }
            prof = new Profiler();
            prof.startCollecting();
            try {
                JdbcUtils.closeSilently(conn);
            } finally {
                prof.stopCollecting();
                profClose = prof.getTop(3);
            }
            long time = System.currentTimeMillis() - start;
            String success;
            if (time > 1000) {
                success = "<a class=\"error\" href=\"#\" onclick=\"var x=document.getElementById('prof').style;x.display=x.display==''?'none':'';\">" +
View Full Code Here

                return StringUtils.convertBytesToString(sha.getKeyPasswordHash(p[0], p[1].toCharArray()));
            } else if (isBuiltIn(sql, "@prof_start")) {
                if (profiler != null) {
                    profiler.stopCollecting();
                }
                profiler = new Profiler();
                profiler.startCollecting();
                return "Ok";
            } else if (isBuiltIn(sql, "@sleep")) {
                String s = sql.substring("@sleep".length()).trim();
                int sleep = 1;
View Full Code Here

       
        // to test with more nodes, use:
        // int count = 1000000;
        int count = 10;
       
        Profiler prof = null;
        String nodeType = NodeTypeConstants.NT_OAK_UNSTRUCTURED;
        if (session.getRootNode().hasNode("many")) {
            session.getRootNode().getNode("many").remove();
            session.save();
        }
        Node many = session.getRootNode().addNode("many", nodeType);
        for (int i = 0; i < count; i++) {
            Node n = many.addNode("test" + i, nodeType);
            n.setProperty("prop", i);
            if (i % 100 == 0) {
                session.save();
            }
            long now = System.currentTimeMillis();
            if (now - last > 5000) {
                int opsPerSecond = (int) (i * 1000 / (now - start));
                System.out.println(i + " ops; " + opsPerSecond + " op/s");
                last = now;
                if (prof != null) {
                    System.out.println(prof.getTop(5));
                }
                if (opsPerSecond < 1000 && i % 100 == 0) {
                    prof = new Profiler();
                    prof.startCollecting();
                }
            }
        }
       
        start = System.currentTimeMillis();
        last = start;

        for (int i = 0; i < count; i++) {
            Node n = many.getNode("test" + i);
            long x = n.getProperty("prop").getValue().getLong();
            assertEquals(i, x);
            long now = System.currentTimeMillis();
            if (now - last > 5000) {
                int opsPerSecond = (int) (i * 1000 / (now - start));
                System.out.println(i + " read ops; " + opsPerSecond + " op/s");
                last = now;
                if (prof != null) {
                    System.out.println(prof.getTop(5));
                }
                if (opsPerSecond < 1000 && i % 100 == 0) {
                    prof = new Profiler();
                    prof.startCollecting();
                }
            }
        }
    }
View Full Code Here

        deleteDb("scriptSimple");
        reconnect();
        String inFile = "org/h2/test/testSimple.in.txt";
        InputStream is = getClass().getClassLoader().getResourceAsStream(inFile);
        LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(is, "Cp1252"));
        ScriptReader reader = new ScriptReader(lineReader);
        while (true) {
            String sql = reader.readStatement();
            if (sql == null) {
                break;
            }
            sql = sql.trim();
            try {
                if ("@reconnect".equals(sql.toLowerCase())) {
                    reconnect();
                } else if (sql.length() == 0) {
                    // ignore
                } else if (sql.toLowerCase().startsWith("select")) {
                    ResultSet rs = conn.createStatement().executeQuery(sql);
                    while (rs.next()) {
                        String expected = reader.readStatement().trim();
                        String got = "> " + rs.getString(1);
                        assertEquals(sql, expected, got);
                    }
                } else {
                    conn.createStatement().execute(sql);
View Full Code Here

        // but for Ubuntu, the default ulimit is 1024,
        // which breaks the test
        int len = getSize(10, 50);
        Task[] tasks = new Task[len];
        for (int i = 0; i < len; i++) {
            tasks[i] = new Task() {
                public void call() throws SQLException {
                    Connection c = DriverManager.getConnection(url, user, password);
                    PreparedStatement prep = c.prepareStatement("insert into employee values(?, ?, 0)");
                    int id = getNextId();
                    prep.setInt(1, id);
View Full Code Here

TOP

Related Classes of org.h2.util.Profiler

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.