系统:CentOS 5.6
TPC-W 官方介绍:http://www.tpc.org/tpcw/
下载TPC-W(java版):http://pharm.ece.wisc.edu/tpcw/tpcw.tar.gz
解压缩后就是一个文件夹tpcw1.0
(说明:下面的操作命令大多都是在tpcw1.0所在目录下开始进行的)
安装与配置过程如下:
1.软件安装:
下载并安装JDK
http://www.oracle.com/technetwork/java/javase/downloads/index.html
安装版本:jdk-6u22-linux-i586.bin
路径:/usr/local/java
下载并安装Tomcat
http://tomcat.apache.org/
安装版本:apache-tomcat-6.0.26.tar.gz
路径:/usr/local/apache-tomcat-6.0.26
安装MySQL服务器端
#yum install mysql-server
下载并配置JDBC MySQL驱动
http://dev.mysql.com/downloads/connector/j/
解压后复制mysql-connector-java-5.1.13-bin.jar到此路径下(目录不存在则自己创建):/usr/local/apache-tomcat-6.0.26/webapps/servlet/WEB-INF/lib
2.环境变量设置:
根据自己安装软件的路径在/etc/profile文件末尾添加:
export JAVA_HOME=/usr/local/java/jdk1.6.0_22
export CATALINA_HOME=/usr/local/apache-tomcat-6.0.26
export PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/servlet-api.jar: $CATALINA_HOME/webapps/servlet/WEB-INF/lib/mysql-connector-java-5.1.13-bin.jar$CLASSPATH
重启或注销一下计算机,让环境变量生效
3.修改部分源码:
修改tpcw1.0\populate\populate_images
#!/usr/local/bin/perl ------> #!/usr/bin/perl
$DEST_DIR="/local_home/cain/Images"; ------> $DEST_DIR="/usr/local/apache-tomcat-6.0.26/webapps/tpcw/Images";
修改tpcw1.0\populate\TPCW_Populate.java
private static final String driverName = "com.mysql.jdbc.Driver";//"COM.ibm.db2.jdbc.app.DB2Driver"; private static final String dbName = "jdbc:mysql://localhost:3306/tpcw2";//"jdbc:db2:tpcw2";
PreparedStatement statement = con.prepareStatement ("INSERT INTO address(ADDR_ID,ADDR_STREET1,ADDR_STREET2,ADDR_CITY,ADDR_STATE,ADDR_ZIP,ADDR_CO_ID) VALUES (?, ?, ?, ?, ?, ?, ?)"); //myql是安装在linux上的,所以有大小写之分, 解决com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'tpcw2.ADDRESS'
try { Class.forName(driverName); con = DriverManager.getConnection(dbName, "root", "");//(dbName); con.setAutoCommit(false);//解决java.sql.SQLException: Can't call commit when autocommit=true }修改tpcw1.0\servlets\TPCW_Database.java
static String driverName = "com.mysql.jdbc.Driver";//"COM.ibm.db2.jdbc.app.DB2Driver"; static String jdbcPath = "jdbc:mysql://localhost:3306/tpcw2";//"jdbc:db2:tpcw2";
private static final boolean use_connection_pool = false; //true;
try { Class.forName(driverName).newInstance();//Class.forName(driverName); // Class.forName("postgresql.Driver"); // Create URL for specifying a DBMS Connection con; while(true) { try { // con = DriverManager.getConnection("jdbc:postgresql://eli.ece.wisc.edu/tpcw", "milo", ""); con = DriverManager.getConnection(jdbcPath, "root", "");//con = DriverManager.getConnection(jdbcPath); break;
(下面就是将Prepare SQL语句改成MySql语句,这里简写如下:)
sql.getName="SELECT c_fname,c_lname FROM customer WHERE c_id = ?" sql.getBook="SELECT * FROM item,author WHERE item.i_a_id = author.a_id AND i_id = ?" sql.getCustomer="SELECT * FROM customer, address, country WHERE customer.c_addr_id = address.addr_id AND address.addr_co_id = country.co_id AND customer.c_uname = ?" sql.doSubjectSearch="SELECT * FROM item, author WHERE item.i_a_id = author.a_id AND item.i_subject = ? ORDER BY item.i_title limit 50" sql.doTitleSearch="SELECT * FROM item, author WHERE item.i_a_id = author.a_id AND substring(soundex(item.i_title),0,4)=substring(soundex(?),0,4) ORDER BY item.i_title limit 50" sql.doAuthorSearch="SELECT * FROM author, item WHERE substring(soundex(author.a_lname),0,4)=substring(soundex(?),0,4) AND item.i_a_id = author.a_id ORDER BY item.i_title limit 50" sql.getNewProducts="SELECT i_id, i_title, a_fname, a_lname " +\ "FROM item, author " +\ "WHERE item.i_a_id = author.a_id " +\ "AND item.i_subject = ? " +\ "ORDER BY item.i_pub_date DESC,item.i_title " +\ "limit 50" sql.getBestSellers="SELECT i_id, i_title, a_fname, a_lname " +\ "FROM item, author, order_line " +\ "WHERE item.i_id = order_line.ol_i_id " +\ "AND item.i_a_id = author.a_id " +\ "AND order_line.ol_o_id > (SELECT MAX(o_id)-3333 FROM orders) " +\ "AND item.i_subject = ? " +\ "GROUP BY i_id, i_title, a_fname, a_lname " +\ "ORDER BY SUM(ol_qty) DESC " +\ "limit 50" sql.getRelated="SELECT J.i_id,J.i_thumbnail from item I, item J where (I.i_related1 = J.i_id or I.i_related2 = J.i_id or I.i_related3 = J.i_id or I.i_related4 = J.i_id or I.i_related5 = J.i_id) and I.i_id = ?" sql.adminUpdate="UPDATE item SET i_cost = ?, i_image = ?, i_thumbnail = ?, i_pub_date = CURRENT_DATE WHERE i_id = ?" sql.adminUpdate.related="SELECT ol_i_id " +\ "FROM orders, order_line " + \ "WHERE orders.o_id = order_line.ol_o_id " +\ "AND NOT (order_line.ol_i_id = ?) " +\ "AND orders.o_c_id IN (SELECT o_c_id " +\ " FROM orders, order_line " +\ " WHERE orders.o_id = order_line.ol_o_id " +\ " AND orders.o_id > (SELECT MAX(o_id)-10000 FROM orders)" + \ " AND order_line.ol_i_id = ?) " +\ "GROUP BY ol_i_id " +\ "ORDER BY SUM(ol_qty) DESC " +\ "limit 5" sql.adminUpdate.related1="UPDATE item SET i_related1 = ?, i_related2 = ?, i_related3 = ?, i_related4 = ?, i_related5 = ? WHERE i_id = ?" sql.getUserName="SELECT c_uname FROM customer WHERE c_id = ?" sql.getPassword="SELECT c_passwd FROM customer WHERE c_uname = ?" sql.getRelated1="SELECT i_related1 FROM item where i_id = ?" sql.getMostRecentOrder.id="SELECT o_id " +\ "FROM customer, orders " +\ "WHERE customer.c_id = orders.o_c_id " +\ "AND c_uname = ? " +\ "ORDER BY o_date, orders.o_id DESC " +\ "limit 1" sql.getMostRecentOrder.order="SELECT orders.*, customer.*, " +\ " cc_xacts.cx_type, " +\ " ship.addr_street1 AS ship_addr_street1, " +\ " ship.addr_street2 AS ship_addr_street2, " +\ " ship.addr_state AS ship_addr_state, " +\ " ship.addr_zip AS ship_addr_zip, " +\ " ship_co.co_name AS ship_co_name, " +\ " bill.addr_street1 AS bill_addr_street1, " +\ " bill.addr_street2 AS bill_addr_street2, " +\ " bill.addr_state AS bill_addr_state, " +\ " bill.addr_zip AS bill_addr_zip, " +\ " bill_co.co_name AS bill_co_name " +\ "FROM customer, orders, cc_xacts," +\ " address AS ship, " +\ " country AS ship_co, " +\ " address AS bill, " + \ " country AS bill_co " +\ "WHERE orders.o_id = ? " +\ " AND cx_o_id = orders.o_id " +\ " AND customer.c_id = orders.o_c_id " +\ " AND orders.o_bill_addr_id = bill.addr_id " +\ " AND bill.addr_co_id = bill_co.co_id " +\ " AND orders.o_ship_addr_id = ship.addr_id " +\ " AND ship.addr_co_id = ship_co.co_id " +\ " AND orders.o_c_id = customer.c_id" sql.getMostRecentOrder.lines="SELECT * " + \ "FROM order_line, item " + \ "WHERE ol_o_id = ? " +\ "AND ol_i_id = i_id" sql.createEmptyCart="SELECT COUNT(*) FROM shopping_cart" sql.createEmptyCart.insert="INSERT into shopping_cart (sc_id, sc_time) " + \ "VALUES ((SELECT COUNT(*) FROM shopping_cart)," + \ "CURRENT_TIMESTAMP)" sql.addItem="SELECT scl_qty FROM shopping_cart_line WHERE scl_sc_id = ? AND scl_i_id = ?" sql.addItem.update="UPDATE shopping_cart_line SET scl_qty = ? WHERE scl_sc_id = ? AND scl_i_id = ?" sql.addItem.put="INSERT into shopping_cart_line (scl_sc_id, scl_qty, scl_i_id) VALUES (?,?,?)" sql.refreshCart.remove="DELETE FROM shopping_cart_line WHERE scl_sc_id = ? AND scl_i_id = ?" sql.refreshCart.update="UPDATE shopping_cart_line SET scl_qty = ? WHERE scl_sc_id = ? AND scl_i_id = ?" sql.addRandomItemToCartIfNecessary="SELECT COUNT(*) from shopping_cart_line where scl_sc_id = ?" sql.resetCartTime="UPDATE shopping_cart SET sc_time = CURRENT_TIMESTAMP WHERE sc_id = ?" sql.getCart="SELECT * " + \ "FROM shopping_cart_line, item " + \ "WHERE scl_i_id = item.i_id AND scl_sc_id = ?" sql.refreshSession="UPDATE customer SET c_login = NOW(), c_expiration = (CURRENT_TIMESTAMP + INTERVAL 2 HOUR) WHERE c_id = ?" sql.createNewCustomer="INSERT into customer (c_id, c_uname, c_passwd, c_fname, c_lname, c_addr_id, c_phone, c_email, c_since, c_last_login, c_login, c_expiration, c_discount, c_balance, c_ytd_pmt, c_birthdate, c_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" sql.createNewCustomer.maxId="SELECT max(c_id) FROM customer" sql.getCDiscount="SELECT c_discount FROM customer WHERE customer.c_id = ?" sql.getCAddrId="SELECT c_addr_id FROM customer WHERE customer.c_id = ?" sql.getCAddr="SELECT c_addr_id FROM customer WHERE customer.c_id = ?" sql.enterCCXact="INSERT into cc_xacts (cx_o_id, cx_type, cx_num, cx_name, cx_expire, cx_xact_amt, cx_xact_date, cx_co_id) " + \ "VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, (SELECT co_id FROM address, country WHERE addr_id = ? AND addr_co_id = co_id))" sql.clearCart="DELETE FROM shopping_cart_line WHERE scl_sc_id = ?" sql.enterAddress.id="SELECT co_id FROM country WHERE co_name = ?" sql.enterAddress.match="SELECT addr_id FROM address " + \ "WHERE addr_street1 = ? " +\ "AND addr_street2 = ? " + \ "AND addr_city = ? " + \ "AND addr_state = ? " + \ "AND addr_zip = ? " + \ "AND addr_co_id = ?" sql.enterAddress.insert="INSERT into address (addr_id, addr_street1, addr_street2, addr_city, addr_state, addr_zip, addr_co_id) " + \ "VALUES (?, ?, ?, ?, ?, ?, ?)" sql.enterAddress.maxId="SELECT max(addr_id) FROM address" sql.enterOrder.insert="INSERT into orders (o_id, o_c_id, o_date, o_sub_total, " + \ "o_tax, o_total, o_ship_type, o_ship_date, " + \ "o_bill_addr_id, o_ship_addr_id, o_status) " + \ "VALUES (?, ?, CURRENT_DATE, ?, 8.25, ?, ?, CURRENT_DATE + INTERVAL ? DAY, ?, ?, 'Pending')" sql.enterOrder.maxId="SELECT count(o_id) FROM orders" sql.addOrderLine="INSERT into order_line (ol_id, ol_o_id, ol_i_id, ol_qty, ol_discount, ol_comments) " + \ "VALUES (?, ?, ?, ?, ?, ?)" sql.getStock="SELECT i_stock FROM item WHERE i_id = ?" sql.setStock="UPDATE item SET i_stock = ? WHERE i_id = ?" sql.verifyDBConsistency.custId="SELECT c_id FROM customer" sql.verifyDBConsistency.itemId="SELECT i_id FROM item" sql.verifyDBConsistency.addrId="SELECT addr_id FROM address"
修改tpcw1.0\servlets\TPCW_Util.java
public static final String SESSION_ID="jsessionid="; //"$sessionid{1}quot;;
修改tpcw1.0\rbe\RBE.java
public static String www1 = "http://localhost:8080/";//"http://ironsides.cs.wisc.edu:8001/"; new StrStrPattern(";jsessionid="); //(";$sessionid{1}quot;); public static final String field_sessionID = ";jsessionid="; //";$sessionid{1}quot;;
# service mysqld start
# mysql
> CREATE DATABASE tpcw2;
5.开始安装TPC-W:
mkdir -p ${CATALINA_HOME}/webapps/tpcw/Images
mkdir -p ${CATALINA_HOME}/webapps/servlet/WEB-INF/classes
在数据库tpcw2中生成数据
cd populate
service mysqld start
javac TPCW_Populate.java
java TPCW_Populate
cp TPCW_Populate.class ${CATALINA_HOME}/webapps/servlet/WEB-INF/classes
生成并部署图片
cd ../ImgGen/ImgFiles
make
cd ..
cd ../populate
perl populate_images
cp ../images/* ${CATALINA_HOME}/webapps/tpcw/Images
编译并部署servlets
cd ../servlets
javac *.java
cp *.class ${CATALINA_HOME}/webapps/servlet/WEB-INF/classes
vi ${CATALINA_HOME}/webapps/servlet/WEB-INF/web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>TPC-W</display-name> <description> TPC-W Java Implementation </description> <servlet> <servlet-name>TPCW_home_interaction</servlet-name> <servlet-class>TPCW_home_interaction</servlet-class> </servlet> <servlet> <servlet-name>TPCW_shopping_cart_interaction</servlet-name> <servlet-class>TPCW_shopping_cart_interaction</servlet-class> </servlet> <servlet> <servlet-name>TPCW_order_inquiry_servlet</servlet-name> <servlet-class>TPCW_order_inquiry_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_order_display_servlet</servlet-name> <servlet-class>TPCW_order_display_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_search_request_servlet</servlet-name> <servlet-class>TPCW_search_request_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_execute_search</servlet-name> <servlet-class>TPCW_execute_search</servlet-class> </servlet> <servlet> <servlet-name>TPCW_new_products_servlet</servlet-name> <servlet-class>TPCW_new_products_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_best_sellers_servlet</servlet-name> <servlet-class>TPCW_best_sellers_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_product_detail_servlet</servlet-name> <servlet-class>TPCW_product_detail_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_customer_registration_servlet</servlet-name> <servlet-class>TPCW_customer_registration_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_buy_request_servlet</servlet-name> <servlet-class>TPCW_buy_request_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_buy_confirm_servlet</servlet-name> <servlet-class>TPCW_buy_confirm_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_admin_request_servlet</servlet-name> <servlet-class>TPCW_admin_request_servlet</servlet-class> </servlet> <servlet> <servlet-name>TPCW_admin_response_servlet</servlet-name> <servlet-class>TPCW_admin_response_servlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TPCW_home_interaction</servlet-name> <url-pattern>/TPCW_home_interaction</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_shopping_cart_interaction</servlet-name> <url-pattern>/TPCW_shopping_cart_interaction</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_order_inquiry_servlet</servlet-name> <url-pattern>/TPCW_order_inquiry_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_order_display_servlet</servlet-name> <url-pattern>/TPCW_order_display_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_search_request_servlet</servlet-name> <url-pattern>/TPCW_search_request_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_execute_search</servlet-name> <url-pattern>/TPCW_execute_search</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_new_products_servlet</servlet-name> <url-pattern>/TPCW_new_products_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_best_sellers_servlet</servlet-name> <url-pattern>/TPCW_best_sellers_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_product_detail_servlet</servlet-name> <url-pattern>/TPCW_product_detail_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_customer_registration_servlet</servlet-name> <url-pattern>/TPCW_customer_registration_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_buy_request_servlet</servlet-name> <url-pattern>/TPCW_buy_request_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_buy_confirm_servlet</servlet-name> <url-pattern>/TPCW_buy_confirm_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_admin_request_servlet</servlet-name> <url-pattern>/TPCW_admin_request_servlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TPCW_admin_response_servlet</servlet-name> <url-pattern>/TPCW_admin_response_servlet</url-pattern> </servlet-mapping> </web-app>
编译RBE
cd rbe
cd util
javac *.java
cd ../args
mkdir -p rbe/util
cp ../util/*.class rbe/util/
mkdir rbe/args
javac *.java
cp *.class rbe/args/
mv rbe ../
cd ..
javac *.java
(注:由于直接编译会出现错误,所以这里要修改部分函数名
tpcw1.0/rbe/util/Debug.java中
public class Debug { public static void assert(boolean assertCond, String message) …
把函数名assert改成你自己想要的名字, 如assert1
接着以下三个文件中所有出现的Debug.assert中的assert都改成你自己修改函数名, 如Debug.assert1
tpcw1.0/rbe/EB.java
tpcw1.0/rbe/util/CharSetStrPattern.java
tpcw1.0/rbe/util/Histogram.java)
6.测试TPC-W:
启动tomcat
# startup.sh
访问http://localhost:8080/servlet/TPCW_home_interaction页面测试是否安装成功
7.运行TPC-W:
cd tpcw1.0/
java rbe.RBE -EB rbe.EBTPCW1Factory 30 -OUT test.m -RU 100 -MI1000 -RD 100 -CUST 10000 -ITEM 10000