Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sara Brown
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sara Brown,

In addition to what Jeff Verdegan has said, this might be helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic