ppt - C-JDBC

obtainablerabbiΔιαχείριση Δεδομένων

31 Ιαν 2013 (πριν από 4 χρόνια και 4 μήνες)

127 εμφανίσεις

Dynamic Content Web Sites:
Technologies & Scalability

Emmanuel Cecchet

emmanuel.cecchet@inria.fr

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

2

Dynamic content Web site


Web content is more and more dynamic


LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

3

e
-
Commerce servers


Multi
-
tier architecture

HTTP
Application
protocol
Web server
Database
Application
server
Client
Internet
SQL
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

4

Outline


Technologies


Performance


Clustering


Conclusion


LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

5

PHP


Hypertext Preprocessor


Scripting language


Module integrated in Web server


SQL
Web server
Database
Client
HTTP
...

httpd
PHP

httpd
PHP
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

6

PHP example

<!DOCTYPE HTML PUBLIC "
-
//W3C//DTD HTML 4.01 Transitional//EN">

<html>


<body>


<h1>Region list</h1>


<?php


$result =
mysql_query
("
SELECT * FROM regions
", $link) or


die
("
ERROR: Request failed
");


if

(
mysql_num_rows
($result) == 0)


print
("
<h2>Sorry, no region, db is empty.</h2><br>
");


else


while

($row =
mysql_fetch_array
($result))


{


print
("
<a href=
\
"BrowseCategories.php?region=
".


$row["id"]."
\
">
".$row["name"]."
</a><br>
\
n
");


}


mysql_free_result
($result);


?>


</body>

</html>


LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

7

PHP


Pros


easy to learn


ideal for small projects


widely used


no strong typing


Cons


no strong typing


code maintenance


interpreted language


executes in the Web server process


ad
-
hoc APIs for database access

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

8

Java Servlets


Java based


Executes in a “Servlet Container”


JDBC: unified interface for database access

JDBC
Tomcat Servlet
container
Web server
Database
Client
HTTP
Servlet
server
AJP12
h
t
t
p
d
JVM
...
h
t
t
p
d
servlet
servlet
servlet
servlet
servlet
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

9

Java Servlet example

public class BrowseRegions extends
HttpServlet

{






public void
doGet
(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException


{


out.print("
<h1>Region list</h1>
");




try


{


ResultSet rs = connection.createStatement().executeQuery("
SELECT * FROM regions
");


if (!rs.first())


out.print("
<h2>Sorry, no region, db is empty</h2><br>
");


else


do


{


out.print("
<a href=
\
"BrowseCategories?region=
"+rs.getInteger("id")+


"
\
">
"+rs.getString("name")+"
</a><br>
\
n
");


} while (rs.next());


}



catch (Exception e)


{


out.print("
ERROR: Request failed for the following reason:

" + e);


return;


}


}

}

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

10

What about JSP?


Java Server Pages


Sun’s answer to Microsoft ASP


“scripting for servlets”


Scripting language


Compiled into a Java servlet at the first
execution

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

11

JSP example

<!DOCTYPE HTML PUBLIC "
-
//W3C//DTD HTML 4.01 Transitional//EN">

<html>


<body>


<h1>Region list</h1>


<%


try {


ResultSet rs = connection.createStatement().executeQuery("
SELECT * FROM regions
");


if (!rs.first()) {


%>


<h2>Sorry, no region, db is empty</h2><br>


<% } else


do{


%>


<a href="BrowseCategories?region="
<%= rs.getInteger("id") %>

">


<%= rs.getString("name") %>

</a><br>


<%


} while (rs.next());


}


catch (Exception e) {


%>


ERROR: Request failed for the following reason: <%= e.getMessage() %>


<% } %>


</body>

</html>


LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

12

Servlets/JSP


Pros


OO programming (JSP for scripting)


design patterns maturity


JDBC for database access


Servlet container independent from Web server


Cons


Web server / Servlet server communication


limited number of services


OO programming is more verbose (servlets)

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

13

J2EE Servers


Java 2 Enterprise Edition


Separation of presentation and business logics

J2EE Application Server
Web server
Database
Web
container
EJB
container
Presentation
logic
Business
logic
Client
Internet
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

14

J2EE Servers


Presentation logic



JSP or Servlets


Business logic


Enterprise JavaBeans (EJB)


Entity Beans



database mapping



BMP: by hand



CMP: automatic


Session Beans



stateless: temporary operations



stateful: temporary objects (shopping cart)


Message Driven Beans



asynchronous messages

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

15

J2EE


Pros


well suited for large projects or EAI


presentation and business logic isolation


large number of services (transactions, security,
asynchronous messaging, clustering, …)


Cons


requires skills



large number of specs



impact of design on performances


complex to setup


portability across servers to improve

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

16

Open
-
source offers


PHP


implementation from php.net


included in Apache


Servlets


Tomcat (http://jakarta.apache.org/tomcat/)


Jetty (http://jetty.mortbay.com)


J2EE


JOnAS (http://jonas.objectweb.org)


JBoss (http://jboss.org)


LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

17

Outline


Technologies


Performance


Clustering


Conclusion


LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

18

RUBiS Benchmark


online auction site


modeled after eBay.com


9 open
-
source implementations


PHP


Servlets


7 EJB


all results are online


http://rubis.objectweb.org/

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

19

RUBiS


PHP & Servlets


Apache/PHP vs Apache/Tomcat

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

20

JVM Performance

0
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
200
220
240
260
280
300
320
340
360
380
400
420
440
460
480
500
520
540
560
580
600
Number of clients
Throughput in requests/minute
IBM
JRockit
Sun
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

21

Design patterns: Servlets only


Presentation and business logic mixed

Database

Web container

Servlet

Presentation

logic

Business

logic

Servlet

Presentation

logic

Business

logic

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

22

Design patterns: Session
Beans


Presentation and business logic separation

Session bean

EJB container

Business

logic

Servlet

Web container

Servlet

Database

Presentation

logic

Presentation

logic

Session bean

Business

logic

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

23

Design pattern: Entity Beans


Data Access Objects separation with Entity
Beans (BMP or CMP)

EJB container

Entity

Bean

Database

Entity

Bean

Entity

Bean

Web
container

Servlet

Presentation

logic

Business

logic

Servlet

Presentation

logic

Business

logic

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

24

Design patterns: Session
façade


Façade session bean with EJB 1.1

EJB container

Entity

Bean

Session facade

Web container

Session facade

Database

Entity

Bean

Entity

Bean

Business

logic

Business

logic

Servlet

Servlet

Presentation

logic

Presentation

logic

Communication layer

Remote interface

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

25

Design patterns: EJB 2.0 local


Session façade with EJB 2.0 local interface
Entity Beans

EJB container

Entity

Bean

Session facade

Web container

Session facade

Database

Entity

Bean

Entity

Bean

Business

logic

Business

logic

Servlet

Servlet

Presentation

logic

Presentation

logic

Local interface

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

26

Code complexity

0
2000
4000
6000
8000
10000
12000
14000
PHP
Servlets-
only
Session
beans
EB CMP
EB BMP
Session
façade
EJB 2.0
local
Lines of code
Business logic
Presentation logic
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

27

RUBiS
-

J2EE Servers


Apache/Tomcat/JBoss vs Apache/Tomcat/JOnAS

0
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
Session Beans
EB-CMP
EB-BMP
Session façade
EJB 2.0 Local
Maximum throughput in requests/minute
Optimized JBoss
Optimized JOnAS
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

28

J2EE Performance


Session Beans = Servlets >= PHP


Entity Beans


BMP = CMP


data access very (too?) fine grain


Design pattern determines performance


Communication layers : 45 to 90% cpu

usage


Container design


Less than 2% of execution time in user bean
code

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

29

Outline


Technologies


Performance


Clustering


Conclusion


LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

30

Clustering

Internet
Web server
Web server
Web server
Client
Client
Client
Client
Client
Client
Client
Web server
Web server
Servlet Server
EJB Server
Servlet Server
Servlet Server
EJB Server
DB Server
DB Server
Servlet Server
EJB Server
DB Server
Servlet Server
Servlet Server
EJB Server
EJB Server
EJB Server
DB Server
DB Server
DB Server
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

31

Web site Clustering


Load balancing on Web Servers


hardware: L4
-
switch


software


One
-
IP techniques


LVS (http://www.linuxvirtualserver.org/)


RR
-
DNS

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

32

Servlet/JSP Clustering


Web server to Servlet server


Load balancing with JK module (mod_jk)


Static weighted round
-
robin


Session affinity


Servlet/JSP server clustering


Tomcat in
-
memory session replication


failover ensured by mod_jk

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

33

EJB Clustering


Servlet/JSP to EJB server


clustered JNDI


load
-
balancing and failover by cluster
-
aware
stubs


EJB Server clustering


cluster stubs for load
-
balancing


transparent failover for idempotent methods


bean state persisted in database

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

34

J2EE Clustering


Database clustering


Commercial offers


Oracle RAC (60.000$ / cpu)


based on expensive SAN (Storage Area Network)


Open
-
source solutions


No real clustering


master/slave replication in MySQL


Postgres
-
R (still in alpha)

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

35

Database clustering


Performance scalability bounded by database


Large SMP are not commodity


Database tier must be


scalable


fault tolerant (high availability + failover)


without modifying the client application


using open source databases


on commodity hardware

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

36

RAIDb


Redundant Array of Inexpensive Databases

(RAIDb)


better performance and fault tolerance than a single database,


at a low cost,


by combining multiple DB instances into an array of DB.


RAIDb controller


gives the view of a single database to the client


balances the load on the database backends


RAIDb levels


RAIDb
-
0: full partitioning


RAIDb
-
1: full mirroring (best fault tolerance)


RAIDb
-
2: partial replication (best performance)

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

37

C
-
JDBC


Middleware implementing RAIDb


Two components


generic JDBC 2.0 driver (C
-
JDBC driver)


C
-
JDBC Controller


C
-
JDBC Controller provides


performance scalability


high availability


failover


caching, logging, monitoring, …


Supports heterogeneous databases

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

38

RAIDb with

Database
Database
C-JDBC Controller
Scalability - Fault tolerance - Failover -
Monitoring - Caching - Logging - ...
Database JDBC driver
Database
Database
Database
Database
JVM
Java client
program
Database
JDBC driver
JVM
EJB Container
JOnAS
, WebLogic,
JBoss, WebSphere, ...
Servlet container
Tomcat
, Jetty, ...
Database
JDBC driver
MySQL, PostgreSQL,
Oracle, DB2, InstantDB, ...
Database
JDBC driver
JVM
Java client
program
C-JDBC driver
JVM
EJB
Container

JOnAS
,
WebLogic, JBoss,
WebSphere, ...
Servlet
container

Tomcat
,
Jetty, ...
C-JDBC driver
C-JDBC
driver
JVM
MySQL, PostgreSQL, Oracle, DB2, InstantDB, ...
JVM
C-JDBC
No scalability
No fault tolerance
No failover
EJB
Container

JOnAS
,
WebLogic, JBoss,
WebSphere, ...
Servlet
container

Tomcat
,
Jetty, ...
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

39

C
-
JDBC RAIDb
-
1 example


no client code

modification


original PostgreSQL

driver and RDBMS

engine


C
-
JDBC provides

scalable performance

and high availability

PostgreSQL
PostgreSQL
C-JDBC Controller
RAIDb-1
PostgreSQL JDBC driver
PostgreSQL
Java client
program
C-JDBC driver
JVM
C-JDBC driver
C-JDBC
driver
JVM
JVM
EJB Container
JOnAS, WebLogic,
JBoss, WebSphere, ...
Servlet container
Tomcat, Jetty, ...
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

40

C
-
JDBC RAIDb
-
2 example


unload a single

Oracle DB with

several MySQL


add caching,

fault tolerance,

and monitoring

for free

MySQL
MySQL
C-JDBC Controller
RAIDb-2
MySQL JDBC driver
MySQL
Oracle
Java client
program
C-JDBC driver
JVM
C-JDBC driver
C-JDBC
driver
JVM
JVM
Oracle JDBC driver
EJB Container
JOnAS, WebLogic,
JBoss, WebSphere, ...
Servlet container
Tomcat, Jetty, ...
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

41

TPC
-
W Performance

0
200
400
600
800
1000
1200
1400
1600
0
1
2
3
4
5
6
Number of nodes
Throughput in requests per minute
Single DB
RAIDb-0
RAIDb-1
RAIDb-2
LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

42

Outline


Technologies


Performance


Clustering


Conclusion


LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

43

PHP, Servlets or J2EE ?


PHP: Apache


ideal for small projects


no typing, ad
-
hoc APIs


Servlets: Tomcat/Jetty


OO programming


JDBC for database access


J2EE: JOnAS/JBoss


for large projects


business and presentation logic isolation


large number of services


Clustering for scalability

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

44

Questions ?



Apache/PHP/Tomcat: http://www.apache.org


Jetty:
http://jetty.mortbay.com


JOnAS: http://jonas.objectweb.org/


JBoss: http://www.jboss.org


RUBiS: http://www.objectweb.org/rubis


LVS:

http://www.linuxvirtualserver.org



: http://c
-
jdbc.objectweb.org/

LinuxWorld 2003


San Francisco


Emmanuel.Cecchet@inria.fr

45

RUBiS


Overall results

0
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
Session Beans
EB-CMP
EB-BMP
Session
façade
EJB 2.0 Local
Maximum throughput in interactions/minute
JBoss - Standard RMI
JOnAS - Standard RMI
JBoss - Optimized RMI
JOnAS - Jeremie