我想在Java代码中使用通过JMeter API使用的吞吐量整形计时器。
我的目的是通过JMeter API以编程方式使用吞吐量调整计时器。
我已经通过将名为VariableThroughputTimer.java的类文件添加到我的项目文件夹的源目录中来引用它。
这是我的代码段的一部分:
// VariableThroughputTimer
VariableThroughputTimer timer = new VariableThroughputTimer();
timer.setEnabled(true);
timer.setName("VariableThroughputTimer");
timer.setProperty("Start RPS", 1);
timer.setProperty("End RPS", 1000);
timer.setProperty("Duration", 60);
timer.setComment("Table below sets request rate shcedule ant preview graph instantly shows effect of changes.");
timer.setProperty(TestElement.TEST_CLASS, kg.apc.jmeter.vizualizers.CorrectedResultCollector.class.getName());
timer.setProperty(TestElement.GUI_CLASS, kg.apc.jmeter.vizualizers.TransactionsPerSecondGui.class.getName());
// Thread Group
ThreadGroup threadGroup = new ThreadGroup();
threadGroup.setName("Thread Group");
threadGroup.setNumThreads(4);
threadGroup.setRampUp(1);
threadGroup.setDuration(1);;
threadGroup.setSamplerController(loopController);
threadGroup.setSamplerController(PublishController);
threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());
// Test Plan
TestPlan testPlan = new TestPlan("IOT_Jmeter");
testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());
// HTTP Request Sampler and Header Manager
HashTree httpRequestTree = new HashTree();
httpRequestTree.add(mqttConnectSampler);
httpRequestTree.add(mqttpubSampler);
httpRequestTree.add(csvDataSet);
httpRequestTree.add(timer);
因此,无论何时,我都会尝试执行代码。它不执行。
这是我的Eclipse IDE的日志:
2019-02-12 16:13:28 [main] INFO StandardJMeterEngine:453 - Starting ThreadGroup: 1 : Thread Group
2019-02-12 16:13:28 [main] INFO StandardJMeterEngine:513 - Starting 4 threads for group Thread Group.
2019-02-12 16:13:28 [main] INFO StandardJMeterEngine:523 - Thread will continue on error
2019-02-12 16:13:28 [main] INFO ThreadGroup:222 - Starting thread group... number=1 threads=4 ramp-up=1 perThread=250.0 delayedStart=false
2019-02-12 16:13:28 [main] INFO ThreadGroup:236 - Started thread group number 1
2019-02-12 16:13:28 [main] INFO StandardJMeterEngine:464 - All thread groups have been started
2019-02-12 16:13:28 [Thread Group 1-1] INFO JMeterThread:705 - Thread started: Thread Group 1-1
2019-02-12 16:13:28 [Thread Group 1-1] INFO FileServer:265 - Stored: C:\Users\angshuman.basak\Downloads\apache-jmeter-5.0\csvDataNew.csv
2019-02-12 16:13:28 [Thread Group 1-1] INFO VariableThroughputTimer:304 - No further RPS schedule, asking threads to stop...
2019-02-12 16:13:28 [Thread Group 1-1] INFO VariableThroughputTimer:319 - Stopping gracefuly threads of Thread Group : Thread Group
2019-02-12 16:13:28 [Thread Group 1-1] INFO JMeterThread:797 - Stopping: Thread Group 1-2
2019-02-12 16:13:28 [Thread Group 1-1] INFO JMeterThread:797 - Stopping: Thread Group 1-3
2019-02-12 16:13:28 [Thread Group 1-1] INFO JMeterThread:797 - Stopping: Thread Group 1-4
2019-02-12 16:13:28 [Thread Group 1-1] INFO JMeterThread:797 - Stopping: Thread Group 1-1
2019-02-12 16:13:28 [Thread Group 1-1] WARN VariableThroughputTimer:147 - No free threads available in current Thread Group Thread Group, made 0 samples/s for expected rps 1.0 samples/s, increase your number of threads
2019-02-12 16:13:28 [Thread Group 1-1] INFO JMeterThread:324 - Thread finished: Thread Group 1-1
2019-02-12 16:13:29 [Thread Group 1-2] INFO JMeterThread:705 - Thread started: Thread Group 1-2
2019-02-12 16:13:29 [Thread Group 1-2] INFO JMeterThread:324 - Thread finished: Thread Group 1-2
2019-02-12 16:13:29 [Thread Group 1-3] INFO JMeterThread:705 - Thread started: Thread Group 1-3
2019-02-12 16:13:29 [Thread Group 1-3] INFO JMeterThread:324 - Thread finished: Thread Group 1-3
2019-02-12 16:13:29 [Thread Group 1-4] INFO JMeterThread:705 - Thread started: Thread Group 1-4
2019-02-12 16:13:29 [Thread Group 1-4] INFO JMeterThread:324 - Thread finished: Thread Group 1-4
2019-02-12 16:13:29 [main] INFO StandardJMeterEngine:223 - Notifying test listeners of end of test
2019-02-12 16:13:29 [main] INFO FileServer:485 - Close: C:\Users\angshuman.basak\Downloads\apache-jmeter-5.0\csvDataNew.csv
2019-02-12 16:13:29 [main] INFO Summariser:327 - summary = 0 in 00:00:00 = ******/s Avg: 0 Min: 9223372036854775807 Max: -9223372036854775808 Err: 0 (0.00%)
summary = 0 in 00:00:00 = ******/s Avg: 0 Min: 9223372036854775807 Max: -9223372036854775808 Err: 0 (0.00%)
上面的Summariser表示测试未执行。从上面的日志中,可变吞吐量计时器获取以下内容:
2019-02-12 16:13:28 [Thread Group 1-1] INFO VariableThroughputTimer:304 - No further RPS schedule, asking threads to stop...
2019-02-12 16:13:28 [Thread Group 1-1] INFO VariableThroughputTimer:319 - Stopping gracefully threads of Thread Group: Thread Group
2019-02-12 16:13:28 [Thread Group 1-1] WARN VariableThroughputTimer:147 - No free threads available in current Thread Group Thread Group, made 0 samples/s for expected rps 1.0 samples/s, increase your number of threads
我想使用吞吐量整形计时器以编程方式执行代码。如果我的实现不正确或解决了执行问题,我想为VariableThroughputTimer使用正确的代码。
非常感谢您的援助。
答案 0 :(得分:0)
您打算如何仅通过4个线程来实现每秒1000个请求?仅当您有4毫秒的响应时间(极不可能)时才有可能。
根据日志条目,您应该
线程组线程组,以0个样本/秒的速度为预期的rps 1.0个样本/秒,增加线程数`
还请确保将基础Loop Controller配置为永久迭代 。
展望未来,可以考虑使用Concurrency Thread Group,它可以与使用Schedule Feedback函数的吞吐量整形计时器连接,因此,如果当前数量不足以达到/维护JMeter,JMeter将能够启动额外的线程。目标吞吐量。请查看Using JMeter’s Throughput Shaping Timer Plugin文章以了解更多详细信息。
答案 1 :(得分:0)
根据所需的吞吐量,您的线程组配置不合适。由于所需的吞吐量为1000 RPS
,因此如果响应时间为1000 threads
,则至少需要1 second
。如果响应时间为0.5 seconds
,则需要500 threads
才能达到1000 RPS
。因此,仅使用4 threads
不能达到1000 RPS。要仅使用4个线程来达到1000 RPS,您的响应时间必须为.004 seconds
(4毫秒)。
您将测试持续时间设置为仅1秒,在这种情况下也是错误的。