Home > Documentation > Reference > Samples > Sample applications > daytrader - a more complex application |
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:
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.
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.
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 implementations on the configuration page by changed the Runtime Mode.
Implementation | Details |
---|---|
TradeDirect | Pattern: Servlet-to-JDBC |
TradeJDBC | Pattern: Servlet-to-SessionBean-to-JDBC |
TradeBean | Pattern: Servlet-to-SessionBean-to-EntityBean |
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. |
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
As previously mentioned, all of the primary business 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 |
|
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 business 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 |
|
Daytrader is available in the Apache's subversion repository, run the following command to checkout the source files into the daytrader-2.0 directory.
svn co http://svn.apache.org/repos/asf/geronimo/daytrader/trunk/ <daytrader_home>
<daytrader_home> could be any directory dedicated to hold daytrader-2.0.
This process may take several minutes depending on the machine and network connectivity speed.
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.
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.
<geronimo_home>/bin/geronimo start
set GERONIMO_HOME=<geronimo_home>
cd <daytrader_home>/bin/dbscripts/derby
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.2.2.0 ). Once you verified the versions match run the script.
createDerbyDB
daytrader-g-2.0-SNAPSHOT-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.
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-2.0-SNAPSHOT.ear <daytrader_home>\plans\daytrader-g-2.0-SNAPSHOT-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-2.0-SNAPSHOT.ear
EAR using the daytrader-g-2.0-SNAPSHOT-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.
Daytrader is now ready for testing.
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.
Daytrader can be run in number of configurations and also provides a suite of web primitives to ease testing. Each of these primitives singularly test key operations in the enterprise Java programming model. Some of these can be configured to run repeateadly based on the configuration settings that we will cover later on. The following sections describe more in detail these primitives test suite.
The following table describe the Web container related set of primitives. Those primitives that can be set to run multiple times are highlighted.
Primitive | Description |
---|---|
PingHtml | PingHtml is the most basic operation providing access to a simple "Hello World" page of static HTML. |
Explicit GC | Invoke Garbage Collection on AppServer. Reports heap statistics after the GC has completed. |
PingServlet | PingServlet tests fundamental dynamic HTML creation through server side servlet processing. |
PingServletWriter | PingServletWriter extends PingServlet by using a PrintWriter for formatted output vs. the output stream used by PingServlet. |
PingServlet2Include | PingServlet2Include tests response inclusion. Servlet 1 includes the response of Servlet 2. |
PingServlet2Servlet | PingServlet2Servlet tests request dispatching. Servlet 1, the controller, creates a new JavaBean object forwards the request with the JavaBean added to Servlet 2. Servlet 2 obtains access to the JavaBean through the Servlet request object and provides dynamic HTML output based on the JavaBean data. |
PingJSP | PingJSP tests a direct call to JavaServer Page providing server-side dynamic HTML through JSP scripting. |
PingJSPEL | PingJSPEL tests a direct call to JavaServer Page providing server-side dynamic HTML through JSP scripting and the usage of the new JSP 2.0 Expression Language. |
PingServlet2JSP | PingServlet2JSP tests a commonly used design pattern, where a request is issued to servlet providing server side control processing. The servlet creates a JavaBean object with dynamically set attributes and forwards the bean to the JSP through a RequestDispatcher The JSP obtains access to the JavaBean and provides formatted display with dynamic HTML output based on the JavaBean data. |
PingHTTPSession1 | PingHTTPSession1 - |
PingHTTPSession2 | PingHTTPSession2 |
PingHTTPSession3 | PingHTTPSession3 |
PingJDBCRead | PingJDBCRead tests fundamental servlet to JDBC access to a database performing a single-row read using a prepared SQL statement. |
PingJDBCWrite | PingJDBCRead tests fundamental servlet to JDBC access to a database performing a single-row write using a prepared SQL statement. |
PingServlet2JNDI | PingServlet2JNDI tests the fundamental J2EE operation of a servlet allocating a JNDI context and performing a JNDI lookup of a JDBC DataSource. |
The following table describe the EJB container related set of primitives. Those primitives that can be set to run multiple times are highlighted.
Primitive | Description |
---|---|
PingServlet2SessionEJB | PingServlet2SessionEJB tests key function of a servlet call to a stateless SessionEJB. The SessionEJB performs a simple calculation and returns the result. |
PingServlet2EntityEJBLocal | PingServlet2EntityEJB tests key function of a servlet call to an EJB 2.0 Container Managed Entity. In this test the EJB entity represents a single row in the database table. The |
PingServlet2Session2Entity | This tests the full servlet to Session EJB to Entity EJB path to retrieve a single row from the database. |
PingServlet2Session2 | This test extends the previous EJB Entity test by calling a Session EJB which uses a finder method on the Entity that returns a collection of Entity objects. Each object is displayed by the servlet |
PingServlet2Session2CMROne2One | This test drives an Entity EJB to get another Entity EJB's data through an EJB 2.0 CMR One to One relationship |
PingServlet2Session2CMROne2Many | This test drives an Entity EJB to get another Entity EJB's data through an EJB 2.0 CMR One to Many relationship |
PingServlet2Session2JDBC | This tests the full servlet to Session EJB to JDBC path to retrieve a single row from the database. |
PingServlet2Session2 | This test extends the previous JDBC test by calling a Session EJB to JDBC path which returns multiple rows from the database. |
PingServlet2MDBQueue | PingServlet2MDBQueue drives messages to a Queue based Message Driven EJB (MDB).Each request to the servlet posts a message to the Queue. The MDB receives the message asynchronously and prints message delivery statistics on each 100th message. |
PingServlet2MDBTopic | PingServlet2MDBTopic drives messages to a Topic based Publish/Subscribe Message Driven EJB (MDB).Each request to the servlet posts a message to the Topic. The TradeStreamMDB receives the message asynchronously and prints message delivery statistics on each 100th message. Other subscribers to the Topic will also receive the messages. |
PingServlet2TwoPhase | PingServlet2TwoPhase drives a Session EJB which invokes an Entity EJB with findByPrimaryKey (DB Access) followed by posting a message to an MDB through a JMS Queue (Message access). These operations are wrapped in a global 2-phase transaction and commit. |
So now you know what set of primitives are available and which of those can be set to run multiple times. The following table describes what parameters are available from the Daytrader Configuration Utilities to set the runtime parameters.
Parameter | Option | Description |
---|---|---|
Run-Time Mode | EJB | Run Time Mode determines server implementation of the TradeServices to use in the DayTrader application Enterprise Java Beans including Session, Entity and Message beans or Direct mode which uses direct database and JMS access. |
Order-Processing Mode | Synchronous | Order Processing Mode determines the mode for completing stock purchase and sell operations. Synchronous mode completes the order immediately. Asychronous_2-Phase performs a 2-phase commit over the EJB Entity/DB and MDB/JMS transactions. |
Access Mode | Standard | Access Mode determines the protocol used by the DayTrader Web application to access server side services. The Standard mode uses the default Java RMI protocol. The Web Services mode uses the Axis implementation of Web Services including SOAP, WSDL and UDDI. |
Scenario Workload Mix | Standard | This setting determines the runtime workload mix of DayTrader operations when driving the benchmark through TradeScenarioServlet. |
WebInterface | JSP | This setting determines the Web interface technology used, JSPs or JSPs with static images and GIFs. |
DayTrader Max Users | By default the DayTrader database is populated with 50 users (uid:0 - uid:49) and 100 quotes (s:0 - s:99). |
Primitive Iteration | By default the DayTrader primitives are execute one operation per web request. Change this value to repeat operations multiple times per web request. |
Publish Quote Updates | Publish quote price changes to a JMS topic. Needed for running the #Streamer application client. |
Enable long run support | Enable long run support by disabling the show all orders query performed on the Account page. |
Enable operation trace | Enable DayTrader processing trace messages. |
So far we saw what primitives are available, which of those can be set to run multiple iterations and how to configure the application runtime parameters.
100
.With these settings, every time you hit PingServlet2EntityEJBLocal or refresh the page that primitive will get executed 100
times. When doing performance analysis, being able to "play" with these parameters is very valuable. This helps you track down execution times of these very specific functions. When used combined with a load simulation tool, the different configurations will assist you with the fine tuning of the server based on the specific needs of your environment.
We just saw how to run singular functions/operations tests via the available primitives. The very same settings you configured for running those primitives also affect the GUI for trading simulation.
Additional details for configuring and running Daytrader can be found in the application FAQ available by pointing your web browser to http://localhost:8080/daytrader
After you performed some tests and want to run a new set from scratch you will need to reset the runtime configuration and transaction data from the database.
These simple steps are all you need to start a new set of tests on Daytrader however, you may still want to restart the server depending on the type of tests you are running.
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.
In order for the quote price updates to get published to the JMS topic, the "Publish Quote Updates" flag on the configuration page must be enabled.
To start the Streamer application client run the following command.
<geronimo_home>/bin/java -jar client.jar geronimo/daytrader-streamer-client/2.0-SNAPSHOT/car
<geronimo_home>/bin/java -jar client.jar geronimo/daytrader-wsapp-client/2.0-SNAPSHOT/car
Bookmark this on Delicious Digg this | Privacy Policy - Copyright © 2003-2011, The Apache Software Foundation, Licensed under ASL 2.0. |