title: JMeter - out of memory on linux
body: <p>I am trying to run a load test for a application. For this i am using JMeter (v.2.13) on an Ubuntu Vm with 60GB Ram and more than enough CPU power. Goal is to reach 10k Users connected via WebSocket.</p>
  
  <p>However during the test runs i get the following errors on the ssh-console (at approx. 1.5k to 2.5k simulated users)</p>
  
  <pre><code>OpenJDK 64-Bit Server VM warning: Attempt to protect stack guard pages failed.
  OpenJDK 64-Bit Server VM warning: Attempt to deallocate stack guard pages failed.
  OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00007f20ee653000, 12288, 0) failed; error='Cannot allocate memory' (errno=12)
  #
  # There is insufficient memory for the Java Runtime Environment to continue.
  # Native memory allocation (malloc) failed to allocate 12288 bytes for committing reserved memory.
  # An error report file with more information is saved as:
  # /jmetertests/jm/bin/hs_err_pid1833.log
  OpenJDK 64-Bit Server VM warning: Attempt to deallocate stack guard pages failed.
  OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00007f2218de8000, 12288, 0) failed; error='Cannot allocate memory' (errno=12)
  </code></pre>
  
  <p>The mentioned error report file looks like this</p>
  
  <pre><code># There is insufficient memory for the Java Runtime Environment to continue.
  # Native memory allocation (malloc) failed to allocate 12288 bytes for committing reserved memory.
  # Possible reasons:
  #   The system is out of physical RAM or swap space
  #   In 32 bit mode, the process size limit was hit
  # Possible solutions:
  #   Reduce memory load on the system
  #   Increase physical memory or swap space
  #   Check if swap backing store is full
  #   Use 64 bit Java on a 64 bit OS
  #   Decrease Java heap size (-Xmx/-Xms)
  #   Decrease number of Java threads
  #   Decrease Java thread stack sizes (-Xss)
  #   Set larger code cache with -XX:ReservedCodeCacheSize=
  # This output file may be truncated or incomplete.
  #
  #  Out of Memory Error (os_linux.cpp:2798), pid=1833, tid=140472285792000
  #
  # JRE version: OpenJDK Runtime Environment (7.0_75-b13) (build 1.7.0_75-b13)
  # Java VM: OpenJDK 64-Bit Server VM (24.75-b04 mixed mode linux-amd64 )
  # Derivative: IcedTea 2.5.4
  # Distribution: Ubuntu 14.04 LTS, package 7u75-2.5.4-1~trusty1
  # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
  </code></pre>
  
  <p>I tried to allocate more memory by modifying the jmeter.sh through adding the following line right before the java-command is issued in the .sh-file:</p>
  
  <pre><code>JVM_ARGS="-Xms5g -Xmx20g -Xss300k"
  </code></pre>
  
  <p>I also tried setting the <code>_JAVA_OPTIONS</code> environment variable with the following command</p>
  
  <pre><code>export _JAVA_OPTIONS="-Xms5g -Xmx20g"
  </code></pre>
  
  <p>And finally I found this command im some SO-thread</p>
  
  <pre><code>sysctl -w vm.max_map_count=500000
  </code></pre>
  
  <p>The <code>top</code>-Command gives me the following information on memory</p>
  
  <pre><code>KiB Mem:  61836576 total, 15163400 used, 46673176 free,    10636 buffers
  KiB Swap:        0 total,        0 used,        0 free.    94492 cached Mem
  </code></pre>
  
  <h1>UPDATE</h1>
  
  <p>FYI: I do not use any listeners in JMeter except the simple data writer. However errors are thrown even if I disable that last listener.</p>
  
  <pre><code>java -Xms40g -version
  </code></pre>
  
  <p>is succesful - so i can really allocate so much memory</p>
  
  <p>I reduced the stack size by using</p>
  
  <pre><code>-Xss300k
  </code></pre>
  
  <p>which helped ot at least changed something as I now get a </p>
  
  <pre><code>Uncaught Exception java.lang.OutOfMemoryError:
  unable to create new native thread. See log file for details.
  </code></pre>
  
  <p>error. It seems that the number of threads on the system are exhausted?</p>
  
  <h1>Update2</h1>
  
  <p>as requested by some user the results uf <code>ulimit -a</code></p>
  
  <pre><code>core file size          (blocks, -c) 0
  scheduling priority             (-e) 0
  pending signals                 (-i) 491456
  max locked memory       (kbytes, -l) 64
  open files                      (-n) 500000
  pipe size            (512 bytes, -p) 8
  POSIX message queues     (bytes, -q) 819200
  real-time priority              (-r) 0
  stack size              (kbytes, -s) 8192
  max user processes              (-u) 491456
  ... all other entries are set to 'unlimited'
  </code></pre>
  
  <p>and the limits.conf contains the following entries</p>
  
  <pre><code>*         hard    nofile      900000
  *         soft    nofile      900000
  root      hard    nofile      900000
  root      soft    nofile      900000
  </code></pre>
  
  <p>Additonally i have set the <code>threads-max</code> under <code>proc/sys/kernel</code> to something ridiculous high and also increased the value of <code>proc/sys/vm/max_map_count</code> </p>
  
  <p>Did I miss something or did i do something wrong?
  Thank you for your help.</p>