450 likes | 455 Views
Explore the technologies and scalability of dynamic content web sites, including PHP, Java Servlets, JSP, and J2EE servers. Learn about performance, clustering, and more.
E N D
Dynamic Content Web Sites: Technologies & Scalability Emmanuel Cecchet emmanuel.cecchet@inria.fr
Dynamic content Web site • Web content is more and more dynamic
e-Commerce servers • Multi-tier architecture
Outline • Technologies • Performance • Clustering • Conclusion
PHP • Hypertext Preprocessor • Scripting language • Module integrated in Web server
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>
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
Java Servlets • Java based • Executes in a “Servlet Container” • JDBC: unified interface for database access
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; } } }
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
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>
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)
J2EE Servers • Java 2 Enterprise Edition • Separation of presentation and business logics
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
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
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)
Outline • Technologies • Performance • Clustering • Conclusion
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/
RUBiS – PHP & Servlets • Apache/PHP vs Apache/Tomcat
Design patterns: Servlets only • Presentation and business logic mixed Servlet Presentation Servlet logic Presentation Business logic logic Business logic Database Web container
Design patterns: Session Beans • Presentation and business logic separation Servlet Session bean Business Presentation logic logic Session bean Servlet Presentation Business Database logic logic Web container EJB container
Design pattern: Entity Beans • Data Access Objects separation with Entity Beans (BMP or CMP) Servlet Presentation Servlet logic Entity Bean Presentation Business logic logic Entity Bean Business logic Entity Database Bean EJB container Web container
Remote interface Communication layer Design patterns: Session façade • Façade session bean with EJB 1.1 Servlet Session facade Entity Presentation Business Bean logic logic Entity Session facade Bean Servlet Business Presentation Database Entity logic logic Bean Web container EJB container
Local interface Design patterns: EJB 2.0 local • Session façade with EJB 2.0 local interface Entity Beans Servlet Session facade Entity Presentation Business Bean logic logic Entity Session facade Bean Servlet Business Presentation Database Entity logic logic Bean Web container EJB container
RUBiS - J2EE Servers • Apache/Tomcat/JBoss vs Apache/Tomcat/JOnAS
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% cpuusage • Container design • Less than 2% of execution time in user bean code
Outline • Technologies • Performance • Clustering • Conclusion
Web site Clustering • Load balancing on Web Servers • hardware: L4-switch • software • One-IP techniques • LVS (http://www.linuxvirtualserver.org/) • RR-DNS
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
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
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)
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
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)
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
C-JDBC RAIDb-1 example • no client codemodification • original PostgreSQLdriver and RDBMSengine • C-JDBC providesscalable performanceand high availability
C-JDBC RAIDb-2 example • unload a singleOracle DB withseveral MySQL • add caching,fault tolerance,and monitoringfor free
Outline • Technologies • Performance • Clustering • Conclusion
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
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/