2

I have come across heap errors while loading a large dataset into Jena. `Is there some way by which I may allocate the JVM(Java) a large heap space.

I know I can achieve this by making changes into eclipse.ini. But is there some way by which I may increase the Java heap size using command line in linux (I using a 64GB RAM server: running 12.04 Ubuntu LTS server)?

The error which I am getting due to less heap space is: exception in thread main gc overhead limit exceeded.

Also how can I find the maximum amount of heap space which I can set for my systems

I tried export JAVA_OPTS= -Xms4096m -Xmx4096m but ended up getting the error: bash: export: -Xms4096m': not a valid identifier bash: export:-Xmx4096m': not a valid identifier

Alice Everett
  • 369
  • 1
  • 7
  • 13
  • 1
    research `Xmx` and `Xms` options –  Dec 21 '13 at 02:35
  • @JarrodRoberson I tried but setting them through JVM_OPTIONS does not work for me. Also how can I find the maximum amount of heap space which I can set for my systems. Thanks a lot for replying...i read the post before posting the question..but since I am a novice at linux..i did not get much – Alice Everett Dec 21 '13 at 02:39
  • 1
    this kind of information is easy to find with any search engine. – Leo Dec 21 '13 at 02:44
  • @Leo Ya I tried ...but being a novice i am not able to comprehend much – Alice Everett Dec 21 '13 at 02:47
  • @AliceEverett You could try running the command `free` on your bash prompt. – Elliott Frisch Dec 21 '13 at 02:58
  • @ElliottFrisch Thanks for helping again. I tried export JAVA_OPTS= -Xms4096m -Xmx4096m but ended up getting the error bash: export: `-Xms4096m': not a valid identifier bash: export: `-Xmx4096m': not a valid identifier – Alice Everett Dec 21 '13 at 03:01

2 Answers2

6

Try (note quotes are not optional with two words)

export JAVA_OPTS="-Xms4096m -Xmx4096m"

Or, even

export MIN="4096m" # <-- Those quotes are (one word).
export MAX="4096m"
export JAVA_OPTS="-Xms$MIN -Xmx$MAX" # <-- single quotes would break variable expansion
Elliott Frisch
  • 183,598
  • 16
  • 131
  • 226
5
java -Xms4096m -Xmx4096m [YourAppHere]

This command will allocate 4GB (or 4096 MB) of heap memory at the start (the -Xms4096m option), and will have a maximum heap memory size of 4GB (the -Xmx4096m option).

Obviously you can change the number to whatever sizes you want to. There is overhead if the computer has to increase the size of memory (Every time it increases the memory size, it doubles the allocation) so if you have that much ram, you might as well just allocate it at the beginning of the app.

oconnecp
  • 672
  • 5
  • 13
  • what does [YourAppHere] signify. Also thanks for answering :) – Alice Everett Dec 21 '13 at 02:42
  • the java file that you are running – oconnecp Dec 21 '13 at 02:44
  • actually I am running java bytecodes(i.e. executable equivalent of C++)..can I specify the executable name here – Alice Everett Dec 21 '13 at 02:45
  • Also is there a way by which I may set java heap size permanently for some time – Alice Everett Dec 21 '13 at 02:46
  • 1
    java is always run as bytecode, whether it's just compiled, or compressed into a jar. Java runs on a virtual machine and only understands bytecode specifically made for it. Those commands will set the heap size to whatever you want them to be and it is persistant as long as the app is running. if you need a shortcut write a sh script that calls that command instead of typing it everytime – oconnecp Dec 21 '13 at 02:49
  • @AliceEverett You can write a script file to start your program, then you run the script... – Elliott Frisch Dec 21 '13 at 02:51
  • Thanks a lot for helping..but i tried with apache-jena-2.10.0 (Inside bin binaries are kept) and it gives me the Error: Could not find or load main class ..tdbloader – Alice Everett Dec 21 '13 at 02:51
  • @ElliottFrisch I tried but with binaries kept in bin of apache-jena..its gives me the error mentioned above. Thanks a lot for replying :) – Alice Everett Dec 21 '13 at 02:53
  • The method which I used for loading files is: bin/tdbloader --loc=/home/sysadmin/mydatasetdata -v /full/path/to/rdf/or/ttl/files/ – Alice Everett Dec 21 '13 at 02:55