aspose file tools*
The moose likes Performance and the fly likes Increase JVM size for thread creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Increase JVM size for thread creation " Watch "Increase JVM size for thread creation " New topic
Author

Increase JVM size for thread creation

pravin gate
Greenhorn

Joined: Feb 20, 2012
Posts: 10
I have 2 tasks in which I am using multithreading, in which one task is short task like login other is longer such as file transfer.

So is it there any way where I can provide small amount of jvm (thread) memory for small tasks and good amount of memory for large tasks.

For both tasks I have separate servers.

I have heard that we can increase size of java heap space .

Suppose I have a 2 GB memory RAM, So can I allocate 2 GB or 1.5 GB to my heap memory? I s it good way. What are positive and negative facts are there regarding it?

when and how should I use these JVM command line options -Xms and -Xmx for which kind of applications?


Any suggestions will be helpful.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8010
    
  22

pravin gate wrote:So is it there any way where I can provide small amount of jvm (thread) memory for small tasks and good amount of memory for large tasks.

You can certainly allocate more memory for a JVM (in several ways), but I'm not sure whether that include limits per Thread (never tried).

However, I'm not sure that either task you list is going to be affected much by throwing memory at it. As you say, the login task is small, and the file transfer task is likely to be limited by the speed of the connection rather than the amount of available memory. In fact, if it was me, I think I might be looking at limiting the amount of memory available to a file transfer process rather than expanding it, simply because it might be hanging around for a long time; however, I think I'd probably use a mechanism like a blocking queue to do it, rather than mucking about with startup params.

My advice would be to do profiling to find out
(a) Whether you really do have a problem, and
(b) Exactly where it is.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
pravin gate
Greenhorn

Joined: Feb 20, 2012
Posts: 10
ok. So here I have created a Test application from which I am able to login(means creating connections to a singke port) number of users.
But after connecting 3000+ users , program giving me Outofflowmemory memory heap space exceptions.

I was trying to increase memory heap size like this way in java runtime settings :-Xms200m -Xmx500m.
But still I am not able to connect more users than 3000+users.

Why is it so? What should I need to do ?

Winston Gutkowski wrote:
pravin gate wrote:So is it there any way where I can provide small amount of jvm (thread) memory for small tasks and good amount of memory for large tasks.

You can certainly allocate more memory for a JVM (in several ways), but I'm not sure whether that include limits per Thread (never tried).

However, I'm not sure that either task you list is going to be affected much by throwing memory at it. As you say, the login task is small, and the file transfer task is likely to be limited by the speed of the connection rather than the amount of available memory. In fact, if it was me, I think I might be looking at limiting the amount of memory available to a file transfer process rather than expanding it, simply because it might be hanging around for a long time; however, I think I'd probably use a mechanism like a blocking queue to do it, rather than mucking about with startup params.

My advice would be to do profiling to find out
(a) Whether you really do have a problem, and
(b) Exactly where it is.

Winston
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8010
    
  22

pravin gate wrote:ok. So here I have created a Test application from which I am able to login(means creating connections to a singke port) number of users.
But after connecting 3000+ users , program giving me Outofflowmemory memory heap space exceptions.

Are you sure this is a Java message, or are you, for example, logging in to a database?

I've seen references to 'flow memory' from the latter, but never from Java itself.

It would be a lot better if you include the entire message (or, indeed, the entire stack trace) exactly as you are getting it.

Winston
pravin gate
Greenhorn

Joined: Feb 20, 2012
Posts: 10
This exception I am getting when I am trying to connect 4000 users to single port (means 4000 users will be logged in after successful login) .


And I am also printing Rutimefree memory of heap size which shows latest value 5328 before exception.
I am able to connect (login) around 3000 users without any exception.

So what should I need to do to login more users?

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8010
    
  22

pravin gate wrote:This exception I am getting when I am trying to connect 4000 users to single port (means 4000 users will be logged in after successful login) .

Port, schmort - shouldn't make a whit of difference (except that you may be taxing a particular bit of inetd (or whatever the port listener du jour is these days)).

Also: nothing to do with 'flow memory'; or so it would seem.

The only thing I see is that there are an awful lot of what look like Swing or AWT methods involved. Any particular reason for that? It may be perfectly reasonable, but is it possible that you're retaining more than just the login credentials from your process?

Fraid I'm no expert when it comes to GUI apps, but 4,000 logins sounds pretty reasonable to me, even if they aren't doing anything. I've worked on some medium size servers that didn't allow that many user logins.

Apart from twiddling with the heap size, I can't suggest much more; if a 10% increase allows you 10% (or roundabout) more logins, I suspect you've found your bottleneck.

Winston
pravin gate
Greenhorn

Joined: Feb 20, 2012
Posts: 10
Ok.Thanks Winston for your helpful suggestions.

I also tried to increase Jvm heap size (-Xms and -Xmx.) But It's not showing me any effects on output.I am still not able to login 4000 users.


Winston Gutkowski wrote:
pravin gate wrote:This exception I am getting when I am trying to connect 4000 users to single port (means 4000 users will be logged in after successful login) .

Port, schmort - shouldn't make a whit of difference (except that you may be taxing a particular bit of inetd (or whatever the port listener du jour is these days)).

Also: nothing to do with 'flow memory'; or so it would seem.

The only thing I see is that there are an awful lot of what look like Swing or AWT methods involved. Any particular reason for that? It may be perfectly reasonable, but is it possible that you're retaining more than just the login credentials from your process?

Fraid I'm no expert when it comes to GUI apps, but 4,000 logins sounds pretty reasonable to me, even if they aren't doing anything. I've worked on some medium size servers that didn't allow that many user logins.

Apart from twiddling with the heap size, I can't suggest much more; if a 10% increase allows you 10% (or roundabout) more logins, I suspect you've found your bottleneck.

Winston
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 417
    
    2

There is a java option to dump -XX:+HeapDumpOnOutOfMemoryError set this on the command line , then when it crashes you get a hprof load that into Visual VM (with your JDK in bin directory) and it should tell you where your memory has gone or use EclipseMAT free download and look at the reports it generates.




"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Rojan punn
Greenhorn

Joined: Nov 29, 2011
Posts: 17

-Xms and -Xmx willl be used to inistalise max memory pool and min memory pool.This can be used for any application.it is your chice how you application should behave by providing java options.

I would say keep the initial siz and max size to same value and try.So this way when jvm startsup it will have all the memory it need till the end.
There is no way you can give a thread based memory allocation in a single jvm(as far i know). you can try tlab opion but highly inefficiant if threads are not using the allocated memory (not running) good side of this is that you will have a chunk of memory only for the your thread running.
Maximum memory for you login application can be changed to 1024 if you want and see this has any effect.

But following also need to be checked.

1) memory leak-
closing connection .resultset and statemets after use preferably in finally if posible.
avoid declaring class level variables for evrything,
2) avoid keeping data into the memory.
3) need to identify where you hold chunks of data into memory?
4) try different gc mechanisms
I have no clue what effect awt windows have on you jvm interms of memory

Regards,
Rojan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Increase JVM size for thread creation