The reasons that so many people download and use MySQL and GlassFish are compelling. In addition to being open source, MySQL and GlassFish are fast, reliable, and easy to use. Though attractive individually, MySQL and GlassFish when used together provide an excellent solution for quickly developing and deploying web applications that are not only secure and reliable, but also scale to meet increasing demand and are highly responsive to user requests. This article, the first in a series of articles, covers the advantages of using MySQL with GlassFish and illustrates why the combination is a perfect choice for developing and deploying web applications. In future articles in the series, you'll see how easy it is to build web applications that take advantage of MySQL and GlassFish features. Although various versions of GlassFish and MySQL are available for download, this series of articles focuses on GlassFish v2 Update Release 2 (UR2) and MySQL 5.1 Community Server.
Contents
Many of the characteristics that make MySQL so successful also apply to GlassFish. This section briefly describes those characteristics. Open Source
The open-source license that applies to MySQL is the GNU General Public License (GPL). Through GPL, users can view the MySQL source code, change it, and share their changes with an active community of open source developers and enthusiasts. By participating in the MySQL open source community, users can get the latest community-based upgrades, bug fixes, and innovations.
As is the case for MySQL, GlassFish is open-source software. GlassFish source code is available under dual licenses: the Common Development and Distribution License (CDDL) and GPL Version 2 (GPL v2) plus Classpath exception. Users can choose the license that best fits their needs. Either of these open-source licenses allows users to access the GlassFish source code and customize it to meet their requirements. GlassFish too is supported by a large and active community. Many members of the community work on the GlassFish project, whose primary objective is developing the open-source GlassFish application server. In addition, the community participates in GlassFish subprojects, where they develop various technologies apart from the application server. Members of the GlassFish community don't necessarily develop code for the application server. By simply using the application server, they can file and track bugs and exchange information with other community members. Members of the GlassFish community have access to the latest community-based upgrades, bug fixes, and support. Easy to Download and Install
Although you can download and install MySQL and GlassFish individually, you can also download them in a single bundle that includes MySQL 5.0 Community Server and GlassFish v2ur1. After you download the bundle, you run a setup script to install GlassFish and MySQL Community Server. Then you configure MySQL. In this way, you can install both MySQL and GlassFish very quickly.
Easy to Use
MySQL supports ANSI standard SQL, the standard programming language for querying and managing relational databases. MySQL supports the same language and, in general, the same feature set as other databases that support the standard. So developers have an easy learning curve as they go from their previous database system to MySQL. Many developers find SQL an easy language to use because of its relatively straightforward syntax. In general, MySQL statements follow a "Do action To target " syntax, where action is the action you want to perform, and target is the target on which you want to perform the action. For example, to retrieve all the data in the
MySQL provides a client program called the MySQL monitor that allows users to enter SQL statements. To start the program you enter the
The MySQL monitor then displays the result of the query:
MySQL also offers a tool called the MySQL Query Browser that allows you to graphically build and manage queries. For example, Figure 1 shows the MySQL Query Browser user interface (UI). If a user drags the
Ease of use is also an important objective of GlassFish. In fact, ease of use is the primary objective of Java EE 5, the Java platform version that GlassFish fully implements. Because it is open source, GlassFish gives developers the flexibility to meet their needs. And by fully supporting the Java EE 5 standard, GlassFish provides the technical richness that's required to provide real-life solutions. It's this combination of characteristics that give developers true freedom. An important usability enhancement in the Java EE 5 platform is the use of annotations to mark objects -- or methods within objects -- as having particular characteristics or to inject dependencies on resources. Various Java EE 5 technologies implemented in GlassFish such as Java Servlet 2.5, JavaServer Faces (often referred to as JSF) 1.2, Enterprise JavaBeans (EJB) 3.0 -- which includes the Java Persistence API -- and web services technologies such as Java API for XML-Based Web Services (JAX-WS) 2.0 and Java Architecture for XML Binding (JAXB) 2.0, support the use of annotations. With annotations you can simplify the code for objects such as servlet classes, EJB bean classes, and web services implementation classes, enabling you to code these objects as Plain Old Java Objects (POJOs).
Resource-injection annotations replace a lot of the resource-related interactions that an object has to have with its container in the application server. For example, in the following code snippet, the
Other annotations eliminate a lot of the boilerplate code, such as XML deployment descriptors, that previously needed to be developed for objects such as EJB entity classes and web services implementation classes. For example, the following code snippet marks an EJB bean as a remote stateless session bean:
The Easy to Administer
SQL is not only an easy-to-use query language, it's also an easy-to-use data management language. You can use SQL statements to perform database administrative tasks such as creating a database, granting user access to a database, creating tables, and filling tables with data. For example, to create a database named
MySQL also includes a client program called To start the program, you enter the
MySQL also offers a graphical administrative tool called MySQL Administrator. The tool allows you to perform a variety of administrative tasks such as configuring a MySQL server and administering user accounts. It also displays critical "health" issues regarding the database server, such as the current, minimum, maximum, and average number of queries as well as the query cache hit rate. Figure 2 shows the MySQL Administrator page for viewing information about a MySQL user.
GlassFish also provides easy-to-use tools for administration. One is the intelligent command line interface (CLI). The other is the Admin Console. In general, you can perform almost any GlassFish-related administrative task on a GlassFish instance or cluster through the CLI or through the Admin Console. A cluster is a group of GlassFish v2 application server instances that can be managed and monitored as a single logical entity. The CLI is "intelligent" because it suggests alternative entries if you make an error when you enter a command. For example, the command to start a GlassFish domain is
the CLI suggests an alternative:
The Admin Console provides a graphical UI to administer GlassFish instances or clusters. Figure 3 shows the Common Tasks page in the Admin Console for a domain that is enabled for clustering.
Notice that buttons are displayed for tasks such as creating a new cluster, deploying a web application, and monitoring data. These buttons are supplemented by a navigation tree that gives you an alternate path to performing administrative tasks. To initiate an operational task, you simply click the appropriate button in the page or click a node in the tree. The Admin Console makes it particularly easy to monitor resources such as connection pools, that is, the cache of database connections maintained by the database, and also includes a call flow feature that makes it easy to track a transaction as it moves through various GlassFish application server containers. This is illustrated in Figure 4.
You can get plug-ins that enable you to integrate both MySQL and GlassFish with popular development tools such as the NetBeans IDE or the Eclipse IDE. In addition, the MySQL-GlassFish-NetBeans bundle integrates MySQL and GlassFish into NetBeans IDE 6.1. After MySQL and GlassFish are integrated into an IDE, you can use the IDE to easily register MySQL servers and perform administrative tasks such as view, create, and delete MySQL databases. You can then use the IDE to build applications that access those databases and deploy the applications on the GlassFish application server. IDEs such as NetBeans 6.1 include features that streamline the process of building web applications, including applications that use web services or that access persistent data. For example, you can take advantage of the JavaServer Faces create, read, update, and delete (CRUD) Generator in NetBeans IDE 6.1 to create a JavaServer Faces-based CRUD application from EJB entity classes, as shown in Figure 5.
In addition to their integration with popular IDEs, both MySQL and GlassFish can be used with popular open-source development frameworks such as Ruby on Rails, Spring, Struts, and Seam. Fast, Scalable, Reliable
MySQL offers scale-out capabilities that enable you to improve application performance and scalability incrementally and when you need it. MySQL Scale Out: The term scale out refers to an architectural design that separates and spreads the database workload across different physical servers. As demand increases, you can scale out by adding database servers on low-cost commodity hardware and spread the increased workload across the database servers. This strategy is in contrast to a scale-up approach, which requires a large up-front investment in more expensive and complex server hardware in order to add capacity. In a typical situation, users initiate sessions on web or application servers. These servers send requests as required into the MySQL database servers through load balancers or other application logic that directs the requests. When a request causes a server to write into the database, the server replicates its data to other MySQL servers to keep them up-to-date for subsequent queries. Figure 6 illustrates the scale-out architecture.
In high-availability, high-volume settings, a failure in any MySQL server is typically corrected by taking the failed server offline and swapping it for another server. In a few minutes, the database can be replicated on the new server, and query service can proceed as before. The low cost of commodity servers makes this swap-out strategy cost-effective. This scale-out design helps MySQL run very fast -- the MySQL database consistently scores among the top databases for performance and throughput -- and it also makes MySQL very reliable because redundancy is built into the design.
GlassFish -- High Performance and Reliability: GlassFish too scores consistently high for performance and throughput when compared to other application servers. In fact, recently GlassFish v2 posted the best open source result on SPECjAppServer 2004,1 -- an end-to-end application that exercises all major Java EE technologies implemented by compliant application servers -- for a pair of Sun Fire X4150 servers, each equipped with one Intel Xeon CPU. For details, see Open Source Leader in Application and Database tiers of SPECjAppServer 2004 benchmark. In general, GlassFish is the fastest open-source application server -- even outperforming most closed-source application servers, and is the industry's price-performance leader. In addition, the HTTP layer of the web tier in GlassFish, which is implemented through the Grizzly framework, takes advantage of the Java New I/O (NIO) APIs to scale to thousands of users. GlassFish ensures reliability through clustering and memory replication. As mentioned earlier, a cluster is a group of GlassFish v2 application server instances that you can manage and monitor as a single logical entity. Memory replication is an aspect of clustering. In memory replication, information about the state of user sessions with deployed applications in a GlassFish v2 instance is replicated to a peer instance in the cluster. Each GlassFish v2 instance in a cluster sends session-state information to the next instance in the cluster, its replication partner. As Figure 7 shows, if Instance 1 fails, the load balancer routes the sessions interacting with Instance 1 to another instance, here Instance 2. If the routed-to instance is the replication partner of the failed GlassFish instance, the sessions are handled there. But if the routed-to instance is not the replication partner, the replication partner transfers the replicated session data to the routed-to instance. In other words, if the load balancer routes the sessions to Instance 3, which is not the replication partner, then Instance 2, which is the replication partner, sends the state data to Instance 3 to handle the sessions.
You can place cluster instances and their replication partners on different machines to further increase availability. In this way, if one of the machines fails, session data is not lost. For more information on clustering and memory replication, see Clustering in GlassFish Version 2. Flexible Optimization
MySQL includes a pluggable storage engine layer in which it offers many different types of databases, each optimized for a specific type of processing. The storage engine layer is part of the MySQL storage architecture shown in Figure 8.
The pluggable storage layer gives you a lot of flexibility in choosing a database best suited for your needs. For example, if you're building a web site that requires high-speed reads and high-speed loads, but doesn't need support for transactions, you can take advantage of a MyISAM database, which is optimized for this type of processing. By comparison, if you're building a site that requires transactions, the InnoDB database is a good choice because of its atomicity, consistency, isolation, and durability (ACID) properties, which guarantee that database transactions are processed reliably. In addition, MySQL offers various types of databases from partners and from the community, each optimized for a particular type of processing. You can use multiple storage engines in a single application. This is particularly useful in a replication setup where a master copy of a database on one server is used to supply copies, called slaves, to other servers. A storage engine for a table in a slave can be different than a storage engine for a table in the master. In this way, you can take advantage of each engine's abilities. Only the MySQL database system offers this pluggable storage capability. Can Be Used in All Major Environments
MySQL is optimized for Windows, Solaris, and Linux and runs on all major operating systems and hardware. In fact, it's the "M" in the widely used LAMP (Linux, Apache Web Server, MySQL, and PHP) stack, as well as the SAMP (S=Solaris) and WAMP( W=Windows) stack. Similarly, GlassFish runs on all major operating systems and hardware, including Windows, Solaris, Linux, MacOS, and AIX. GlassFish v2UR2 offers many other features that make it very attractive for web application development and deployment. These features support the following:
Apache Tomcat is an open-source web container that runs Java servlets and JSP pages in web applications. Tomcat is popular in the open source community, and is often used with MySQL. However, it's important to understand that GlassFish can provide an even better open-source solution for web applications than Tomcat, and for many developers might be a better choice to use with MySQL. This section highlights some of the reasons why.
GlassFish provides a more extensive web technology implementation than Tomcat. Although Tomcat supports servlet and JavaServer Faces technology, GlassFish goes beyond that, supporting all Java EE 5 technologies, including the following:
In addition, GlassFish supports Web 2.0 technologies and methodologies such as jMaki and Comet. Because Tomcat is limited essentially to servlet and JSP technology, you have to install additional software if you want other web tier functionality, or if you want technology that is beyond the scope of the web tier. GlassFish is a full-fledged application server that implements all Java EE 5 technologies as well as Web 2.0 technologies. You do not need to install any additional software to take advantage of technologies and frameworks such as the following:
In addition, GlassFish offers Java EE 5-based ease-of-use features such as dependency injection that are not available in Tomcat. Better Administration Tools
Although Tomcat comes with a number of administration and monitoring tools, such as the Tomcat Web Application Manager, GlassFish provides more comprehensive and easier-to-use administration and monitoring tools. Users can perform almost any GlassFish-related administration task either from an intelligent CLI or from a web-based Admin Console. The Admin Console Common Tasks page presents buttons to initiate many of the more commonly performed tasks such as deploying a web application, so that these actions can be performed from a central point.
Significantly, the Admin Console is enabled for Java Management Extensions (JMX) technology through registered Management Beans (MBeans). This allows you to connect the Admin Console to other JMX tools such as Java Monitoring and Management Console (JConsole) and VisualVM for more extensive monitoring. In addition, you can extend GlassFish's administration and monitoring features by creating and registering your own custom MBeans. GlassFish monitoring facilities make it particularly easy to monitor resources such as connection pools. GlassFish also includes a call flow feature that makes it easy to track a transaction as it moves through various GlassFish application server containers. Better Performance
GlassFish, through its Grizzly framework, has better HTTP-related performance than Tomcat's Java-based HTTP connector, Coyote, and scales better to handle more requests than Tomcat. Because Tomcat is a web container and GlassFish is a full-fledged application server, their overall performance can't be directly compared. However, GlassFish is an extremely fast application server, as demonstrated by benchmarks such as SPECjAppServer,1. More Flexible Load Balancing
GlassFish, through its clustering capabilities, gives administrators more flexibility in terms of load balancing than Tomcat. In addition, clustering enables a high degree of reliability. If a GlassFish v2 instance in a cluster fails, the session interacting with that instance is rerouted to another instance in the cluster. Easy Migration Path
Last but not least, there is an easy migration path from Tomcat to GlassFish. An application that runs in Tomcat will run in GlassFish without modification. Easy to use, easy to administer, integrated with popular development tools, fast, scalable, reliable -- these are all characteristics that make MySQL the world's most popular open-source database. However, the very same characteristics also apply to GlassFish -- an open-source, enterprise-quality, Java EE 5-compliant application server. Those characteristics as well as GlassFish's comprehensive feature set make it an ideal choice to use with MySQL for developing and deploying web applications. In the next article in this series, you'll see how to take advantage of MySQL and GlassFish features to easily build a CRUD web application that accesses persistent data. 1SPEC and SPECjAppServer are registered trademarks of Standard Performance Evaluation Corporation. Results from www.spec.org as of 11/03/2008. 2xSun Fire X4150 (8 cores, 2chips) and 1xSun Fire X4150 (4 cores, 1 chip) 1197.10 SPECjAppServer2004 JOPS@Standard; Best result with 8 cores in application-tier of the benchmark: 1xHP BL460c (8 cores,2chips) and 1xHP BL480c (8 cores,2 chips) 2056.27 SPECjAppServer2004 JOPS@Standard; Best result with 2 systems in application-tier of the benchmark: 2xDell PowerEdge 2950 (8 cores, 2 chips) and 1xDell PowerEdge R900 (4 chips, 24 cores) 4,794.33 SPECjAppServer2004 JOPS@Standard. For More Information
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||