scijava/scyjava

Adding memory to java runtime

Closed this issue · 4 comments

I am working on PyImageJ and for image analysis I need more date than maxMemory offers, I have 16GB of RAM, but he max memory returns 3580 MB available to Java and I need at least 8GB. Is it possible to add the memory? I tried following code but it yielded same result.

from scyjava import config, jimport


config.add_option('-Xmx8g')
Runtime = jimport('java.lang.Runtime')

print(Runtime.getRuntime().maxMemory() // (2**20), " MB available to Java")

@tornikepirveli I adapted your script:

from scyjava import config, jimport
def mem(gb):
  config.add_option(f"-Xmx{gb}g")
  Runtime = jimport("java.lang.Runtime")
  maxmem = Runtime.getRuntime().maxMemory()
  mb = maxmem // (2**20)
  mib = maxmem // (10**6)
  percent = 100 * mb // (1024 * gb)
  print(f"{mb} MB ({mib} MiB) available: {percent}% of requested")

And tried it with various values. Here are the results on my macOS system with 16GB of RAM:

>>> mem(4)
3641 MB (3817 MiB) available: 88% of requested
>>> mem(8)
7282 MB (7635 MiB) available: 88% of requested
>>> mem(10)
9102 MB (9544 MiB) available: 88% of requested
>>> mem(12)
10923 MB (11453 MiB) available: 88% of requested
>>> mem(14)
12743 MB (13362 MiB) available: 88% of requested

Restarting Python in between each call, of course.

So for me, the value is increasing. It appears there is consistently a 12% fraction of overhead as it scales.

Are you seeing different behavior?

If 3580 MB is the highest you ever get, I'm wondering if maybe you are using a 32-bit rather than 64-bit JVM?

Thanks for the quick reply, I reinstalled 64-bit JVM and I think it resolved that issue. Thanks for the notice!

Sorry, I actually caught the problem, as it seems I had installed 64-bit previously too, so there was not that. The problem was in imagej using most of my ram and there was not much left for scyjava.

I understand it is a different topic, so I will open new topic on PyImageJ repository and I will close this one hence there is no problem with initial answer.