29
Jonathan Abrams SDForum Java SIG December 4, 2007 Building High-Traffic Java-Based Web Applications

December 4 SDForum Java Sig Presentation

Embed Size (px)

DESCRIPTION

December 4 SDForum Java Sig Presentation - Jonathan Abrams

Citation preview

Page 1: December 4 SDForum Java Sig Presentation

Jonathan AbramsSDForum Java SIG

December 4, 2007

Building High-Traffic Java-Based Web Applications

Page 2: December 4 SDForum Java Sig Presentation

2

Popular Languages for Web Apps

• Ruby/RoR– Hot & trendy!– Many small web 2.0 startups– Unknown scalability (Twitter)

• PHP– Facebook, Friendster, Yahoo– Proven and very popular– No connection pooling?– Page-oriented, not usually MVC?– Maintainability?

• Python– Has its fans (Yelp, YouTube?), somewhat similar to

Ruby?– Less common than Ruby or PHP

Page 3: December 4 SDForum Java Sig Presentation

3

Java Misconceptions

• Overly complicated• No longer relevant• Doesn’t scale as well as PHP• Strongly typed is bad/hard vs.

Ruby/PHP• Takes more code and more time• Cannot rapidly prototype

Page 4: December 4 SDForum Java Sig Presentation

4

Tim Bray - Nov 2006“Comparing Frameworks”

“For Web apps, I’ve given PHP the edge, because I think building scalable PHP is a little easier. By default, PHP gives you a “shared-nothing” (or at least “shared very little”) architecture, which means you’re going to scale out pretty well until your database hits the wall. Java is a much richer system and assumes you’re smart enough to know whether a shared-nothing architecture is appropriate or not. The effect is, you have to be smarter to get the same kind of scaling out of Java.”

Page 5: December 4 SDForum Java Sig Presentation

5

Java Realities

• Very mature and proven• Excellent performance (fast JVM/JIT)• Scales fine unless you use it wrong

(sessions, large heaps)• Powerful and flexible

– Cross-platform– Server, client, desktop, mobile, etc.

Page 6: December 4 SDForum Java Sig Presentation

6

Java Realities

• Strong typing can actually be a big help (plus JSP/EL handles type conversions and you can also use Object or polymorphism)

• You can write quick spaghetti code in JSP!• JSP is great for rapid prototyping, modified

JSPs are automatically recompiled in development

• J2EE and breadth of Java technologies and frameworks IS complicated!

Page 7: December 4 SDForum Java Sig Presentation

7

Ruby on Rails vs. Java?

• Groovy/Grails• JRuby• Object/relational mapping

(Hibernate?)• Code by convention (servlet

mapping via servlet filter, instead of controller servlet or web.xml?)

Page 8: December 4 SDForum Java Sig Presentation

8

Who is using Java?

Social Networks• (Friendster)• Bebo• Hi5• Tagged• Tickle• Classmates.com

Events• eVite• MeetUp • Socializr• Involver

Page 9: December 4 SDForum Java Sig Presentation

9

Who is using Java?

E-Commerce• Air Canada• Bank of America• Bestbuy.com• Billboard.com• Blue Nile• Citysearch• DICE• DirecTV• Fedex• Hallmark.com• Hertz

Startups• Daily Candy• Feedburner• Indeed.com• Instructables• Jaxtr• Kaboodle• Like.com• LinkedIn• Mint• Ning• Zillow

• Hotwire• Kayak• Kodak/Ofoto• Macy's• NY Times• Shutterfly• Snapfish• Stamps.com• Staples.com• Ticketweb• Vault.com• Walgreens.com

Page 10: December 4 SDForum Java Sig Presentation

10

J2EE vs. POJO

J2EE The standard for developing multitier enterprise applications

POJO Plain Old Java Object

Page 11: December 4 SDForum Java Sig Presentation

11

Web App FrameworksStruts An open source framework for

building Servlet/JSP based web applications based on the Model-View-Controller (MVC) design paradigm

WebWorks WebWork is a Java web-application development framework

Struts2 Apache Struts 2 is an elegant, extensible framework for creating enterprise-ready Java web applications.Apache Struts 2 was originally known as WebWork 2

Spring Framework Spring is a layered Java/J2EE application framework with a flexible MVC web application framework

Maverick Maverick is a Model-View-Controller (aka "Model 2") framework for web publishing using Java and J2EE. In principle it combines the best features of Struts, WebWork, and Cocoon2

Page 12: December 4 SDForum Java Sig Presentation

12

More FrameworksJSF JavaServer Faces technology is a framework

for building user interfaces for web applications

Facelets An alternative view technology for building JSF applications

Tapestry Tapestry is an open-source framework for creating dynamic, robust, highly scalable web applications in Java

Velocity The Apache Velocity Engine is a free open-source templating engine. Velocity permits you to use a simple yet powerful template language to reference objects defined in Java code.

Tiles Apache Tiles is a templating framework built to simplify the development of web application user interfaces. Tiles grew in popularity as a component of the popular Struts framework. It has since been extracted from Struts and is now integrated with various frameworks, such as Struts 2 and Shale.

Shale Shale is a modern web application framework, fundamentally based on JavaServer Faces

Page 13: December 4 SDForum Java Sig Presentation

13

Even More FrameworksSeam JBoss Seam is a powerful new

application framework for building next generation Web 2.0 applications

Helma Helma is an open source web application framework for fast and efficient scripting and serving of your websites and Internet applications.

Wicket With proper mark-up/logic separation, a POJO data model, and a refreshing lack of XML, Apache Wicket makes developing web-apps simple and enjoyable again

Rife Full-stack open-source component framework to quickly and consistently develop and maintain Java web applications

Page 14: December 4 SDForum Java Sig Presentation

14

Yet More FrameworksjMaki (GlassFish) jMaki is an Ajax framework that

provides a lightweight model for creating JavaScript centric Ajax-enabled web applications using Java, Ruby, PHP, and Phobos

XMLC XMLC is a presentation technology that provides an object-oriented mechanism for creating dynamic content from static HTML and XML documents

Grails Grails aims to bring the "coding by convention" paradigm to Groovy. It's an open-source web application framework that leverages the Groovy language and complements Java Web

GWT Google Web Toolkit (GWT) is an open source Java development framework that lets you escape the matrix of technologies that make writing AJAX applications so difficult and error prone.

Page 15: December 4 SDForum Java Sig Presentation

15

Object/Relational Mapping

• Hibernate• JDO• TopLink (Oracle -> GlassFish)• iBatis (XML-based Object/Relational mapping

and persistence framework) ibatis.apache.org

Page 16: December 4 SDForum Java Sig Presentation

16

Ancient History of Servlets

• 1999 – HotLinks (social bookmarking)– Apache JServ, Solaris, Oracle– Servlets writing HTML - ouch

• 2002 – Friendster– JSP 1.0, Tomcat, MySQL– Java mixed with HTML– Servlets– No tag files

Page 17: December 4 SDForum Java Sig Presentation

17

JSP/Servlets Today

• 2006 – Socializr– JSP 2.0– JSTL/EL– Tag files written in JSP,

SimpleTagSupport, functions, beans– Servlets

– Documentation and support of JSP 2.0/JSTL/tag files poor compared to PHP/ruby/etc.

– Scriptlets required to access Java constants from JSPs

Page 18: December 4 SDForum Java Sig Presentation

18

Servlet/JSP Technologies• JSP pages• JSP fragments• EL• JSTL• .tag files• Tag classes• functions• servlets• beans

Complicated but powerful/flexible

Page 19: December 4 SDForum Java Sig Presentation

19

Socializr Java Architecture

Page 20: December 4 SDForum Java Sig Presentation

20

JSP vs. Servlet?

Web page, HTML JSP

Logic, modify DB Servlet

Reusable UI component

Tag file

Reusable non-UI code

Tag class or function

Data classes and DAOs

Java classes (beans)

RSS feeds Servlets with ROME

REST APIs Servlets

HTML email templates

JSP

Page 21: December 4 SDForum Java Sig Presentation

21

Hi5 and Bebo Examples

Hi5

• JSP• Struts• iBatis• some Spring

libraries

Bebo

• No frameworks• JSP• Simple in-house

MVC• Memcached• No hibernate

Page 22: December 4 SDForum Java Sig Presentation

22

Servlet Containers

Past

• Tomcat• Jetty• Resin

Future

• Tomcat• Grizzly (NIO front-end

to Glassfish)

Page 23: December 4 SDForum Java Sig Presentation

23

How to scale a webapp

• Lightweight non-sticky sessions• Cache almost everything

(memcached)• Decouple slow processes from webapp• Segment the database (don’t use

replication to scale)• Scale out not up (innovate on your

app, not your infrastructure)

Page 24: December 4 SDForum Java Sig Presentation

24

Session Management

• Use simple lightweight sessions, store in centralized location that can be volatile (memcached at Socializr)

• 9F6077E3322B4E24C90C43178F42B9C0FFD1E4A43AED1BCA –> 656280029

• Keep other user data in cache or cookies

• Avoid sticky sessions, keep load balancing simple

• Don’t use built-in Servlet/JSP sessions

Page 25: December 4 SDForum Java Sig Presentation

25

Evite Session Management

Page 26: December 4 SDForum Java Sig Presentation

26

Caching

• Use memcached, don’t invent your own

• Put a large memcached instance on every webapp node

• Don’t cache inside JVM• Cache almost everything but think

of your expiration strategy and invalidation rules

Page 27: December 4 SDForum Java Sig Presentation

27

Performance Tuning

• JRat - jrat.sourceforge.net

• Example: JSTL FormatDate

• Other cool tools: Lambda Probe, FindBugs

Page 28: December 4 SDForum Java Sig Presentation

28

Java Technologies

• Apache commons: DBCP (Connection Pooling), HttpClient, File Upload

• Connector/J (MySQL JDBC driver)• Memcached Java client• JMagick (poorly documented) (not JAI)• JDOM (for APIs) and StAX (for SolrJ) (XML parsing)• ROME (RSS)• JavaMail (SMTP and POP)• Quartz (scheduling)• Apache XML-RPC• SolrJ• JMS

Page 29: December 4 SDForum Java Sig Presentation

29

Thank You

[email protected]

www.socializr.com/jobs