From 4f0d983c84ae09ffa009df5caa611ab571d586e5 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Mon, 30 Sep 2024 17:42:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0benchmark=E7=9A=84=E5=B7=A5?= =?UTF-8?q?=E7=A8=8B=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow-benchmark-common/pom.xml | 9 +++ .../liteflow/benchmark/CommonBenchmark.java | 67 +++++++++++++++++++ .../yomahub/liteflow/benchmark/cmp/ACmp.java | 20 ++++++ .../yomahub/liteflow/benchmark/cmp/BCmp.java | 20 ++++++ .../yomahub/liteflow/benchmark/cmp/CCmp.java | 20 ++++++ .../liteflow/benchmark/cmp/Person.java | 28 ++++++++ .../liteflow/benchmark/test/CommonTest.java | 36 ++++++++++ .../src/test/resources/flow.xml | 58 +++++----------- .../liteflow/script/javax/JavaxExecutor.java | 12 ++-- 9 files changed, 222 insertions(+), 48 deletions(-) create mode 100644 liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonBenchmark.java create mode 100644 liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/ACmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/BCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/Person.java create mode 100644 liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/test/CommonTest.java diff --git a/liteflow-benchmark/liteflow-benchmark-common/pom.xml b/liteflow-benchmark/liteflow-benchmark-common/pom.xml index 2ca89408f..df0661fd8 100644 --- a/liteflow-benchmark/liteflow-benchmark-common/pom.xml +++ b/liteflow-benchmark/liteflow-benchmark-common/pom.xml @@ -12,4 +12,13 @@ liteflow-benchmark-common + + + com.yomahub + liteflow-script-javax + ${revision} + test + + + \ No newline at end of file diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonBenchmark.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonBenchmark.java new file mode 100644 index 000000000..7d770b5dd --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonBenchmark.java @@ -0,0 +1,67 @@ +package com.yomahub.liteflow.benchmark; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.FlowBus; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; +import org.openjdk.jmh.runner.options.TimeValue; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.PropertySource; + +import java.util.concurrent.TimeUnit; + +@State(Scope.Benchmark) +@EnableAutoConfiguration +@PropertySource(value = "classpath:application.properties") +@ComponentScan("com.yomahub.liteflow.benchmark.cmp") +public class CommonBenchmark { + + private ConfigurableApplicationContext applicationContext; + + private FlowExecutor flowExecutor; + + @Setup + public void setup() { + applicationContext = SpringApplication.run(CommonBenchmark.class); + flowExecutor = applicationContext.getBean(FlowExecutor.class); + } + + @TearDown + public void tearDown() { + applicationContext.close(); + } + + @Benchmark + public void test1(){ + flowExecutor.execute2Resp("chain1"); + } + + @Benchmark + public void test2(){ + flowExecutor.execute2Resp("chain2"); + } + + + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder() + .include(CommonBenchmark.class.getSimpleName()) + .mode(Mode.Throughput) + .warmupIterations(1)//预热次数 + .measurementIterations(3)//执行次数 + .measurementTime(new TimeValue(10, TimeUnit.SECONDS))//每次执行多少时间 + .threads(100)//多少个线程 + .forks(1)//多少个进程 + .timeUnit(TimeUnit.SECONDS) + .build(); + new Runner(opt).run(); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/ACmp.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/ACmp.java new file mode 100644 index 000000000..8c9d02813 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/ACmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + } + +} diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/BCmp.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/BCmp.java new file mode 100644 index 000000000..1dc6a517f --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/BCmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + } + +} diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CCmp.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CCmp.java new file mode 100644 index 000000000..95ee9b80c --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CCmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + } + +} diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/Person.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/Person.java new file mode 100644 index 000000000..be665958d --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/Person.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.benchmark.cmp; + +public class Person { + private String name; + + private Integer salary; + + public Person(String name, Integer salary) { + this.name = name; + this.salary = salary; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getSalary() { + return salary; + } + + public void setSalary(Integer salary) { + this.salary = salary; + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/test/CommonTest.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/test/CommonTest.java new file mode 100644 index 000000000..2977cb4e3 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/test/CommonTest.java @@ -0,0 +1,36 @@ +package com.yomahub.liteflow.benchmark.test; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicLong; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:application.properties") +@SpringBootTest(classes = CommonTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.benchmark.cmp" }) +public class CommonTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void test1() { + flowExecutor.execute2Resp("chain1"); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/resources/flow.xml b/liteflow-benchmark/liteflow-benchmark-common/src/test/resources/flow.xml index ee2649be2..14bd071aa 100644 --- a/liteflow-benchmark/liteflow-benchmark-common/src/test/resources/flow.xml +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/resources/flow.xml @@ -2,54 +2,32 @@ - + list = ListUtil.toList("a", "b", "c") - - List resultList = list.stream().map(s -> "hello," + s).collect(Collectors.toList()) - - defaultContext.setData("resultList", resultList) - - class Student { - int studentID - String studentName + public class Demo implements CommonScriptBody { + public Void body(ScriptExecuteWrap wrap) { + return null; + } } - - Student student = new Student() - student.studentID = 100301 - student.studentName = "张三" - defaultContext.setData("student", student) - - def a = 3 - def b = 2 - defaultContext.setData("s1", a * b) - ]]> - - - - - - - - - THEN(FOR(s2).DO(THEN(a, b, c, s1)), SWITCH(s3).TO(a,b)); + THEN(a,b,c); + + + + THEN(a,b,s1); \ No newline at end of file diff --git a/liteflow-script-plugin/liteflow-script-javax/src/main/java/com/yomahub/liteflow/script/javax/JavaxExecutor.java b/liteflow-script-plugin/liteflow-script-javax/src/main/java/com/yomahub/liteflow/script/javax/JavaxExecutor.java index f4b05af6f..785ab8817 100644 --- a/liteflow-script-plugin/liteflow-script-javax/src/main/java/com/yomahub/liteflow/script/javax/JavaxExecutor.java +++ b/liteflow-script-plugin/liteflow-script-javax/src/main/java/com/yomahub/liteflow/script/javax/JavaxExecutor.java @@ -79,14 +79,10 @@ public class JavaxExecutor extends ScriptExecutor { @Override public Object compile(String script) throws Exception { - try{ - CodeSpec codeSpec = new CodeSpec(convertScript(script)) - .returnType(Object.class) - .parameters(new ParamSpec("_meta", ScriptExecuteWrap.class)).cached(isCache); - return Scripts.compile(codeSpec); - }catch (Exception e){ - return e; - } + CodeSpec codeSpec = new CodeSpec(convertScript(script)) + .returnType(Object.class) + .parameters(new ParamSpec("_meta", ScriptExecuteWrap.class)).cached(isCache); + return Scripts.compile(codeSpec); } private String convertScript(String script){