• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1363
  • Last Modified:

Two applications with -XX:+AggressiveHeap on same server

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
rstaveley
Asked:
rstaveley
  • 7
  • 7
1 Solution
 
Ajay-SinghCommented:
Try using -Xmx4000m in both servers - makes JVM to comsume max memory upto 4G
0
 
rstaveleyAuthor Commented:
> 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
 
rstaveleyAuthor Commented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Ajay-SinghCommented:
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
 
rstaveleyAuthor Commented:
Thanks, Ajay.
0
 
rstaveleyAuthor Commented:
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
 
Ajay-SinghCommented:
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
 
Ajay-SinghCommented:
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
 
rstaveleyAuthor Commented:
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
 
rstaveleyAuthor Commented:
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
 
Ajay-SinghCommented:
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
 
rstaveleyAuthor Commented:
> 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
 
Ajay-SinghCommented:
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
 
Ajay-SinghCommented:
> 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now