4

I am trying to reuse karate scripts and perform load testing using gatling. The scenario defined is to load constant 50 users per second for 10 seconds. (To load test 500 users) However the number of requests per second does not exceed 20 requests per second in the gatling report. Please let me know if i am doing anything wrong. ExampleTest.java code which executes Karate scripts

//package examples;

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
import org.apache.commons.io.FileUtils;

class ExamplesTest {
    
    @Test
    void testParallel() {
        //System.setProperty("karate.env", "demo"); // ensure reset if other tests (e.g. mock) had set env in CI
        Results results = Runner.path("classpath:examples").tags("~@ignore").parallel(10);
        generateReport(results.getReportDir());
        assertEquals(0, results.getFailCount(), results.getErrorMessages());        
    }
    
    public static void generateReport(String karateOutputPath) {        
        Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] {"json"}, true);
        List<String> jsonPaths = new ArrayList<String>(jsonFiles.size());
        jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
        Configuration config = new Configuration(new File("target"), "demo");
        ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
        reportBuilder.generateReports();        
    }
    
}

Scala Code to define load test scenarios.

package perf

import com.intuit.karate.gatling.PreDef._
import io.gatling.core.Predef._
import scala.concurrent.duration._

class KarateSimulate extends Simulation {
    

    val protocol = karateProtocol(
    "/v2/" -> Nil,
    "/v2/" -> pauseFor("get" -> 0, "post" -> 25)
    )
    val userfeeder = csv("data/Token.csv").circular

    val getScores = scenario("Get Scores for Students").feed(userfeeder).exec(karateFeature("classpath:examples/scores/student.feature"))

    setUp(
        getScores.inject(constantUsersPerSec(50) during (10 seconds)).protocols(protocol)
    )   
}

enter image description here

Vijay Reddy
  • 97
  • 1
  • 8

1 Answers1

1

We updated the docs (in the develop branch) with tips on how to increase the thread-pool size if needed: https://github.com/intuit/karate/tree/develop/karate-gatling#increasing-thread-pool-size

Add a file called gatling-akka.conf to the root of the classpath (typically src/test/resources). Here is an example:

akka {
  actor {
    default-dispatcher {
      type = Dispatcher
      executor = "thread-pool-executor"
      thread-pool-executor {
        fixed-pool-size = 100
      }
      throughput = 1
    }
  }
}

Since we made some fixes recently, please try to build from source if the above does not work for 0.9.6.RC4, it is easy, here are the instructions: https://github.com/intuit/karate/wiki/Developer-Guide

If that does not work, it is important that you follow this process so that we can replicate: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Please see these links below for good examples of how others have worked with the Karate project team to replicate issues so that they can be fixed:

https://github.com/intuit/karate/issues/1668

https://github.com/intuit/karate/issues/845

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thank you Peter, will try out and update the result. – Vijay Reddy Jul 30 '20 at 18:06
  • I have this in my feature file to get data from feeder file. ```And header Authorization = 'Bearer'+ karate.get('__gatling.accessToken')``` , now after adding the .conf file it looks like the access token is not loading from the userFeeder as specified in the scala code above.. get request has the following value ```Authorization: Bearernull``` – Vijay Reddy Jul 30 '20 at 19:19
  • @VijayReddy that does not make sense. sorry. time for you to follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Jul 31 '20 at 01:10
  • 1
    The issue specified in the comment got resolved by updating the pom file with correct dependencies and was successfully able to send 100 requests per second. Thank you @PeterThomas – Vijay Reddy Aug 07 '20 at 05:35
  • @VijayReddy What was the issue here ....which dependency you updated can you also post the solution Was the configuration shared by Peter worked or you did anything else ? – vdrulerz Mar 03 '21 at 06:21
  • 2
    @vdrulerz The issue here was that when the load was 100+ users , there should be 100 requests sent but this was not happening, after adding the code peter suggested and made some minor changes to POM it worked. With the latest version of Karate not sure if there is any change required for pom dependencies. – Vijay Reddy Mar 09 '21 at 08:14