Under the hood of GlassFish v2 Clustering

5
Under the hood of GlassFish v2 Clustering Tuesday Jun 05, 2007 from Nazrul's Blog GlassFish V2 is a production-ready Java EE 5 application server currently in beta. There was a lot of interest about GlassFish this year during JavaOne . I had a chance to talk to many customers interested in GlassFish. Some were already using Sun's distribution and dealing with very large deployments. In this blog, I will share few tricks and tips that may come in handy while dealing with GlassFish V2. First, a quick re-cap. GlassFish V2 has support for profiles (OnePager , blog - [1], [2]) where the server install ation is co nfigured for different usage. Three profiles are available by default: developer , cluster , and enterprise. Developers would typically work with a single Java EE server instance and use the developer profile. Cluster and enterprise profiles are targeted for deployments. A typical GlassFish V2 installation [in cluster or enterprise profile] consists of one or more administration domain. A domain provides a common authentication and ad ministration point for a collection of Java EE server instances. Domain Administration Server (DAS) handles all the administrative operations in a domain. Each remote machine [in cluster o r enterprise profile] has a light weight process called Node Agent . DAS interacts with the Node Agent to manage the life-cycle operations (create, delete , start, stop) in a remote machine. Nod e Agents and remote Java EE server instances synchronizes with DAS during startup to get the latest configuration from central repository managed by DAS . GlassFish V2 supports the concept of cluster where multiple Java EE server instances can be grouped for horizontal scalability. GlassFish V2 also supports in-memory replication feature where state of a dep loyed application is replicated to a peer in the cluster and thus enables the application to be highly available. E ach Java EE server ins tance in a cluster shares the same set of applications and configuration information. To summarize, GlassFish V2 offers enterprise features such as clustering (screencast, blog ), high availability (screencast), and load balancing ( GF page, blog) to support highly scalable, vo lume enterprise deployments for service-oriented architecture (SOA) and Web 2.0 applications. Refer to GlassFish V2 architecture wiki and JavaOne session T S-4436: T echnical Overview of GlassFish v2 (abstract, blog) for more details. Q: Does GlassFish V2 support hot deployment to a cluster?  Yes, GlassFish V2 offers multi-phase deployment to cluster and minimizes deployment related failures to distributed machines. Use the --target option in asadmin deploy command (example, %asadmin deploy --target cluster1 foo.war ) or t he Administration Console. Deployment is

Transcript of Under the hood of GlassFish v2 Clustering

Page 1: Under the hood of GlassFish v2 Clustering

8/7/2019 Under the hood of GlassFish v2 Clustering

http://slidepdf.com/reader/full/under-the-hood-of-glassfish-v2-clustering 1/5

Under the hood of GlassFish v2 Clustering 

Tuesday Jun 05, 2007 from Nazrul's Blog

GlassFish V2 is a production-ready Java EE 5 application server currently in beta. There was alot of interest about GlassFish this year during JavaOne. I had a chance to talk to manycustomers interested in GlassFish. Some were already using Sun's distribution and dealing withvery large deployments. In this blog, I will share few tricks and tips that may come in handywhile dealing with GlassFish V2.

First, a quick re-cap. GlassFish V2 has support for profiles (OnePager ,blog - [1], [2]) where the server installation is configured for differentusage. Three profiles are available by default: developer , cluster , andenterprise. Developers would typically work with a single Java EE server 

instance and use the developer profile. Cluster and enterprise profiles aretargeted for deployments.

A typical GlassFish V2 installation [in cluster or enterprise profile] consists of one or moreadministration domain. A domain provides a common authentication and administration point for a collection of Java EE server instances. Domain Administration Server (DAS) handles all theadministrative operations in a domain.

Each remote machine [in cluster or enterprise profile] has a light weight process called Node

Agent . DAS interacts with the Node Agent to manage the life-cycle operations (create, delete,start, stop) in a remote machine. Node Agents and remote Java EE server instances synchronizes 

with DAS during startup to get the latest configuration from central repository managed by DAS .

GlassFish V2 supports the concept of cluster where multiple Java EE server instances can begrouped for horizontal scalability. GlassFish V2 also supports in-memory replication featurewhere state of a deployed application is replicated to a peer in the cluster and thus enables theapplication to be highly available. Each Java EE server instance in a cluster shares the same setof applications and configuration information.

To summarize, GlassFish V2 offers enterprise features such as clustering (screencast, blog), highavailability (screencast), and load balancing (GF page, blog) to support highly scalable, volumeenterprise deployments for service-oriented architecture (SOA) and Web 2.0 applications. Refer 

to GlassFish V2 architecture wiki and JavaOne sessionT 

S-4436:T 

echnical Overview of GlassFish v2 (abstract, blog) for more details.

Q: Does GlassFish V2 support hot deployment to a cluster? 

Yes, GlassFish V2 offers multi-phase deployment to cluster and minimizes deployment relatedfailures to distributed machines. Use the --target option in asadmin deploy command (example,%asadmin deploy --target cluster1 foo.war ) or the Administration Console. Deployment is

Page 2: Under the hood of GlassFish v2 Clustering

8/7/2019 Under the hood of GlassFish v2 Clustering

http://slidepdf.com/reader/full/under-the-hood-of-glassfish-v2-clustering 2/5

dynamic; i.e., deployed application bits are transferred automatically to the remote server instances. You don't need to restart the cluster after deploying an application. V2 also offersother deployment features such as auto-deploy, directory deploy, ant integration (blog),NetBeans Integration, etc. Refer to deployment documentation for more details.

Q: I s it possible to deploy the same application tomultiple clusters? 

Yes. Use asadmin create-application-ref (example,%asadmin create-application-ref --target cluster2

myApp ) and asadmin delete-application-ref commandswith --target option in CLI or manage target for thedeployed application in Administration Console.

Q: I s there a way to start a remote server instance when DAS is not running? 

Yes, you may use the startserv/stopserv scripts under the bin directory (blog) or re-start the nodeagent. asadmin start-node-agent command will automatically start the remote server instanceswithout synchronizing with DAS.

Q: H ow do I  force a full synchronization of a remote server instance? 

A hidden file named .com_sun_appserv_timestamp keeps track of the last successfulsynchronization time of DAS. If you remove these files manually (not an official interface) under the remote server instance(s), a full synchronization will happen during the next server re-start. If synchronization fails for any reason, these files are automatically removed to force a fullsynchronization. In GlassFish V2, significant improvement was made in synchronization

performance (~40% - your mileage may vary).

The configuration under remote instances are treated as cache (for example, all files under nodeagents/na1/server1). In extreme cases, if you remove all files of a remote server instance andrestart the node agent, the remote server instance (for example, server1) will be recreated and allnecessary files will be synchronized. Refer to synchronization documentation for more details.

Q: I s there a way to backup/clone DAS so that it is not a single point of failure for 

management? 

DAS has no role in application runtime functionality. So, when DAS is un-available, the cluster 

will continue to run. You may use %asadmin backup-domain command to create a backup of DAS . After that, please backup the zip from backup-domain command in a highly availablestorage. When /if DAS 's machine crashes, you may use %asadmin restore-domain commandwith the previously backed-up zip to restore the domain in another machine. During DAS 'sstartup, it will ping all the node agents to notify the new co-ordinates of DAS . Solaris [Sun]Cluster has support for Sun Java System Application Server . You may use it to provideautomatic failover. Refer to this documentation for more details.

Page 3: Under the hood of GlassFish v2 Clustering

8/7/2019 Under the hood of GlassFish v2 Clustering

http://slidepdf.com/reader/full/under-the-hood-of-glassfish-v2-clustering 3/5

Q: I s there a way to specify machine specific JVM options for a server instance in a cluster? 

Yes. You may use tokens (${token}) in the config element for a cluster and define the tokenproperty with different values for different server instance. Refer to administration reference guide for more details. Here is a quick example where we are setting max heap size for a server 

instance that is part of a cluster .

<domain ...><applications>...</applications><resources>...</resources>

<configs><config ... name="cluster1-config">...<java-config ...>

<jvm-options>${MAX_HEAP_SIZE}</jvm-options></java-config></config>

</configs>

<servers><server ... config-ref="cluster1-config"

name="server1"><system-property name="MAX_HEAP_SIZE" value="-

Xmx512m"/></server>

</servers>

<clusters>...</clusters><node-agents>...</node-agents>

<lb-configs>...</lb-configs><load-balancers>...</load-balancers>

</domain>

Q: I s it possible to specify JNDI name at cluster scope? For example, is it possible to use two

different connection pools for an application that is deployed to two clusters? 

Yes. You may use the same tokenization strategy described above. Create a token for JDBCresource pool name and then specify the token property with desired (different) values for thetwo clusters. When application code looks up the JNDI name, it will end up connecting to two

different database pools for the two different clusters. For example,

<jdbc-resource ... jndi-name="jdbc/db" pool-name="${POOL_NAME}">

<cluster ... name="cluster1"><system-property name="POOL_NAME" value="DerbyPool"/>

</cluster><cluster ... name="cluster2">

Page 4: Under the hood of GlassFish v2 Clustering

8/7/2019 Under the hood of GlassFish v2 Clustering

http://slidepdf.com/reader/full/under-the-hood-of-glassfish-v2-clustering 4/5

<system-property name="POOL_NAME" value="MySQLPool"/></cluster>

Q: Say, I am dealing with a large

deployment involving many clusters

with multiple server instances (> 30). I s

there a way to optimize DAS's foot-

print? 

During the cluster creation, instead of cloning the config for each cluster , use a reference to anexisting config (example, cluster1-config). If you need to customize a value, use tokens anddefine them in each cluster . This will reduce the overall memory foot-print. Also, avoiddeploying the applications to DAS (on Administration Console, target named server )unnecessarily. You may consider creating new domains (%asadmin create-domain) whenappropriate.

Q: I s there a way share a library across a cluster? 

Yes. If you copy the library jar under the cluster's config/lib directory (example,domains/domain1/config/cluster1-config/lib), the library will be available cluster wide. You willneed to update the classpath-prefix or classpath-suffix. Refer to Sivakumar's blog for moreclassloader related issues. According to Siva's blog, library jars can be shared at domain andapplication scope also in GlassFish V2.

  domains/domain1/lib - domain wide scope, common classloader add thejars automatically

  domains/domain1/config/cluster1-config/lib - config wide, update

classpath-prefix or classpath-suffix  domains/domain1/lib/applibs - application scope, added to application

class loader automatically  domains/domain1/config/cluster1-config/lib/ext - adds to java.ext.dirs

automatically

Q: Do you need special packaging of applications to use them in cluster? 

No. Application code level changes are not needed. GlassFish V2 offers in-memory replicationfor high-availability with almost zero configuration also.

Q: I s it possible to install different versions on the same machine?  

For GlassFish, this is not an issue. For SJS AS 9.1, you may also use the filebased installer. For native package based installation, SJS AS 8.x will be upgraded to SJS AS 9.1 on the samemachine.

Q: Do you have support for monitoring? 

Page 5: Under the hood of GlassFish v2 Clustering

8/7/2019 Under the hood of GlassFish v2 Clustering

http://slidepdf.com/reader/full/under-the-hood-of-glassfish-v2-clustering 5/5

GlassFish V2 offers a wide range of monitoring statistics. Statistics on server log, server runtime,deployed applications, resources and transactions are available. Refer to the following blogs ([1],[2]) for more details. Call Flow (tech tip) allows you to find out how a particular applicationresponse is being processed across different containers of the Application Server. Web servicesmonitoring is also available (article) along with new improvements in CLI (blog) for 

mornitoring.

Q: Do you have any support for large data center deployments? 

Yes, you may use N1 Service Provisioning System with SJS AS. We are working on a newplugin for SJS AS 9.1 (Sun's distribution of GlassFish V2) also.