+ All Categories
Home > Documents > J2EE: Best Practices for Application Development …• Enable session persistence • Reduce...

J2EE: Best Practices for Application Development …• Enable session persistence • Reduce...

Date post: 12-Apr-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
55
J2EE: Best Practices for Application Development and Achieving High-Volume Throughput Michael S Pallos, MBA Session: 3567, 4:30 pm August 11, 2003
Transcript
Page 1: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

J2EE: Best Practices for Application Development and Achieving High-Volume Throughput

Michael S Pallos, MBASession: 3567, 4:30 pmAugust 11, 2003

Page 2: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Agenda

• Architecture Overview• WebSphere Application Server scalability• A proven design pattern• Servlets and Java Server Pages• Sessions• Memory usage

Page 3: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Agenda (continued)

• Enterprise Java Beans• Connecting to legacy systems and

databases– Connection Pooling– Prepared Statements– Session Database– Java Database Connector (JDBC)

• Systems Management

Page 4: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Architectural Overview

WebSphere Application Server –

•3.5 & 4.x

• 5.x

Page 5: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

WAS Architecture (3.5 & 4.x)

Admin Server

EmbeddedHTTP Server

Servlet

Admin Server - JVM

Application Server - JVM

HTTP Server

Plug-in

plugin-cfg.xml

EJB

Servlet

JSP

Web Container

EJB ContainerIIOP

HTTP(S)

HTTP(S)

Node (machine)

Client PC

WebBrowser

ApplicationDatabase

WAS Admin ConsoleGUI Administration

RepositoryJava Admin Consolehttp://localhost:9090/admin

WebSphere ControlProgram (WSCP)CMDXMLConfig

Page 6: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

WAS Architecture (5.x)

plugin-cfg.xml

WAS Administrative ConsoleStandard J2EE 1.3 Web App

HTTP(S)

EJB

JSP

Servlet

XML Configuration Files

wsadmin Scripting command line Tool

(BSF & JMX based)

AppServerXClient PC

WebBrowser HTTP(S)

HttpServer1Application Instance (JVM)

HTTP Server Servlet Container

EmbeddedHTTP Server

Plug-in

ApplicationDatabase

EJB Container

Page 7: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Application Server Clones

• Server Groups– Templates Application server and contents– Changes to group propagate to all clones– Not JVMs and Not Application Servers

• Clones– Exact Copy configured/functional application server– Managed by parent server group

• Vertical Clones– Additional running copy of Application Server on same node

• Horizontal Clone– Additional running copy of Application Server on different node

Page 8: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Vertical Cloning

ApplicationDatabase

AdministrationRepository

Admin Server - JVM

Application Server #1 Clone A - JVM

Web BrowserClient

HTTP Server

Plug-in

plugin-cfg.xml

EJBsServlets

JSPs

Web Container

EJB Container

Node (machine #2)

Application Server #1 Clone B - JVM

EJBsServlets

JSPs

Web Container

EJB Container

HTTP(S)

Machine #1

Page 9: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Vertical Cloning• Strengths

– Improved throughput on large machines– Easy to maintain and support

• Weaknesses– Limited available resources on single machine

• Threats– Single point of failure– Memory/CPU overhead if have too many clones

• Opportunities– Can be combined with other topologies

Page 10: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Horizontal Cloning

ApplicationDatabase

AdministrationRepository

Admin Server - JVM

Application Server #1 Clone A - JVM

Web BrowserClient

HTTP Server

Plug-in

plugin-cfg.xml

EJBsServlets

JSPs

Web Container

EJB Container

Node (machine #2)HTTP(S)

machine #1 Admin Server - JVM

Application Server #1 Clone A - JVM

EJBsServlets

JSPs

Web Container

EJB Container

Node (machine #3)

Page 11: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Horizontal Cloning

• Strengths– Distribution of load among machines– Failover support if one machine goes down– More machines provide more CPU power

• Weaknesses– More difficult to setup and maintain– More $$ for hardware and software

• Threats– Requires session persistency– Increased network traffic between machines

• Opportunities– Can increase number of machines as needed, highly scalable

Page 12: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Design Pattern

Model View Controller

Page 13: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Design Pattern

• MVC– Model – responsible for the data or

business process (persistence/business logic)

– View – responsible for the user’s display (CUI/GUI)

– Controller – is responsible for the flow of the application (traffic cop)

Page 14: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Model-View-Controller

HTML

HTML

Beans

BeansJSP

Servlet

View ModelController

Submit

Request

Forward

Response

Cookie

DB

Page 15: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Servlets &

Java Server Pages (JSP)

Page 16: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Servlets & JSP

• Small, thin Servlets– 50 < Lines of code

• Avoid single-threaded• Avoid System.Out.Println() • Avoid string concatenation

– Use Java StringBuffer• Avoid Serialization• Synchronize statements are costly

Page 17: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Synchronize statementsH

TTP

Req

uest

s/Se

c(H

undr

eds)

No synchronization Synchronization0

10

20

30

40

50

60

www.developer.ibm.com

Page 18: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •
Page 19: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •
Page 20: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Sessions

Page 21: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Sessions

• Keep session objects small < 2k• Designing session data

– Life of Session• Persistent session as dedicated data

source– Single row persistence

• Multi row persistence w/ a large field

– Keep large object graphs out

Page 22: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Sessions (continued)

• Do not create HttpSession objects by default on JSPs– Even though it is part of J2EE spec– Use <%@page session=”false”%>

• Writing your own JDBC calls

Page 23: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •
Page 24: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Data Source & Backend Systems

Data Source

Connection Pooling

Prepare Statements

Session Database

Java Database Connector (JDBC)

Page 25: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Data Source

• Set up data-source once– Object initialization phase– Servlet.init(), ejbActive() – Release to connection pool

Page 26: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Data Source CachingH

TTP

Req

uest

s/Se

c(H

undr

eds)

Cached DatasourceNon-cached Datasource

0102030405060

8070

www.developer.ibm.com

Page 27: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Connection Pooling

• Obtain and close the connection in the same method

• JNDI lookups are expensive• Do not declare connections as static objects• Do not close connections in the finalize

method• If you open a connection, close the

connection• Do not manage data access in Container

Managed Persistence (CMP) beans

Page 28: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Connection PoolingH

TTP

Req

uest

s/Se

c(H

undr

eds)

Conn. Pooling No Conn. Pooling0102030405060

8070

www.developer.ibm.com

Page 29: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Prepared Statements

• Statement– Compiled prior to execution

• Prepared Statement– Separates the compilation process and adding

substitution variables– Use this one!

• Callable Statement– Removes SQL entirely by making a Stored

Procedure Call

Page 30: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

How is SQL effecting CPU?

Page 31: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Session Persistence

• Enable session persistence• Reduce session size• Release HttpSession when finished• Choose persistence options• Avoid creating HttpSession by JSP

default– <%@page session=“false “%>

• Tune the cache size

Page 32: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Session Persistence

Persist!

Cache! InputWaitsUntil

SessionsExpire

OverflowConfigured

(Default)

Add UntilHeap

isExceeded

Persistence

CacheExceeded

(1000 Default)

Yes

Yes

Yes

No

NoNo

In-memory cache overflow algorithm.

Page 33: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Session Persistence (continued)

• Tune the cache size• Add additional application server clones• Tune the session timeout interval• Tune multi-row persistence management

Simplified multi-row session representation.

Session ID

Web Application

Property Small Value Big Value

AB12345 CandleDemo CandleDemo.First.Name “Michael”

AB12345 CandleDemo CandleDemo.last.Name “Pallos”

AB12345 CandleDemo CandleDemo.String A huge string…

Page 34: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •
Page 35: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

JDBC

• Choose your driver wisely• JDBC API levels supported

– JDBC 1.0 is the default– JDBC 2.0 is required by WAS

• Select a Type 2 JDBC driver– When incorporating distributed transactions and

cataloged databases, Type 2 JDBC driver offers the best performance.

Page 36: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

DB Connections

Page 37: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Memory Usage

Page 38: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Memory Usage• Allocation

– Avoid dynamic allocation– Hidden object creation

• Streams• Print writer

• Garbage collections– Pool and reuse objects– Servlet guideline < 50 lines of code

• Health checks– Watch for memory usage growth– Small page size– Small message size

Page 39: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Enterprise Java Beans (EJB)

Page 40: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Enterprise Java Beans• One size DOES NOT fit all

– Ensure you need distributed objects• Alternative to Entity beans

– Tactical– Non-Scalable

• Access Entity beans from Session beans– Triple performance as opposed to accessing

directly from client– Reduces the number of remote method calls– Single transaction context

Page 41: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Accessing Entity BeansH

TTP

Req

uest

s/Se

c(H

undr

eds)

Access from Client CodeAccess via Session Bean05

10

15

20

25

30

www.developer.ibm.com

Page 42: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Enterprise Java Beans

• Read-Only getter methods / Access Intent• Reduce Tx Level

– TRANSACTION_READ_UNCOMMITTED– TRANSACTION_READ_COMMITTED– TRANSACTION_REPEATABLE_READ– TRANSACTION_SERIALIZABLE

• Cache EJB Home– Reduce JNDI calls

Page 43: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

EJB CachingH

TTP

Req

uest

s/Se

c(H

undr

eds)

Client Code Home Caching010203040506070

Session Beanwww.developer.ibm.com

Page 44: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •
Page 45: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Thread Pools

• Create thread pool funnel• Minimize the size of thread pools

ApplicationDatabase

Web BrowserClient

HTTP Server

& plug-in

Application ServerWeb ContainerEJB Container

Data Source

Listener Threads Pool

Servlet/JSP Thread Pool

Database Connection Pool

100 20 10

Request for Static Pages & Dynamic Pages Queue Queue

Servlet Threads Requesting DB Connections

Dynamic PagesStatic Pages

Page 46: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Monitoring Tools

What to look for.

Analyst Recommendations.

Page 47: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Monitoring Tools

• Customer (End-User) Experience – End-To-End (More than just J2EE environment)– Latency Time

• WebSphere Application Server– Instrumentation (class loader hooks)– Workflow Analysis– IBM API (PMI)– Application Server Log– SMF 120 Records (mainframe)

Page 48: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Monitoring Tools (continued)

• Legacy Systems– CICS– IMS

• Database– Connection Pools– DBMS

Page 49: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •
Page 50: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

WebSphere Application Server

Source:

Page 51: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Summary

• Distributed Applications are Complex– A proven design pattern– Servlets and Java Server Pages (JSP)– Sessions– Connecting to legacy systems and

databases• Connection Pooling• Prepared Statements• Session Database• Java Database Connector

Page 52: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Summary• Distributed Applications are Complex

– Memory usage– Enterprise Java Beans– Solid Monitoring Tool

• Hire Experience (consultants)– Follow road to success

• Architecture• Development• Testing • Deployment (Migration)• Monitoring

– Best Practices

Page 53: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Questions

E-mail:[email protected]

Page 54: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

Thank you for your participation• WebSphere Advisor, Nov/Dec 2002

– Best Practices: Application Performance– http://advisor.com/doc/10050

• WebSphere Advisor, April 2003– 5 Java Performance Best Practices– http://advisor.com

• WebSphere Developers Journal, May/June 2003– Best Practices: WAS / DBMS Persistence– http://www.candle.com (Link from home page, Aug 03)

• Webinar expoQ Dailey– Best Practices: J2EE– http://www.ebizq.net/expoq/events/event22.html

Page 55: J2EE: Best Practices for Application Development …• Enable session persistence • Reduce session size • Release HttpSession when finished • Choose persistence options •

A note from Legal…This presentation represents customer's use of Candle's products.

Because each customer's systems, uses and needs are different, Candle does not guarantee comparable results. Candle does not warrant the accuracy of information provided by customers or Candle's business partners. If a product mentioned herein is not yet generally available to Candle's commercial customers, Candle has no obligation to develop the product, to commercially release it, or to incorporate any features or functionalities of the product into any future commercially released product.

Other product names and terms in this document may be trademarks of their respective companies.

-- Candle Corporation Legal Department


Recommended