⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdbcbench.java

📁 一个用java写的开源的数据库系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* Copyright (c) 2001-2002, The HSQL Development Group * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the HSQL Development Group nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */package org.hsqldb.test;// nbazin@users - enhancements to the original code/* *  This is a sample implementation of the Transaction Processing Performance *  Council Benchmark B coded in Java and ANSI SQL2. * *  This version is using one connection per thread to parallellize *  server operations. * @author Mark Matthews (mark@mysql.com) */import java.sql.*;import java.util.*;import java.io.*;class JDBCBench {    /* tpc bm b scaling rules */    public static int tps       = 1;         /* the tps scaling factor: here it is 1 */    public static int nbranches = 1;         /* number of branches in 1 tps db       */    public static int ntellers  = 10;        /* number of tellers in  1 tps db       */    public static int naccounts = 100000;    /* number of accounts in 1 tps db       */    public static int nhistory = 864000;     /* number of history recs in 1 tps db   */    public final static int TELLER              = 0;    public final static int BRANCH              = 1;    public final static int ACCOUNT             = 2;    int                     failed_transactions = 0;    int                     transaction_count   = 0;    static int              n_clients           = 10;    static int              n_txn_per_client    = 10;    long                    start_time          = 0;    static boolean          transactions        = true;    static boolean          prepared_stmt       = false;    static String           tableExtension      = "";    static String           createExtension     = "";    static String           ShutdownCommand     = "";    static PrintStream      TabFile             = null;    static boolean          verbose             = false;    MemoryWatcherThread     MemoryWatcher;    /* main program,    creates a 1-tps database:  i.e. 1 branch, 10 tellers,...     *                    runs one TPC BM B transaction     * example command line:     * -driver  org.hsqldb.jdbcDriver -url jdbc:hsqldb:/hsql/test33 -user sa -clients 20     */    public static void main(String[] Args) {        String  DriverName         = "";        String  DBUrl              = "";        String  DBUser             = "";        String  DBPassword         = "";        boolean initialize_dataset = false;        for (int i = 0; i < Args.length; i++) {            if (Args[i].equals("-clients")) {                if (i + 1 < Args.length) {                    i++;                    n_clients = Integer.parseInt(Args[i]);                }            } else if (Args[i].equals("-driver")) {                if (i + 1 < Args.length) {                    i++;                    DriverName = Args[i];                    if (DriverName.equals(                            "org.enhydra.instantdb.jdbc.idbDriver")) {                        ShutdownCommand = "SHUTDOWN";                    }                    if (DriverName.equals(                            "com.borland.datastore.jdbc.DataStoreDriver")) {}                    if (DriverName.equals("com.mckoi.JDBCDriver")) {                        ShutdownCommand = "SHUTDOWN";                    }                    if (DriverName.equals("org.hsqldb.jdbcDriver")) {                        tableExtension  = "CREATE CACHED TABLE ";                        ShutdownCommand = "SHUTDOWN COMPACT";                    }                }            } else if (Args[i].equals("-url")) {                if (i + 1 < Args.length) {                    i++;                    DBUrl = Args[i];                }            } else if (Args[i].equals("-user")) {                if (i + 1 < Args.length) {                    i++;                    DBUser = Args[i];                }            } else if (Args[i].equals("-tabfile")) {                if (i + 1 < Args.length) {                    i++;                    try {                        FileOutputStream File = new FileOutputStream(Args[i]);                        TabFile = new PrintStream(File);                    } catch (Exception e) {                        TabFile = null;                    }                }            } else if (Args[i].equals("-password")) {                if (i + 1 < Args.length) {                    i++;                    DBPassword = Args[i];                }            } else if (Args[i].equals("-tpc")) {                if (i + 1 < Args.length) {                    i++;                    n_txn_per_client = Integer.parseInt(Args[i]);                }            } else if (Args[i].equals("-init")) {                initialize_dataset = true;            } else if (Args[i].equals("-tps")) {                if (i + 1 < Args.length) {                    i++;                    tps = Integer.parseInt(Args[i]);                }            } else if (Args[i].equals("-v")) {                verbose = true;            }        }        if (DriverName.length() == 0 || DBUrl.length() == 0) {            System.out.println(                "usage: java JDBCBench -driver [driver_class_name] -url [url_to_db] -user [username] -password [password] [-v] [-init] [-tpc n] [-clients]");            System.out.println();            System.out.println("-v          verbose error messages");            System.out.println("-init       initialize the tables");            System.out.println("-tpc        transactions per client");            System.out.println("-clients    number of simultaneous clients");            System.exit(-1);        }        System.out.println(            "*********************************************************");        System.out.println(            "* JDBCBench v1.1                                        *");        System.out.println(            "*********************************************************");        System.out.println();        System.out.println("Driver: " + DriverName);        System.out.println("URL:" + DBUrl);        System.out.println();        System.out.println("Scale factor value: " + tps);        System.out.println("Number of clients: " + n_clients);        System.out.println("Number of transactions per client: "                           + n_txn_per_client);        System.out.println();        try {            Class.forName(DriverName);            JDBCBench Me = new JDBCBench(DBUrl, DBUser, DBPassword,                                         initialize_dataset);        } catch (Exception E) {            System.out.println(E.getMessage());            E.printStackTrace();        }    }    public JDBCBench(String url, String user, String password, boolean init) {        Vector      vClient = new Vector();        Thread      Client  = null;        Enumeration e       = null;        try {            if (init) {                System.out.println("Start: "                                   + (new java.util.Date()).toString());                System.out.print("Initializing dataset...");                createDatabase(url, user, password);                System.out.println("done.\n");                System.out.println("Complete: "                                   + (new java.util.Date()).toString());            }            System.out.println("* Starting Benchmark Run *");            MemoryWatcher = new MemoryWatcherThread();            MemoryWatcher.start();            transactions  = false;            prepared_stmt = false;            start_time    = System.currentTimeMillis();            for (int i = 0; i < n_clients; i++) {                Client = new ClientThread(n_txn_per_client, url, user,                                          password);                Client.start();                vClient.addElement(Client);            }            /*            ** Barrier to complete this test session            */            e = vClient.elements();            while (e.hasMoreElements()) {                Client = (Thread) e.nextElement();                Client.join();            }            vClient.removeAllElements();            reportDone();            transactions  = true;            prepared_stmt = false;            start_time    = System.currentTimeMillis();            for (int i = 0; i < n_clients; i++) {                Client = new ClientThread(n_txn_per_client, url, user,                                          password);                Client.start();                vClient.addElement(Client);            }            /*            ** Barrier to complete this test session            */            e = vClient.elements();            while (e.hasMoreElements()) {                Client = (Thread) e.nextElement();                Client.join();            }            vClient.removeAllElements();            reportDone();            transactions  = false;            prepared_stmt = true;            start_time    = System.currentTimeMillis();            for (int i = 0; i < n_clients; i++) {                Client = new ClientThread(n_txn_per_client, url, user,                                          password);                Client.start();                vClient.addElement(Client);            }            /*            ** Barrier to complete this test session            */            e = vClient.elements();            while (e.hasMoreElements()) {                Client = (Thread) e.nextElement();                Client.join();            }            vClient.removeAllElements();            reportDone();            transactions  = true;            prepared_stmt = true;            start_time    = System.currentTimeMillis();            for (int i = 0; i < n_clients; i++) {                Client = new ClientThread(n_txn_per_client, url, user,                                          password);                Client.start();                vClient.addElement(Client);            }            /*            ** Barrier to complete this test session            */            e = vClient.elements();            while (e.hasMoreElements()) {                Client = (Thread) e.nextElement();                Client.join();            }            vClient.removeAllElements();            reportDone();        } catch (Exception E) {            System.out.println(E.getMessage());            E.printStackTrace();        } finally {            MemoryWatcher.end();            try {                MemoryWatcher.join();                if (ShutdownCommand.length() > 0) {                    Connection C    = connect(url, user, password);                    ;                    Statement  Stmt = C.createStatement();                    Stmt.execute(ShutdownCommand);                    Stmt.close();                    connectClose(C);                }                if (TabFile != null) {                    TabFile.close();                }            } catch (Exception E1) {}            System.exit(0);        }    }    public void reportDone() {        long end_time = System.currentTimeMillis();        double completion_time = ((double) end_time - (double) start_time)                                 / 1000;        if (TabFile != null) {            TabFile.print(tps + ";" + n_clients + ";" + n_txn_per_client                          + ";");        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -