12

I'm testing using Apache's Jmeter, I'm simply accessing one page of my companies website and turning up the number of users until it reaches a threshold, the problem is that when I get to around 3000 threads JMeter doesn't run all of them. Looking at the Aggregate Graph it only runs about 2,536 (this number varies but is always around here) of them.

The partial run comes with the following exception in the logs:

01:16 ERROR - jmeter.JMeter: Uncaught exception: 
java.lang.OutOfMemoryError: unable to create new native thread
    at java.lang.Thread.start0(Native Method)
    at java.lang.Thread.start(Unknown Source)
    at org.apache.jmeter.threads.ThreadGroup.start(ThreadGroup.java:293)
    at org.apache.jmeter.engine.StandardJMeterEngine.startThreadGroup(StandardJMeterEngine.java:476)
    at org.apache.jmeter.engine.StandardJMeterEngine.run(StandardJMeterEngine.java:395)
    at java.lang.Thread.run(Unknown Source)

This behavior is consistent. In addition one of the times JMeter crashed in the middle outputting a file that said:

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 32756 bytes for ChunkPool::allocate
# 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 (allocation.cpp:211), pid=10748, tid=11652
#
# JRE version: 6.0_31-b05
# Java VM: Java HotSpot(TM) Client VM (20.6-b01 mixed mode, sharing windows-x86 )

Any ideas?
I tried changing the heap size in jmeter.bat, but that didn't seem to help at all.

Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
Irony
  • 317
  • 1
  • 3
  • 11

6 Answers6

13

JVM is simply not capable of running so many threads. And even if it is, JMeter will consume a lot of CPU resources to purely switch contexts. In other words, above some point you are not benchmarking your web application but the client computer, hosting JMeter.

You have few choices:

  • experiment with JVM options, e.g. decrease default -Xss512K to something smaller

  • run JMeter in a cluster

  • use tools taking radically different approach like Gatling

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • 2
    The downvotes were probably because you claimed that the JVM can't run many threads, but the discussion in the link you referenced seems to contradict that statement. – sworisbreathing Apr 02 '14 at 20:04
  • 2
    "you are not benchmarking your web application but the client computer, hosting JMeter" - exactly – binithb Sep 05 '14 at 12:39
5

I had a similar issue and increased the heap size in jmeter.bat to 1024M and that fixed the issue.

set HEAP=-Xms1024m -Xmx1024m
Satpal
  • 132,252
  • 13
  • 159
  • 168
Siva
  • 61
  • 1
  • 2
3

For the JVM, if you read hprof it gives you some solutions among which are:

  • switch to a 64 bits jvm ( > 6_u25)

  • with this you will be able to allocate more Heap (-Xmx) , ensure you have this RAM

  • reduce Xss with:

-Xss256k

Then for JMeter, follow best-practices:

Finally ensure you use last JMeter version.

  • Use linux OS preferably

  • Tune the TCP stack, limits

Success will depend on your machine power (cpu and memory) and your test plan.

If this is not enough (for 3000 threads it should be OK), you may need to use distributed testing

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
  • I also suggest running JMeter from linux, and tuning the sysctl, ulimit. (max file handles, increase port range, etc..) – Dominik Antal Sep 18 '14 at 07:49
2

Increasing the heap size in jmeter.bat works fine set HEAP=-Xms1024m -Xmx1024m

OR you can do something like below if you are using jmeter.sh: JVM_ARGS="-Xms512m -Xmx1024m" jmeter.sh etc.

swathy valluri
  • 5,039
  • 2
  • 16
  • 13
2

I ran into this same problem and the only solution that helped me is: https://stackoverflow.com/a/26190804/5796780

proper 100k threads on linux:

ulimit -s  256
ulimit -i  120000
echo 120000 > /proc/sys/kernel/threads-max
echo 600000 > /proc/sys/vm/max_map_count
echo 200000 > /proc/sys/kernel/pid_max 

If you don't have root access:

echo 200000 | sudo dd of=/proc/sys/kernel/pid_max
Community
  • 1
  • 1
Vijay
  • 1,082
  • 8
  • 6
-1

After increasing Xms et Xmx heap size, I had to make my Java run in 64 bits mode. In jmeter.bat :

set JM_LAUNCH=java.exe -d64

Obviously, you need to run a 64 bits OS and have installed Java 64 bits (see https://www.java.com/en/download/manual.jsp)

Franck
  • 560
  • 7
  • 20