wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes why increase number of thread will decrease the time but increase the physical memory. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "why increase number of thread will decrease the time but increase the physical memory." Watch "why increase number of thread will decrease the time but increase the physical memory." New topic
Author

why increase number of thread will decrease the time but increase the physical memory.

Sara Brown
Ranch Hand

Joined: Feb 22, 2012
Posts: 55
my cpu time and elapsed time(JVM) decrease when the number of thread increase.

however my physical memory will get higher when the number of thread increase.

why is that happen?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Sara Brown wrote:my cpu time and elapsed time(JVM) decrease when the number of thread increase.


I would expect that elapsed wall clock time might go down with the proper use of multithreading, but not elapsed CPU time.

Maybe you're not seeing what you think you're seeing. I guess it depends how that CPU time is measured and what you're doing. For example, if the measurement only counts CPU time as when at least one of your apps threads is using the CPU, then if 2 threads using 2 CPUs simultaneously for 1 second, it would only get counted as 1 second of CPU time, even though there were 2 elapsed CPU-seconds. So you 2 tasks that previously to 2 consecutive seconds on 1 CPU, now take 1 second on 2 CPUs.

That would be a strange way to measure it though. It seems unlikely to me, but maybe that's what it is.

Or it might be that previously you had a thread blocked on I/O, and that time was counted as CPU time, but now you have another thread actually doing work while the first thread is blocked.

That still doesn't sound right to me though. I'd actually expect total CPU time to increase, no matter how good your multithreading is, since there will always be some overhead to managing the threads.

however my physical memory will get higher when the number of thread increase.


Well, yes, each thread has its own stack, so the more threads, the more memory being consumed, and of course if you have 2 threads creating objects at the same time instead of just 1, then you'll have twice as many objects in memory.

Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1502
    
    5

Hello Sara Brown,

In addition to what Jeff Verdegan has said, this might be helpful.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why increase number of thread will decrease the time but increase the physical memory.
 
Similar Threads
Bean Pooling EJB
thread, increase in memory used by the object and less memory usage for CPU. is it correct?
counting running threads
Capacity planning (performance tuning of WLP 8.1 SP6 application)
How to debug JBoss crashing