【问题标题】:how to load more requests per second in karate gatling如何在空手道加特林中每秒加载更多请求
【发布时间】:2020-07-30 17:53:50
【问题描述】:

我正在尝试重用空手道脚本并使用 gatling 执行负载测试。定义的场景是每秒加载恒定的 50 个用户,持续 10 秒。 (负载测试 500 个用户)但是在 gatling 报告中每秒的请求数不超过每秒 20 个请求。如果我做错了什么,请告诉我。 ExampleTest.java 执行空手道脚本的代码

//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 代码。

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)
    )   
}

【问题讨论】:

    标签: karate


    【解决方案1】:

    我们更新了文档(在 develop 分支中),提供了有关如何在需要时增加线程池大小的提示:https://github.com/intuit/karate/tree/develop/karate-gatling#increasing-thread-pool-size

    将名为gatling-akka.conf 的文件添加到类路径的根目录(通常为src/test/resources)。这是一个例子:

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

    由于我们最近做了一些修复,如果上述方法不适用于 0.9.6.RC4,请尝试从源代码构建,这很容易,这里是说明:https://github.com/intuit/karate/wiki/Developer-Guide

    如果这不起作用,请务必遵循此流程以便我们可以复制:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

    请参阅下面的这些链接,了解其他人如何与空手道项目团队合作复制问题以便解决问题:

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

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

    【讨论】:

    • 谢谢彼得,将尝试更新结果。
    • 我的功能文件中有这个,可以从馈线文件中获取数据。 And header Authorization = 'Bearer'+ karate.get('__gatling.accessToken') ,现在在添加 .conf 文件后,看起来访问令牌没有从上面的 scala 代码中指定的 userFeeder 加载.. get 请求具有以下值 Authorization: Bearernull
    • @VijayReddy 这没有意义。对不起。是时候遵循这个过程了:github.com/intuit/karate/wiki/How-to-Submit-an-Issue
    • 评论中指定的问题已通过更新具有正确依赖关系的 pom 文件得到解决,并且每秒能够成功发送 100 个请求。谢谢@PeterThomas
    • @vdrulerz 这里的问题是,当负载超过 100 个用户时,应该发送 100 个请求,但这并没有发生,在添加了 peter 建议的代码并对 POM 进行了一些小的更改后,它起作用了.使用最新版本的空手道不确定是否需要对 pom 依赖项进行任何更改。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    相关资源
    最近更新 更多