Download ppt - C-JDBC

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Dynamic Content Web Sites:
Technologies & Scalability
Emmanuel Cecchet
[email protected]
Dynamic content Web site
Web content is more and more dynamic
LinuxWorld 2003 – San Francisco – [email protected]
2
e-Commerce servers
Multi-tier architecture
Client
Internet
HTTP
SQL
Application
protocol
Web server
Application
server
LinuxWorld 2003 – San Francisco – [email protected]
Database
3
Outline
Technologies
Performance
Clustering
Conclusion
LinuxWorld 2003 – San Francisco – [email protected]
4
PHP
Hypertext Preprocessor
Scripting language
Module integrated in Web server
httpd
httpd
...
PHP
PHP
SQL
HTTP
Client
Web server
LinuxWorld 2003 – San Francisco – [email protected]
Database
5
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 – [email protected]
6
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 – [email protected]
7
Java Servlets
Java based
Executes in a “Servlet Container”
JDBC: unified interface for database access
Tomcat Servlet
container
h
h
t
t
t
t
...
p
p
d
d
JVM
AJP12
HTTP
Client
servlet
servlet
servlet
servlet
servlet
Web server
JDBC
Servlet
server
LinuxWorld 2003 – San Francisco – [email protected]
Database
8
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 – [email protected]
9
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 – [email protected]
10
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 – [email protected]
11
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 – [email protected]
12
J2EE Servers
Java 2 Enterprise Edition
Separation of presentation and business logics
Client
Internet
Web server
Presentation
logic
Web
container
Business
logic
EJB
container
Database
J2EE Application Server
LinuxWorld 2003 – San Francisco – [email protected]
13
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 – [email protected]
14
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 – [email protected]
15
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 – [email protected]
16
Outline
Technologies
Performance
Clustering
Conclusion
LinuxWorld 2003 – San Francisco – [email protected]
17
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 – [email protected]
18
RUBiS – PHP & Servlets
Apache/PHP vs Apache/Tomcat
LinuxWorld 2003 – San Francisco – [email protected]
19
JVM Performance
5000
IBM
Throughput in requests/minute
4500
4000
JRockit
Sun
3500
3000
2500
2000
1500
1000
500
0
200 220 240 260 280 300 320 340 360 380 400 420 440 460 480 500 520 540 560 580 600
Number of clients
LinuxWorld 2003 – San Francisco – [email protected]
20
Design patterns: Servlets only
Presentation and business logic mixed
Servlet
Presentation
Servlet logic
Presentation
Business
logic
logic
Business
logic
Database
Web container
LinuxWorld 2003 – San Francisco – [email protected]
21
Design patterns: Session
Beans
Presentation and business logic separation
Servlet
Presentation
logic
Servlet
Presentation
logic
Web container
Session bean
Business
logic
Session bean
Business
logic
Database
EJB container
LinuxWorld 2003 – San Francisco – [email protected]
22
Design pattern: Entity Beans
Data Access Objects separation with Entity
Beans (BMP or CMP)
Servlet
Servlet
Presentation
logic
Presentation
logic
Entity
Bean
Business
logic
Business
logic
Web container
Entity
Bean
Entity
Bean
Database
EJB container
LinuxWorld 2003 – San Francisco – [email protected]
23
Design patterns: Session
façade
Façade session bean with EJB 1.1
Remote interface
Servlet
Presentation
logic
Servlet
Presentation
logic
Web container
Session facade
Entity
Bean
Business
logic
Entity
Bean
Session facade
Business
logic
Entity
Bean
Database
EJB container
Communication layer
LinuxWorld 2003 – San Francisco – [email protected]
24
Design patterns: EJB 2.0 local
Session façade with EJB 2.0 local interface
Entity Beans
Local interface
Servlet
Presentation
logic
Servlet
Presentation
logic
Web container
Session facade
Entity
Bean
Business
logic
Entity
Bean
Session facade
Business
logic
Entity
Bean
Database
EJB container
LinuxWorld 2003 – San Francisco – [email protected]
25
Code complexity
14000
Business logic
12000
Presentation logic
Lines of code
10000
8000
6000
4000
2000
0
PHP
Servlets- Session EB CMP EB BMP Session EJB 2.0
only
beans
façade
local
LinuxWorld 2003 – San Francisco – [email protected]
26
RUBiS - J2EE Servers
Apache/Tomcat/JBoss vs Apache/Tomcat/JOnAS
Maximum throughput in requests/minute
10000
9000
Optimized JBoss
8000
Optimized JOnAS
7000
6000
5000
4000
3000
2000
1000
0
Session Beans
EB-CMP
EB-BMP
LinuxWorld 2003 – San Francisco – [email protected]
Session façade
EJB 2.0 Local
27
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 – [email protected]
28
Outline
Technologies
Performance
Clustering
Conclusion
LinuxWorld 2003 – San Francisco – [email protected]
29
Clustering
Servlet Server
EJB Server
DB Server
Servlet Server
EJB Server
DB Server
Servlet Server
EJB Server
DB Server
Servlet Server
EJB Server
DB Server
Servlet Server
EJB Server
DB Server
Servlet Server
EJB Server
DB Server
Client
Client
Web server
Client
Web server
Internet
Web server
Client
Web server
Client
Client
Web server
Client
LinuxWorld 2003 – San Francisco – [email protected]
30
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 – [email protected]
31
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 – [email protected]
32
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 – [email protected]
33
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 – [email protected]
34
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 – [email protected]
35
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 – [email protected]
36
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 – [email protected]
37
RAIDb with
Servlet
container
Servlet
container
Tomcat,
Servlet container
Jetty,
... ...
Tomcat
, Jetty,
Database
JDBC driver
JVM
EJB
Container
JOnAS,
Java client
program
EJB Container
WebLogic, JBoss,
JOnAS, WebLogic,
WebSphere,
... ...
JBoss,
WebSphere,
C-JDBC
driver
Database
JDBC driver
Java client
program
Database
JDBC driver
JVM
Jetty, ...
EJB
Container
C-JDBC driver
JOnAS,
JVM
WebLogic, JBoss,
WebSphere, ...
Tomcat,
C-JDBC Controller
C-JDBC
Database
MySQL, PostgreSQL,
Oracle, DB2, InstantDB, ...
JVM
JVM
JVM
No scalability
No fault tolerance
No failover
C-JDBC driver
Scalability - Fault tolerance - Failover Monitoring - Caching - Logging - ...
Database JDBC driver
Database Database Database Database Database
MySQL, PostgreSQL, Oracle, DB2, InstantDB, ...
LinuxWorld 2003 – San Francisco – [email protected]
38
C-JDBC RAIDb-1 example
Servlet container
Tomcat, Jetty, ...
no client code
modification
original PostgreSQL
driver and RDBMS
engine
C-JDBC provides
scalable performance
and high availability
C-JDBC driver
Java client
program
JVM
EJB Container
JOnAS, WebLogic,
JBoss, WebSphere, ...
C-JDBC driver
C-JDBC
driver
JVM
JVM
C-JDBC Controller
RAIDb-1
PostgreSQL JDBC driver
PostgreSQL
LinuxWorld 2003 – San Francisco – [email protected]
PostgreSQL
PostgreSQL
39
C-JDBC RAIDb-2 example
Servlet container
unload a single
Oracle DB with
several MySQL
add caching,
fault tolerance,
and monitoring
for free
Tomcat, Jetty, ...
C-JDBC driver
Java client
program
EJB Container
JOnAS, WebLogic,
JBoss, WebSphere, ...
JVM
C-JDBC driver
C-JDBC
driver
JVM
JVM
C-JDBC Controller
RAIDb-2
Oracle JDBC driver
MySQL JDBC driver
MySQL
MySQL
MySQL
Oracle
LinuxWorld 2003 – San Francisco – [email protected]
40
Throughput in requests per minute
TPC-W Performance
1600
1400
1200
Single DB
1000
RAIDb-0
800
RAIDb-1
600
RAIDb-2
400
200
0
0
1
2
3
4
5
6
Num ber of nodes
LinuxWorld 2003 – San Francisco – [email protected]
41
Outline
Technologies
Performance
Clustering
Conclusion
LinuxWorld 2003 – San Francisco – [email protected]
42
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 – [email protected]
43
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 – [email protected]
44
RUBiS – Overall results
Maximum throughput in interactions/minute
10000
JBoss - Standard RMI
9000
JOnAS - Standard RMI
8000
JBoss - Optimized RMI
7000
JOnAS - Jeremie
6000
5000
4000
3000
2000
1000
0
Session Beans
EB-CMP
EB-BMP
LinuxWorld 2003 – San Francisco – [email protected]
Session
façade
EJB 2.0 Local
45
Related documents