Solved

Two applications with -XX:+AggressiveHeap on same server

Posted on 2006-06-29
14
1,108 Views
Last Modified: 2012-06-27
I have two Java applications running as daemons on the same server, which match the description in http://java.sun.com/docs/hotspot/gc1.4.2/#4.2.2.%20AggressiveHeap|outline of being "long-running, memory allocation-intensive jobs".

I read:

> The size of the initial heap is calculated based on the size of the physical memory and attempts to make maximal use of the physical memory for the heap (i.e., the algorithms attempt to use heaps nearly as large as the total physical memory).

How can I get the JVM to attempt to use heaps nearly *half* as large as the total physical memory so I can get both of the applications running optimally? [There is 8G of RAM in the server.]
0
Comment
Question by:rstaveley
  • 7
  • 7
14 Comments
 
LVL 23

Expert Comment

by:Ajay-Singh
Comment Utility
Try using -Xmx4000m in both servers - makes JVM to comsume max memory upto 4G
0
 
LVL 17

Author Comment

by:rstaveley
Comment Utility
> Try using -Xmx4000m

Combined with -XX:+UseParallelGC, would that give me everything that -XX:+AggressiveHeap that I can benefit from for my two applications?
0
 
LVL 17

Author Comment

by:rstaveley
Comment Utility
Let me re-phrase that...

Combined with -XX:+UseParallelGC, would that give me everything from -XX:+AggressiveHeap setting that I can benefit from for my two applications?
0
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 250 total points
Comment Utility
sure it would. Since you are running 2 applications on the same server, try add option too

-XX:ParallelGCThreads=2

It would run 2 threads for parallel GC. By default it runs as many threads a number of cpus on the server.
0
 
LVL 17

Author Comment

by:rstaveley
Comment Utility
Thanks, Ajay.
0
 
LVL 17

Author Comment

by:rstaveley
Comment Utility
Curiously, looking at 39. in http://java.sun.com/docs/hotspot/gc1.4.2/faq.html I see...

Two application instances running on a large multi-processor server with 4gb of physical memory. Each java application instance is allocated a part of total system memory by an explicit specification of the maximum and minimum heap sizes.

      #java -server -XX:+AggressiveHeap -Xms1024m -Xmx1024m

It looks like I could combine -XX:+AggressiveHeap with -Xmx4000m after all?!
0
 
LVL 23

Expert Comment

by:Ajay-Singh
Comment Utility
I don't think so. Once the first application hits the limit (4G), the server would do a lot of swapping to allocate memory of another instance. Its recommended
1. start the server with same values of of -Xms and -Xmx
2. these values should be same or little lesser than size of RAM. In your case it would be good to allocate 2G for each application
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 23

Expert Comment

by:Ajay-Singh
Comment Utility
sorry about typo.
read
>limit (4G)
as limit(8G)
and

>good to allocate 2G for each application
as
good to allocate 4G for each application

0
 
LVL 17

Author Comment

by:rstaveley
Comment Utility
Yes in the FAQ example it was 4G and in my set up there is 8G.

In my 8G set-up, I could do:

nohup java -server -XX:+AggressiveHeap -Xms4000m -Xmx4000m rstaveley.App1 2> /dev/null > /dev/null &
nohup java -server -XX:+AggressiveHeap -Xms4000m -Xmx4000m rstaveley.App2 2> /dev/null > /dev/null &

...leaving 192MB of RAM for for other stuff on the server and get benefits from -XX:+AggressiveHeap, which i wouldn't otherwise get from simply using...

nohup java -server -XX:+UseParallelGC -Xms4000m -Xmx4000m rstaveley.App1 2> /dev/null > /dev/null &
nohup java -server -XX:+UseParallelGC -Xms4000m -Xmx4000m rstaveley.App2 2> /dev/null > /dev/null &

I'm happy to dedicate the RAM to my two applications.
0
 
LVL 17

Author Comment

by:rstaveley
Comment Utility
For the record, I'm using 5.0 and the maximum heap size is 1G - see http://java.sun.com/docs/hotspot/gc5.0/ergo5.html

nohup java -server -XX:+AggressiveHeap -Xms1024m -Xmx1024m rstaveley.App1 2> /dev/null > /dev/null &
nohup java -server -XX:+AggressiveHeap -Xms1024m -Xmx1024m rstaveley.App2 2> /dev/null > /dev/null &

My application ought to be able to live within 1G, but I'm curious that there is a 1G ceiling all the same.
0
 
LVL 23

Expert Comment

by:Ajay-Singh
Comment Utility
ya, thats default behaviour. But you can alter this by setting max amd min to your custom size

make sure that you add the following also:
-XX:ParallelGCThreads=2
0
 
LVL 17

Author Comment

by:rstaveley
Comment Utility
> ya, thats default behaviour. But you can alter this by setting max amd min to your custom size

How so? Presumably not with -Xms/-Xmx because 1024m is the maximum permitted according to http://java.sun.com/docs/hotspot/gc5.0/ergo5.html.

> -XX:ParallelGCThreads=2

I didn't follow the logic on this. The server has 4 logical CPUs (2 CPUs with hyperthreading). The automatic setting would be -XX:ParallelGCThreads=4 on the two applications, which seems sensible, because you may as well use any available CPU?
0
 
LVL 23

Expert Comment

by:Ajay-Singh
Comment Utility
On server-class machines by default the following are selected.
Throughput garbage collector
Heap sizes
initial heap size of 1/64 of physical memory up to 1Gbyte
maximum heap size of ¼ of physical memory up to 1Gbyte
Server runtime compiler

The article says this behaviour is by default. and -Xms/-Xmx DOES the magic.

0
 
LVL 23

Expert Comment

by:Ajay-Singh
Comment Utility
> I didn't follow the logic on this. The server has 4 logical CPUs (2
> CPUs with hyperthreading). The automatic setting would be
> -XX:ParallelGCThreads=4 on the two applications, which seems sensible,
> because you may as well use any available CPU?

GC is always CPU bound. So, if you set it to default(no of CPU in your box), then performance would degrade.
So, its good idea to divide equally.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now