You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 23 Next »

DayTrader is benchmark application built around the paradigm of an online stock trading system. Originally developed by IBM as the Trade Performance Benchmark Sample, DayTrader was donated to the Apache Geronimo community in 2005. This application allows users to login, view their portfolio, lookup stock quotes, and buy or sell stock shares. With the aid of a Web-based load driver such as Mercury LoadRunner, Rational Performance Tester, or Apache JMeter, the real-world workload provided by DayTrader can be used to measure and compare the performance of Java Platform, Enterprise Edition (Java EE) application servers offered by a variety of vendors.

In addition to the full workload, the application also contains a set of primitives used for functional and performance testing of various Java EE components and common design patterns.

This document is organized in the following sections:

Application Architecture

DayTrader is built on a core set of Java EE technologies that includes Java Servlets and JavaServer Pages (JSPs) for the presentation layer and Java database connectivity (JDBC), Java Message Service (JMS), Enterprise JavaBeans (EJBs) and Message-Driven Beans (MDBs) for the back-end business logic and persistence layer. The following diagram provides a high-level overview of the full workload application architecture.

Presentation Layer

The presentation layer consists of several Java Servlets and JSPs that loosely adhere to a Model-View-Controller (MVC) design pattern. TradeAppServlet is the primary controller servlet responsible for recieving incoming client requests, triggering the desired business logic, and forwarding responses to the appropriate JSP page. Additional servlets and JSPs are used to configure the DayTrader runtime options and manage the supporting database.

Business Logic and Persistence Layer

The business logic and persistence layer form the bulk of the DayTrader application. The TradeServices interface defines the core set of business operations available in the application, such as register, login, getHoldings, buy, completeOrder, logout, etc. DayTrader provides three different implementations of these services, corresponding to three commonly used JavaEE application design patterns. These implementations are discussed below. Users can switch between these implemenations on the configuration page by changed the Runtime Mode.

Implementation

Details

TradeDirect
(Default)

Pattern: Servlet-to-JDBC
Runtime Mode: Direct

The TradeDirect class performs CRUD (create, read, update, and delete) operations directly agaist the supporting database using custom JDBC code. Database connections, commits, and rollbacks are managed manually in the code. JTA user transactions are used to coordinate 2-phase commmits.

TradeJDBC

Pattern: Servlet-to-SessionBean-to-JDBC
Runtime Mode: Session Direct

The TradeJDBC stateless session bean serves as a wrapper for TradeDirect. The session bean assumes control of all transaction management while TradeDirect remains responsible for handleing the JDBC operations and connections. This implementation reflects the most commonly used JavaEE application design pattern.

TradeBean

Pattern: Servlet-to-SessionBean-to-EntityBean
Runtime Mode: EJB

The TradeBean stateless session bean uses Caontainer Managed Persistence (CMP) entity beans to represent the business objects. The state of these objects is completely managed by the application servers EJB container.

Another subtle component of this layer involves the Java Messaging Service (JMS). JMS is used within DayTrader for two specific purposes, asynchronously processing buy/sell orders, and publishing quote price updates. The following table discusses these operations in further detail.

Operation

Details

Asynchrounous Order Processing

When a buy or sell operation is performed, an order request is placed on the TradeBroker JMS queue using a client connection. The TradeBrokerMDB consumes messages on this queue and completes the buy or sell operation.

Quote Price Updates

As stocks are traded, the associated quote prices are updated in the database and published to a JMS topic. The TradeStreamerMDB subscribes to these updates consuming the price updates messages, but does nothing more with them. The TradeStreamer JavaEE client that is bundled with DayTrader can be started to view the quote prices updates in real time.

Business Objects and Relationships

The following diagram represents the database schema and associated business objects. Container managed relationships (CMRs) are also depicted in the diagram.

Create diagram and add here

Business Operations (as defined in TradeServices)

As previously mentioned, all of the primary buisness operations provided by DayTrader are defined in the TradeServices interface. These operations are discussed further in the following table.

TradeServices Operation

Details

login

 

logout

 

buy

 

sell

 

getMarketSummary

 

queueOrder

 

completeOrder

 

cancelOrder

 

orderCompleted

 

getOrders

 

getClosedOrders

 

createQuote

 

getQuote

 

getAllQuotes

 

updateQuotePriceVolume

 

getHoldings

 

getHolding

 

getAccountData

 

getAccountProfileData

 

updateAccountProfile

 

register

 

resetTrade

 

User Inerface (UI) Operations

The DayTrader JSP/Servlet-based web client provides a basic set of operations that one would expect to find in any stock trading and portfolio management application. These high level user operations trigger specific business operations (defined above) within the buisness logic and persistence layers to perform the desired task. The following table summarizes the business tasks performed by each user operation/action.

Client (UI) Operation

Flow of Business Operations

Register

 

Login

 

View Account

 

View Account Profile

 

Update Account Profile

 

View Portfolio

 

Sell Holding

 

View Quotes

 

Buy Stock

 

Logout

 

Getting the source

Daytrader is available in the Apache's subversion repository, run the following command to checkout the source files into the daytrader-1.2 directory.

svn co http://svn.apache.org/repos/asf/geronimo/daytrader/branches/1.2/ <daytrader_home>

<daytrader_home> could be any directory dedicated to hold daytrader-1.2.

This process may take several minutes depending on the machine and network connectivity speed.

Building Daytrader

Once all the sources get checked out the next step is to build Daytrader. Daytrader requires Maven 2 for building the binaries.

From the <daytrader_home> directory run the following command.

mvn install

This process will take a couple of minutes. The binaries will be generated in the corresponding target directory for each of the modules in the modules directory.

Configuring Daytrader

By default Daytrader requires a database to be created using the embedded Derby database that is shipped with Geronimo. Typically, the provided deployment plan files are configured to create such database (DaytraderDatabase) on Apache Derby during deployment. However, scripts are provided within the <daytrader_home>/bin/dbscripts/derby directory to create this database manually. Note that at this point this step optional, you can still create the required database after deploying Daytrader and using the (Re)-create DayTrader Database Tables and Indexes link from the application's Configuration Utility page.

Independently on whether you use the command line scripts or the web based option, you will need the tables created before getting to the #Populating sample data section.

The puspose of this section is to show you how to use the provided scripts to create the required DaytraderDatabase so, if needed, you can adapt them to your specific configuration environment. Additional scripts for different databases are also provided.

  • Start Geronimo by running the following command:
    <geronimo_home>/bin/geronimo start
  • The provided database creation script requires setting the GERONIMO_HOME environment variable. On the same window you start Geronimo run the following command:
    set GERONIMO_HOME=<geronimo_home>
  • Change directory to the directory containing the database creation scripts.
    cd <daytrader_home>/bin/dbscripts/derby
  • Open createDerbyDB script and verify/modify the Derby version to match the one being used by Geronimo ( e.g. <geronimo_home>/repository/org/apache/derby/derby/10.1.3.1 ). Once you verified the versions match run the script.
    createDerbyDB
    You sould see a scree similar to the one illustrated below.
    D:\daytrader-1.2\bin\dbscripts\derby>createDerbyDB.bat
    "Invoking IJ command line tool to create the database and tables...please wait"
    ij version 10.1
    ij> ij> ERROR 42Y55: 'DROP TABLE' cannot be performed on 'HOLDINGEJB' because it does not exist.
    ij> ERROR 42Y55: 'DROP TABLE' cannot be performed on 'ACCOUNTPROFILEEJB' because it does not exist.
    ij> ERROR 42Y55: 'DROP TABLE' cannot be performed on 'QUOTEEJB' because it does not exist.
    ij> ERROR 42Y55: 'DROP TABLE' cannot be performed on 'KEYGENEJB' because it does not exist.
    ij> ERROR 42Y55: 'DROP TABLE' cannot be performed on 'ACCOUNTEJB' because it does not exist.
    ij> ERROR 42Y55: 'DROP TABLE' cannot be performed on 'ORDEREJB' because it does not exist.
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> 0 rows inserted/updated/deleted
    ij> ij> Table creation complete
    
  • You can verify the database was created by pointing your browser to the Geronimo Administration Console and clicking on DB Manager.
  • The last step in this configuration is to update the deployment plan. Edit the daytrader-1.2-beta-plan.xml deployment plan located in the <daytrader_home>\plans directory and replace ge-activemq-rar/1.2-beta/rar with ge-activemq-rar/1.2/rar.

You are now ready to deploy the application.

Deploying Daytrader

So far we have retrieved the source file, built, configured, created a database and updated the deployment plan. Now it is time to install the Daytrader application in Geronimo.

There are basically two ways to deploy an application in Geronimo, either using the Geronimo Administration Console or the command line based deployer tool. For this example we will be using the command line based option.

From the <geronimo_home>/bin directory run the following command:

deploy --user system --password manager deploy <daytrader_home>\modules\ear\target\daytrader-ear-1.2-SNAPSHOT.ear <daytrader_home>\plans\daytrader-1.2-beta-plan.xml

The first deploy is the script that calls the deployer tool, then we pass the user name and password. The second deploy is the actual command option for deploying the daytrader-ear-1.2-SNAPSHOT.ear EAR using the daytrader-1.2-beta-plan.xml deployment plan specifically. In your own application you could call this plan geronimo-application.xml and place it in the META-INF directory within you EAR file and you will not need to expressly specify the deployment plan from the command line.

You should see a deployment confirmation screen similar to the one shown below.

D:\geronimo-tomcat-j2ee-1.2\bin>deploy --user system --password manager deploy \daytrader-1.2\modules\ear\target\daytrader-ear-1.2-SNAPSHOT.ear \daytrader-1.2\plans\daytrader-1.2-beta-plan.xml
Using GERONIMO_BASE:   D:\geronimo-tomcat-j2ee-1.2
Using GERONIMO_HOME:   D:\geronimo-tomcat-j2ee-1.2
Using GERONIMO_TMPDIR: D:\geronimo-tomcat-j2ee-1.2\var\temp
Using JRE_HOME:        C:\Java\jdk1.5.0_06\jre
    Deployed geronimo/daytrader/1.2-SNAPSHOT/car
      `-> web.war @ http://localhost:8080/daytrader
      `-> dt-ejb.jar
      `-> geronimo/daytrader-wsapp-client/1.2-SNAPSHOT/car
      `-> geronimo/daytrader-streamer-client/1.2-SNAPSHOT/car
      `-> TradeDataSource
      `-> TradeJMS

Daytrader is now ready for testing.

Populating sample data

With the application deployed and started (starts by default when you deploy it) the next step before using Daytrader is to populate sample data to the database we created before. The following steps illustrate how.

  • Access the application pointing your browser to http://localhost:8080/daytrader



  • Click on the Configuration tab.
  • Click on (Re)-populate DayTrader Database to generate the sample data, this will open a new window showing the progress.
    The initial population size consists of 200 accounts and 400 stock quotes. These values can be updated via the "Configure DayTrader run-time parameters" link on the "Configuration" tab.

Running Daytrader

We have built, configured and installed Daytrader and now the application is ready to testing.

Click on Trading & Portfolios, accept the default user and password and click on Login. You should now be able to begin trading!

Launching the application clients

DayTrader provides two J2EE application clients, the DayTrader Streamer and a web services application. The Streamer application client uses a JMS topic to subscribe to quote price updates as stocks are bought and sold. These updates are tracked and used to determine if database collisions occur while updating the quote prices in the database. The web services application client simply provides a thick client for accessing DayTrader services using a web services interface.

Streamer application client

In order for the quote price updates to published to the JMS topic, the "Publish Quote Updates" flag on the configuration page must be enabled. From the Daytrader Home page click on Configuration and then click on Configure DayTrader run-time parameters. Make sure you select the Publish Quote Updates checkbox.

To start the Streamer application client run the following command.

<geronimo_home>/bin/java -jar client.jar geronimo/daytrader-streamer-client/1.2-SNAPSHOT/car

Web Services application client

<geronimo_home>/bin/java -jar client.jar geronimo/daytrader-wsapp-client/1.2-SNAPSHOT/car

  • No labels