2014年7月16日星期三

EAP_008:部署DayTrader应用

开发运行环境:JBoss EAP 6.2.0 + DayTrader 3.0

DayTrader 是一个端到端 Web 应用程序,非常适合做应用服务器的Benchmark测试。
DayTrader 是根据一个在线股票代理建模的基准测试应用程序。该应用程序能够使用户登录、查看其股票投资组合、查找股票报价,以及买进或卖出股票。
通过借助一个基于 Web 的负载驱动器,由 DayTrader 提供的真实工作负载可以被用于衡量和比较不同供应商提供的 Java EE 应用服务器的性能。
该应用程序还包含了一组原型(primitive),用于对不同 Java EE 组件和常见设计模式进行功能和性能测试。
最新的DayTrader版本是3.0,是针对Java EE 6标准开发设计的,总共包括24个测试用例。

DayTrader 3.0 下载地址:https://github.com/gvijayar/daytrader。
使用 git 克隆到本地:git clone git@github.com:gvijayar/daytrader.git 。

1. 使用Maven构建DayTrader
下载源码后,进入daytrader目录,运行:mvn clean install。

2. 修改standalone-full.xml,修改内容如下:
(1)datasources subsystem部分修改如下:
以Derby数据库为例,
<subsystem xmlns="urn:jboss:domain:datasources:1.1">
            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                    <driver>h2</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <datasource jndi-name="java:jboss/datasources/TradeDataSource" pool-name="jdbc/TradeDataSource" enabled="true" use-ccm="false">
                    <connection-url>jdbc:derby://localhost:1527/daytraderDB;create=true</connection-url>
                    <driver>org.apache.derby</driver>
                    <security>
                        <user-name>demo</user-name>
                        <password>demo</password>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>
                <datasource jndi-name="java:jboss/datasources/NoTxTradeDataSource" pool-name="jdbc/NoTxTradeDataSource" enabled="true" use-ccm="false">
                    <connection-url>jdbc:derby://localhost:1527/daytraderDB;create=true</connection-url>
                    <driver>org.apache.derby</driver>
                    <security>
                        <user-name>demo</user-name>
                        <password>demo</password>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>
                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                    <driver name="org.apache.derby" module="org.apache.derby">
                        <xa-datasource-class>org.apache.derby.jdbc.ClientXADataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>
        </subsystem>

详细步骤请参考《配置Derby数据源》。

以MySQL数据库为例,
<subsystem xmlns="urn:jboss:domain:datasources:1.1">
            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                    <driver>h2</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <datasource jndi-name="java:jboss/datasources/TradeDataSource" pool-name="jdbc/TradeDataSource" enabled="true" use-ccm="false">
                    <connection-url>jdbc:mysql://localhost:3306/demo</connection-url>
                    <driver>mysql</driver>
                    <security>
                        <user-name>root</user-name>
                        <password>welcome1</password>
                    </security>
                </datasource>
                <datasource jndi-name="java:jboss/datasources/NoTxTradeDataSource" pool-name="jdbc/NoTxTradeDataSource" enabled="true" use-ccm="false">
                    <connection-url>jdbc:mysql://localhost:3306/demo</connection-url>
                    <driver>mysql</driver>
                    <security>
                        <user-name>root</user-name>
                        <password>welcome1</password>
                    </security>
                </datasource>
                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                    <driver name="mysql" module="com.mysql">
                        <driver-class>com.mysql.jdbc.Driver</driver-class>
                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>
        </subsystem>

详细步骤请参考《配置MySQL数据源》。

以Oracle数据库为例,
<subsystem xmlns="urn:jboss:domain:datasources:1.1">
            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                    <driver>h2</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <datasource jndi-name="java:jboss/datasources/TradeDataSource" pool-name="jdbc/TradeDataSource" enabled="true" use-ccm="false">
                    <connection-url>jdbc:oracle:thin:@192.168.0.104:1521:XE</connection-url>
                    <driver>oracle</driver>
                    <security>
                        <user-name>demo</user-name>
                        <password>demo</password>
                    </security>
                </datasource>
                <datasource jndi-name="java:jboss/datasources/NoTxTradeDataSource" pool-name="jdbc/NoTxTradeDataSource" enabled="true" use-ccm="false">
                    <connection-url>jdbc:oracle:thin:@192.168.0.104:1521:XE</connection-url>
                    <driver>oracle</driver>
                    <security>
                        <user-name>demo</user-name>
                        <password>demo</password>
                    </security>
                </datasource>
                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                    <driver name="oracle" module="com.oracle">
                        <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>
        </subsystem>
详细步骤请参考《配置Oracle数据源》。
注意:别忘了修改上面配置中的Oracle数据库所在的IP地址。
还要修改 /u01/app/oracle/product/11.2.0/xe/network/admin中的listener.ora和tnsnames.ora中的IP地址,并重启数据库。

(2)因为用到了Queue和Topic,修改messaging subsystem如下:
<subsystem xmlns="urn:jboss:domain:messaging:1.4">
            <hornetq-server>
……
<jms-destinations>
                    <jms-queue name="jms/TradeBrokerQueue">
                        <entry name="java:jboss/jms/TradeBrokerQueue"/>
                        <durable>false</durable>
                    </jms-queue>
                    <jms-topic name="jms/TradeStreamerTopic">
                        <entry name="java:jboss/jms/TradeStreamerTopic"/>
                    </jms-topic>
                </jms-destinations>
 </hornetq-server>
        </subsystem>

3. 启动Derby/Oracle/MySQL数据库
(1)启动Derby
         cd [derby_home]/bin
         ./startNetworkServer
(2)启动Oracle (RHEL 6.5环境下)
          # service oracle-xe start/stop/restart
(3)启动MySQL
         MAC 环境下,
         cd /usr/local/mysql/bin
         启动:sudo ./mysqld_safe
         停止:sudo ./mysqld_safe stop 
         RHEL 环境下,
         # service mysql start/stop/restart

4. 启动JBoss EAP,确认没有报任何错

5. 部署daytrader-ear-3.0.0.ear,Enable,确认没有报任何错

6. 访问http://localhost:8080/daytrader/,点击Configuration,然后
(1)(Re)-create  DayTrader Database Tables and Indexes,重新创建表和索引。
(2)(Re)-populate  DayTrader Database,重新插入数据。
(3)访问:http://localhost:8080/daytrader/scenario
如果想要最"干净"的数据,可以点击 Reset DayTrader (to be done before each run),然后重新执行(1)(2)(3)。

7. 问题
(1)测试用例 PingJDBCRead,出现NullPointException。
经过Debug,修改了如下代码:PingJDBCRead.java, 在78行之后增加如下判断:
# 78行 quoteData = trade.getQuote(symbol);
                if (quoteData != null) {
                        break;
                }

(2)测试用例 PingJDBCWrite,出现NullPointException。
经过Debug,修改了如下代码:PingJDBCRead.java, 在73行之后增加如下判断: 
# 73行   quoteData = trade.updateQuotePriceVolumeInt(symbol, newPrice, 100.0, false);
            if (quoteData != null) {
                        break;
            }

如果(1)(2)还报错,请重新创建表和索引,并重新插入数据,然后在测试。

(3) 测试用例 PingServlet2Session2JDBC,出现NullPointException。
经过Debug,修改了如下代码:PingServlet2Session2JDBC.java, 在75行之后增加如下判断:
#75行 quoteData = directSLSBRemote.getQuote(symbol);
                    if (quoteData != null) {
                        break;
                    }
同时修改了代码:TradeJEEDirect.java,注释了 1856行代码://conn.setAutoCommit(false);
如果不注释该行代码,会有异常发生,导致conn返回null。

(4)测试用例 PingServlet2TwoPhase,出现NullPointException。
经过Debug,修改了如下代码:PingServlet2TwoPhase.java, 在74行之后增加如下判断:
#74行  quoteData = tradeSLSBRemote.pingTwoPhase(symbol);
                    if (quoteData != null) {
                        break;
                    }

(5)java.sql.SQLException: You cannot rollback with autocommit set!
如果出现上面这个错误,需要把 TradeJEEDirect.java的1856行代码取消注释:conn.setAutoCommit(false);

参考文献:
1. http://www.ibm.com/developerworks/cn/opensource/os-perfbenchmk/index.html
2. http://www.ibm.com/developerworks/cn/cloud/library/1310_xiali_daytrader/index.html
3. http://www.ibm.com/developerworks/websphere/techjournal/1208_hare/1208_hare.html

没有评论: