dnafication dnafication - 1 year ago 130
HTTP Question

How much memory (heap size) is required to be set in JMeter

Let's take a very simple jmeter script which downloads a file of 128MB in an HTTP request (GET). Purpose is to stress out the server under test so there is no necessity for file to be stored locally or in memory of the jvm for future use. The file should be completely downloaded as it maintains a connection with the sever.

10 threads or more running concurrently with a pacing of say 5 seconds. Assume unlimited network bandwidth.

File location: https://storage.googleapis.com/videos12/dummy.txt

Question is - how much memory would you set for the heap size of the jmeter's jvm so that you do not get java OOM error? What would be the approach to do a basic calculation?

set HEAP=-Xms512m -Xmx512m
--> this can be set in jmeter.bat file.

a sample test plan in jmeter

Answer Source
  1. Quick answer: 512 Mb is too low for 10 threads downloading a 128Mb file. Increase the heap to 80% of your total physical available RAM.
  2. Longer answer: read the material about Java Performance Tuning, Profiling, and Memory Management, quit your tester job and become JVM expert.
  3. Good answer: don't ask or guess it, measure it. Using i.e. JVisualVM:

    • Run your test with 1 virtual user. Measure heap used
    • Run your test with 2 virtual users. Measure heap used.
    • Run your test with 4 virtual users. Measure heap used.
    • Do complex arithmetic calculations
    • Set JMeter heap accordingly to results

      JVM JMeter visual VM

  4. Correct answer: Given you don't care in the slightest about the response don't use HTTP Request sampler and go for JSR223 Sampler instead. Example code:

    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.HttpClientBuilder;
    import org.apache.http.util.EntityUtils;
    HttpClient client = HttpClientBuilder.create().build();
    HttpGet get = new HttpGet("https://storage.googleapis.com/videos12/dummy.txt");
    HttpResponse response = client.execute(get);
    HttpEntity entity = response.getEntity();

    Very important bits:

    • Make sure you select groovy in the "language: dropdown
    • Make sure you tick Cache compiled script if available box
    • Make sure you don't forget the EntityUtils.consume(entity); line - it does all the magic

For better understanding of the "correct answer" see HttpClient Tutorial for Apache HTTP Components API explained and Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article for scripting best practices.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download