Late 2008 I succeeded in persuading our database teacher to try out Glassfish for a new course on Web and Database programming for first year students. So before I knew it I was responsible for setting up a central Glassfish server for around 120 freshman programmers - UGH!
So how to best do this? This course has weekly lab-exercises and the teachers assistant need to grade them, so a distributed solution with a virtualbox image including netbeans and glassfish was not really the way forward - we needed a central server that the IT-dept. could maintain.
At DIKU we primarily use Gentoo Linux for our server park, so a standard HP DL360 G5 rack server was bought and a 64 bit version of Gentoo was installed from our customized Gentoo installation environment with Cfengine on top. Fortunately somebody had already made a Gentoo e-build package for Glassfish v2UR2, which easily could be updated. And within the hour I had a Glassfish server up and running - then the fun began - it needed configuration.
Our education environment is based on Sunray terminals, but uses Linux based application hosts. Our app-hosts had Eclipse installed, so at first I thought that Eclipse could be used to interact with the remote Glassfish-server, but NONONO! Our Eclipse was the basic Eclipse installation, which didn't support Java EE applications, so I tried installing the Eclipse Enterprise Edition which has a nice Glassfish plugin - but alas - this plugin only support a local installation of Glassfish and couldn't connect to a remote server, so I turned to Netbeans 6.5.
The full edition of Netbeans 6.5 did the trick, but STILL required a local installation of Glassfish for the plugin to connect to the remote host. OK - so far so good. Now the students should be able to connect to the server from within Netbeans and deploy their web-apps.
Then for the configuration of the server: 120 freshman programmers, which need to be able to run their web-apps without crashing the server or overwriting each others programs. I turned to the Sun Java System Application server 9.1 admin guide (which is Glassfish).
Glassfish has support for virtual hosts, so I was wondering whether just setting up 120 virtual hosts would do the trick. Unfortunately the Netbeans Glassfish plugin, does NOT (currently) support deployment to a specific virtual host, so each student had to be given his/her own Glassfish domain which include two dedicated ports - one for the admin interface and one to view the web-apps.
I ended up configuring each domain with the following setup:
I started /opt/glassfish/bin/asadmin in interactive mode and typed:
create-domain --user di080156 --adminport 11156 --instanceport 12156 di080156
Our student accounts are named di080XXX for the student year 2008/2009 where XXX is an increasing number. The UNIX UID for these accounts are always 11XXX where XXX is the same number as in the account name. So I chose that the adminport number should be the same as their UNIX UID, which can easily be looked up in the system by using the command
purps@ask ~/$ id di080156
uid=11156(di080156) gid=10000(del1user) groups=10000(del1user)
The instanceport number is the UNIX UID + 1000
The name of the domain is the same as the student account number, so when I do a 'list-domains' from asadmin, it will be clearly visible which domains might need to get started.
When creating a new domain an admin-user and an admin-password need to be set. The admin username will be the student account number, while the password will be db + the students birth date (DDMMYY) which I could easily pull from our central postgreSQL server.
Now it will be relatively easy for each student to remember the most important data (the servername, the admin-port, the username and the password) to connect to the Glassfish server through Netbeans:
Log on to DIKUs system from a sunray terminal
open a xterm with 'besthost bach'
open /opt/netbeans-6.5/bin/netbeans &
(wait while Netbeans starts)
Choose File | New Project...
Choose Java EE and the type of project
Choose a name and place for the project
Click on button Target Server - choose Add...
Server: Glassfish V2 - click Next
Platform Location: /opt/glassfish-v2ur2
Choose Register Remote Domain og choose Next
Host: glassfish.diku.dk
Port: enter your UNIX UID for your student account
Choose Next
Type Admin username: your di080xxx account name
Type Admin password: dbDDMMYY - where DDMMYY is your birthdate
Choose Finish
Tuning the Glassfish-server
Unfortunately starting 120 domains requires A HELL OF A LOT OF RAM. Each domain is by default started with 512 MB. Our server "only" had 20 GB RAM and 140 GB of swap, so I needed to decrease the RAM usage of each domains JVM. I found the document "Tuning your Glassfish - Performance Tips" presentation and went to /opt/glassfish/domains and for each domain I changed domain.xml from
<jvm-options>-Xmx512m</jvm-options>
to
<jvm-options>-Xms192m</jvm-options>
<jvm-options>-Xmx192m</jvm-options>
Afterwards each domain can be started with the command 'start-domain di080XXX' from asadmin, but after a while you don't want to start 120 domains manually, so a collegue of mine wrote a small script to start/stop all domains sequentially.
#!/bin/bash
ASADMIN=/opt/glassfish/bin/asadmin
DOMAINDIR=/opt/glassfish/domains
start_all(){
for DOMAIN in ${DOMAINDIR}/*; do
${ASADMIN} start-domain ${DOMAIN##*/}
done
}
stop_all(){
for DOMAIN in ${DOMAINDIR}/*; do
${ASADMIN} stop-domain ${DOMAIN##*/}
done
}
usage(){
cat <<-HERE
Usage: ${0} [command]
where command is one of
start start all domains
stop start all domains
restart first stop and then start all domains
HERE
}
case ${1} in
start)
start_all
;;
stop)
stop_all
;;
restart)
stop_all
start_all
;;
*)
usage
;;
esac
Now I am anxiously awaiting the students use of the server. The RAM usage is horrifying and it is swapping like crazy, and I am unsure if I should stuff even more physical RAM in the machine or try turning down the JVM RAM usage on each domain even more. Here is a snapshot of top:
top - 12:23:00 up 22:22, 2 users, load average: 1.55, 4.88, 4.06
Tasks: 212 total, 1 running, 211 sleeping, 0 stopped, 0 zombie
Cpu(s): 1.2%us, 0.3%sy, 0.0%ni, 79.3%id, 19.1%wa, 0.0%hi, 0.1%si, 0.0%st
Mem: 20600040k total, 20497768k used, 102272k free, 6736k buffers
Swap: 143338536k total, 18882040k used, 124456496k free, 18708k cached
Which user (blank for all):
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
23825 root 20 0 708m 166m 3820 S 1 0.8 1:49.27 java
7208 root 20 0 10560 1288 876 R 1 0.0 0:00.37 top
31804 root 20 0 784m 167m 3820 S 1 0.8 1:50.51 java
242 root 15 -5 0 0 0 D 0 0.0 4:08.55 kswapd0
394 root 20 0 706m 167m 3848 S 0 0.8 1:47.89 java
1537 root 20 0 787m 168m 3820 S 0 0.8 1:48.49 java

I think the lack of memory will be fatal to the user experience.
Why can't you set up some rules and share a domain across 10 people?
Each person would deploy/run an app with a different context root (app1,app2,...app3).
Do you really need complete isolation? (i.e for debugging, you would of course, but for executing, maybe not).
For debugging, you could allocate a specific domain that would be used only by 1 person at a time?
Posted by Ludo on February 24, 2009 at 06:49 PM CET #
Beside "Sun Java System Application server 9.1 admin guide", where else I can get more details for using GlassFish Domains?
I would like to use GlassFish as Internet Server, to server my static and dynamic pages. For that I need to map my internet domains to GlassFish Domains. Most of the material on internet only points to "Domain1", which is the default domain for GlassFish.
I appreiciate if you can share the experience/details you got while setting up your domains.
Posted by Domain on February 25, 2009 at 01:38 PM CET #
You can get much more info on Glassfish from:
https://glassfish.dev.java.net/
http://wiki.glassfish.java.net/
http://blogs.sun.com/theaquarium/
and all the documentation can be found here: http://docs.sun.com/app/docs/coll/1343.4
or after you install the glassfish server, its available directly from the administration website (http://localhost:4848 - login using admin as username and adminadmin as password).
The mapping/binding of your internet domain names to a specific server is done through the use of DNS (domain name service). A glassfish domain, is not a domain in that sense. Once you got your glassfish up and running, you can configure your nameserver to point to the glassfish website. This is not done directly on the Glassfish server unless your Glassfish server also runs as your nameserver. (see http://en.wikipedia.org/wiki/Domain_name_system for more info on DNS)
The rest of the setup (if you have several domains, and want them to map to different Glassfish domains), can be done using virtual hosts setup in Glassfish. There is a section on it in the admin guide.
There is a real nice Quick Start Guide for setting up your first glassfish server here:
https://glassfish.dev.java.net/downloads/quickstart/index.html
- it will have you up and running within 30 min.
Best,
Sidsel
Posted by Sidsel Jensen on February 25, 2009 at 02:21 PM CET #
I am using documentation collection for GlassFish 2.1 at http://docs.sun.com/app/docs/coll/1343.6
To me it appears there is much more in GlassFish Domains including clustering, high availability etc. However, at present I am trying to find ***best practices*** in using multiple GlassFish domains maped to multiple internet/intranet domains.
Posted by Domain on February 25, 2009 at 08:05 PM CET #
My suggestion would be for you to post your question at the official Glassfish users maillist <users@glassfish.dev.java.net>
There is an overview of all the Glassfish maillists at https://glassfish.dev.java.net/servlets/ProjectMailingListList
Also there is a good blog post on how to create new virtual hosts in Glassfish here: http://weblogs.java.net/blog/jfarcand/archive/2006/06/dynamically_add.html
Best,
Sidsel
Posted by Sidsel Jensen on February 25, 2009 at 09:35 PM CET #
As Ludo said, depending of your needs, you can have a small set of instances with more students each other deploying different application names. You also can configure different http listeners and virtual server associated with individual applications.
I have worked with similar scenario, and as long as you have some rules (deploy, naming, etc.), everything can work fine.
Claudio Miranda
Posted by Claudio Miranda on February 25, 2009 at 11:33 PM CET #
Hi Claudio
Perhaps you could - and I actually started out by trying to set up a virtual host for each student, but Netbeans does not currently support deployment to different virtual hosts, so that would mean either giving the students direct access to login to the server through ssh and using asadmin to deploy apps or that they should share a username/password to upload apps through the admin-interface. I wasn't really fond of either solution security-wise.
But its true the ram issue could pose a big problem - and Ludos suggestion for sharing a domain between several students is a possibility.
Best,
Sidsel
Posted by Sidsel Jensen on February 26, 2009 at 09:37 AM CET #
First of all, thank you for sharing us your work! A great work!
In these days I had to do the same thing at work, surely for less developers...
I've also needed to change the RAM usage, bringing it down to 128... we have different machine type: Pentium4 with 4GB of RAM :P
Anyway I'm here to tell/ask you that I'm going to copy your colleague script to automatically stop and start domains!!! :D
Kindly,
Luigi
Posted by Luigi on February 27, 2009 at 09:57 AM CET #