HomeProductsFAQEvaluationOrderCustomer Area

Combined RSS feed for site. RSS Feed

Plugin Smithy Software Blog


Setting up GlassFish on a Virtuozzo vServer

This website is running on GlassFish, inside a Virtuozzo virtual server ("vServer"). The vServer is the medium-level vServer offering of the hosting company, with 400 MB of physical RAM guaranteed, and with a maximum RAM allocation of 2000 MB.

When I selected this vServer type, I thought there is no question that a low-volume website can be set up with GlassFish on it. I had selected a Debian image and installed a Sun 1.5 JDK, and then much to my surprise I couldn't even execute the Java virtual machine (JVM):

gtest@v32295:~$ java
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

Restricting the heap size helped, and "-showversion" showed that the Server VM was selected:

gtest@v32295:~$ java -Xmx64m -showversion
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode)
...
It appeared strange to me that the Server VM was selected, but after reading the JDK 6 documentation about the java command which references the description of the Server-Class Machine Detection
I examined the environment under Virtuozzo. And while the specs said that there are only 2000 MB maximum RAM available to the vServer, the operating system reports obviously numbers for the physical machine itself:
gtest@v32295:~$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 37
model name : AMD Opteron(tm) Processor 248
stepping : 1
cpu MHz : 548.443
cache size : 1024 KB
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt lm 3dnowext 3dnow
pni lahf_lm
bogomips : 4393.82
TLB size : 1088 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp

processor : 1
vendor_id : AuthenticAMD
cpu family : 15
model : 37
model name : AMD Opteron(tm) Processor 248
stepping : 1
cpu MHz : 548.443
cache size : 1024 KB
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt lm 3dnowext 3dnow
pni lahf_lm
bogomips : 4386.88
TLB size : 1088 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp
gtest@v32295:~$ cat /proc/meminfo
MemTotal: 49909364 kB
MemFree: 49426572 kB
Buffers: 0 kB
Cached: 0 kB
SwapCached: 0 kB
Active: 0 kB
Inactive: 0 kB
HighTotal: 33551744 kB
HighFree: 33551744 kB
LowTotal: 16357620 kB
LowFree: 15874828 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 0 kB
Writeback: 0 kB
Mapped: 482792 kB
Slab: 0 kB
CommitLimit: 0 kB
Committed_AS: 1477616 kB
PageTables: 0 kB
VmallocTotal: 0 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB

As the operating system reports two processors and a lot more RAM than 2 GB, the JVM thinks that this is a "server-class" machine. What does that mean for the Java heap allocation? According to the Garbage Collector Ergonomics, without explicit specification the initial heap size will be "Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum", so in our case this would be  49909364/64 kB = approx. 779833 kB . The maximum heap size would be set to "Smaller of 1/4th of the physical memory or 1GB", so this should be 1 GB in our case.

These values are obviously too high for the given Virtuozzo environment. For the GlassFish installation this means that the maximum heap size must be specified explicitly in all places where the "java" command is executed.

Let's walk through the GlassFish installation process, along the guidelines in the GlassFish Project - V2 UR1 Final Build download web page:

  1. Extracting the GlassFish download file went fine, as the installation instructions tell you anyway to specify the maximum heap size when invoking the java command.
  2. The first problem came up when trying to run the Ant script that is supposed to set up GlassFish:
    gtest@v32295:~/glassfish$ lib/ant/bin/ant -f setup.xml
    Buildfile: setup.xml

    all:
        [mkdir] Created dir: /home/gtest/glassfish/bin

    get.java.home:

    setup.init:

    check-java:

    get.java.home:

    setup.init:

    validate-java: [echo] Current Java Version 1.6.0_3

    BUILD FAILED
    /home/gtest/glassfish/setup.xml:156: The following error occurred while
    executing this line:
    /home/gtest/glassfish/setup.xml:137: Execute failed: java.io.IOException:
    java.io.IOException: Cannot allocate memory


    The solution was to modify the "lib/ant/bin/ant" script that launches Ant, adding a flag for the maximum heap size:

    ant_exec_command="exec \"$JAVACMD\" -Xmx64m $ANT_OPTS -classpath "$LOCALCLASSPATH" -Dant.home=\"$ANT_HOME\" -Dant.library.dir=\"$ANT_LIB\" $ant_sys_opts org.apache.tools.ant.launch.Launcher $ANT_ARGS -cp \"$CLASSPATH\" $ant_exec_args"
  3. This change makes the script run a little bit longer. This time it will fail in a later step:

    gtest@v32295:~/glassfish$ lib/ant/bin/ant -f setup.xml

    create.domain:
    [exec] Using port 4848 for Admin.
    [exec] Using port 8080 for HTTP Instance.
    [exec] Using port 7676 for JMS.
    [exec] Using port 3700 for IIOP.
    [exec] Using port 8181 for HTTP_SSL.
    [exec] Using default port 3820 for IIOP_SSL.
    [exec] Using default port 3920 for IIOP_MUTUALAUTH.
    [exec] Using default port 8686 for JMX_ADMIN.
    [exec] Domain being created with profile:developer, as specified by
    variable AS_ADMIN_PROFILE in configuration file.
    [exec] Security Store uses: JKS
    [exec] java.io.IOException: Cannot allocate memory
    [exec] CLI130 Could not create domain, domain1

    BUILD FAILED
    /home/gtest/glassfish/setup.xml:172: The following error occurred while executing this line:
    /home/gtest/glassfish/setup.xml:561: exec returned: 1

    This time the invocation of the "asadmin" command failed. The problem is that the "asadmin" command is generated during the Ant run, so it cannot be fixed upfront. So after the script stops with the error message above, I edited the java invocation in the "bin/asadmin" command (line is shortened) and added the "-Xmx64m" option:

    "$AS_JAVA"/bin/java -Xmx64m -Dcom.sun.aas.instanceName=server -Djava.library.path="$AS_NSS":"$AS_INSTALL/lib":"$AS_ICU_LIB" -Dcom.sun.aas.configRoot="$AS_CONFIG" ...

After making these adjustments to the various scripts, GlassFish could be started successfully, and it is running without problems so far. Note that these changes to the scripts do not affect the actual JVM settings that can be adjusted inside the GlassFish admin console.


« February 2012
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
   
       
Today