From 3b43111f18bb24c847610f2e00cb92575690e95b Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Tue, 2 Dec 2025 00:35:29 +0800 Subject: [PATCH] =?UTF-8?q?enhancement=20#ID8XF9=20=E5=AF=B9QLExpress4?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow-benchmark-common-example/pom.xml | 2 +- .../liteflow-benchmark-common/pom.xml | 2 +- .../liteflow/benchmark/cmp/CmpConfig.java | 4 +- .../liteflow-benchmark-compile/pom.xml | 16 +++++ .../liteflow/benchmark/TestCompile.java | 58 +++++++++++++++++++ .../benchmark/cmp/BatchSenderCmp.java | 21 +++++++ .../liteflow/benchmark/cmp/Biz1Cmp.java | 13 +++++ .../liteflow/benchmark/cmp/Channel1Cmp.java | 14 +++++ .../benchmark/cmp/Channel1QueryCmp.java | 18 ++++++ .../liteflow/benchmark/cmp/Channel2Cmp.java | 14 +++++ .../benchmark/cmp/Channel2QueryCmp.java | 19 ++++++ .../liteflow/benchmark/cmp/Channel3Cmp.java | 14 +++++ .../benchmark/cmp/Channel3QueryCmp.java | 19 ++++++ .../liteflow/benchmark/cmp/Channel4Cmp.java | 14 +++++ .../benchmark/cmp/Channel4QueryCmp.java | 18 ++++++ .../liteflow/benchmark/cmp/Channel5Cmp.java | 14 +++++ .../benchmark/cmp/Channel5QueryCmp.java | 18 ++++++ .../liteflow/benchmark/cmp/Channel6Cmp.java | 14 +++++ .../benchmark/cmp/Channel6QueryCmp.java | 17 ++++++ .../benchmark/cmp/ChannelSelectorCmp.java | 24 ++++++++ .../liteflow/benchmark/cmp/IF1SwitchCmp.java | 15 +++++ .../liteflow/benchmark/cmp/IF2SwitchCmp.java | 15 +++++ .../liteflow/benchmark/cmp/IF3SwitchCmp.java | 16 +++++ .../benchmark/cmp/PackageDataCmp.java | 13 +++++ .../context/BatchMessageResultContext.java | 37 ++++++++++++ .../liteflow/benchmark/vo/QueryVO.java | 31 ++++++++++ .../src/test/resources/application.properties | 2 + .../src/test/resources/flow.xml | 8 +++ .../liteflow-benchmark-script-groovy/pom.xml | 2 +- .../liteflow-benchmark-script-java/pom.xml | 2 +- .../pom.xml | 2 +- .../liteflow-benchmark-script-javax/pom.xml | 2 +- liteflow-benchmark/pom.xml | 4 +- .../builder/el/LiteFlowChainELBuilder.java | 5 +- .../yomahub/liteflow/util/QlExpressUtils.java | 2 + 35 files changed, 477 insertions(+), 12 deletions(-) create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/pom.xml create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/TestCompile.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/BatchSenderCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Biz1Cmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel1Cmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel1QueryCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel2Cmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel2QueryCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel3Cmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel3QueryCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel4Cmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel4QueryCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel5Cmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel5QueryCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel6Cmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel6QueryCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/ChannelSelectorCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF1SwitchCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF2SwitchCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF3SwitchCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/PackageDataCmp.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/context/BatchMessageResultContext.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/vo/QueryVO.java create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/resources/application.properties create mode 100644 liteflow-benchmark/liteflow-benchmark-compile/src/test/resources/flow.xml diff --git a/liteflow-benchmark/liteflow-benchmark-common-example/pom.xml b/liteflow-benchmark/liteflow-benchmark-common-example/pom.xml index 821e4a241..d7358da76 100644 --- a/liteflow-benchmark/liteflow-benchmark-common-example/pom.xml +++ b/liteflow-benchmark/liteflow-benchmark-common-example/pom.xml @@ -16,7 +16,7 @@ com.yomahub liteflow-script-javax-pro - ${revision} + ${liteflow-version} test diff --git a/liteflow-benchmark/liteflow-benchmark-common/pom.xml b/liteflow-benchmark/liteflow-benchmark-common/pom.xml index df0661fd8..fb62c3524 100644 --- a/liteflow-benchmark/liteflow-benchmark-common/pom.xml +++ b/liteflow-benchmark/liteflow-benchmark-common/pom.xml @@ -16,7 +16,7 @@ com.yomahub liteflow-script-javax - ${revision} + ${liteflow-version} test diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CmpConfig.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CmpConfig.java index 54dcefdc0..b31896602 100644 --- a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CmpConfig.java +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CmpConfig.java @@ -11,11 +11,11 @@ public class CmpConfig { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") public void processA(NodeComponent bindCmp, @LiteflowFact("name") String name) { - System.out.println(name); +// System.out.println(name); } @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") public void processB(NodeComponent bindCmp, @LiteflowFact("age") int age) { - System.out.println(age); +// System.out.println(age); } } diff --git a/liteflow-benchmark/liteflow-benchmark-compile/pom.xml b/liteflow-benchmark/liteflow-benchmark-compile/pom.xml new file mode 100644 index 000000000..63151a499 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + liteflow-benchmark + com.yomahub + ${revision} + ../pom.xml + + + liteflow-benchmark-compile + + + \ No newline at end of file diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/TestCompile.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/TestCompile.java new file mode 100644 index 000000000..4f8384f2c --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/TestCompile.java @@ -0,0 +1,58 @@ +package com.yomahub.liteflow.benchmark; + +import cn.hutool.core.date.StopWatch; +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +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; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:application.properties") +@SpringBootTest(classes = TestCompile.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.benchmark.cmp" }) +public class TestCompile { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void test1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("channelSenderChain", null, BatchMessageResultContext.class); + BatchMessageResultContext context = response.getFirstContextBean(); + if (response.isSuccess()){ + System.out.println("执行成功,最终选择的渠道是:" + context.getFinalResultChannel()); + }else{ + System.out.println("执行失败:" + response.getCause()); + } + } + + @Test + public void test2() throws Exception { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + + String el = "selectBestChannel = THEN(WHEN(channel1Query, channel2Query, channel3Query,channel4Query, channel5Query, channel6Query),channelSelector).id(\"branch1\");\n" + + " selectBizChannel = THEN(biz1,SWITCH(if_2).to(channel3,channel4,SWITCH(if_3).to(channel5, channel6).id(\"s3\")).id(\"s2\")).id(\"branch2\");\n" + + " THEN(packageData.tag(\"{}\"),SWITCH(if_1).to(channel1,channel2,selectBestChannel,selectBizChannel),batchSender);"; + + for (int i = 1; i <= 20000; i++) { + LiteFlowChainELBuilder.createChain().setChainId("chain_build_"+i).setEL(StrUtil.format(el,i)).build(); + } + + stopWatch.stop(); + + System.out.println(StrUtil.format("耗时:{}",stopWatch.getTotalTimeMillis())); + + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/BatchSenderCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/BatchSenderCmp.java new file mode 100644 index 000000000..98aabc9ef --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/BatchSenderCmp.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.core.NodeComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Random; + +@LiteflowComponent(id = "batchSender", name = "批量发送器") +public class BatchSenderCmp extends NodeComponent { + + private static final Logger log = LoggerFactory.getLogger(BatchSenderCmp.class); + + @Override + public void process() throws Exception { + BatchMessageResultContext context = this.getFirstContextBean(); + log.info("最终获取到的渠道为:[{}]", context.getFinalResultChannel()); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Biz1Cmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Biz1Cmp.java new file mode 100644 index 000000000..74853a246 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Biz1Cmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +import java.util.Random; + +@LiteflowComponent(id = "biz1", name = "获取业务动态值") +public class Biz1Cmp extends NodeComponent { + @Override + public void process() throws Exception { + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel1Cmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel1Cmp.java new file mode 100644 index 000000000..34c8b04ed --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel1Cmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent(id = "channel1", name = "返回渠道1") +public class Channel1Cmp extends NodeComponent { + @Override + public void process() throws Exception { + BatchMessageResultContext context = this.getFirstContextBean(); + context.setFinalResultChannel("channel1"); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel1QueryCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel1QueryCmp.java new file mode 100644 index 000000000..0eaf3ac1f --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel1QueryCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.benchmark.vo.QueryVO; +import com.yomahub.liteflow.core.NodeComponent; + +import java.util.Random; + +@LiteflowComponent(id = "channel1Query", name = "获取渠道1剩余量") +public class Channel1QueryCmp extends NodeComponent { + @Override + public void process() throws Exception { + //mock下渠道1有2w条剩余量 + BatchMessageResultContext context = this.getFirstContextBean(); + context.addQueryVO(new QueryVO("channel1", 20000)); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel2Cmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel2Cmp.java new file mode 100644 index 000000000..8a326a0ec --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel2Cmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent(id = "channel2", name = "返回渠道2") +public class Channel2Cmp extends NodeComponent { + @Override + public void process() throws Exception { + BatchMessageResultContext context = this.getFirstContextBean(); + context.setFinalResultChannel("channel2"); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel2QueryCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel2QueryCmp.java new file mode 100644 index 000000000..308d1339a --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel2QueryCmp.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.benchmark.vo.QueryVO; +import com.yomahub.liteflow.core.NodeComponent; + +import java.util.Random; + +@LiteflowComponent(id = "channel2Query", name = "获取渠道2剩余量") +public class Channel2QueryCmp extends NodeComponent { + @Override + public void process() throws Exception { + + //mock下渠道2有1w条剩余量 + BatchMessageResultContext context = this.getFirstContextBean(); + context.addQueryVO(new QueryVO("channel2", 10000)); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel3Cmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel3Cmp.java new file mode 100644 index 000000000..c32d667e9 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel3Cmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent(id = "channel3", name = "返回渠道3") +public class Channel3Cmp extends NodeComponent { + @Override + public void process() throws Exception { + BatchMessageResultContext context = this.getFirstContextBean(); + context.setFinalResultChannel("channel3"); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel3QueryCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel3QueryCmp.java new file mode 100644 index 000000000..eb1765bf6 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel3QueryCmp.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.benchmark.vo.QueryVO; +import com.yomahub.liteflow.core.NodeComponent; + +import java.util.Random; + +@LiteflowComponent(id = "channel3Query", name = "获取渠道3剩余量") +public class Channel3QueryCmp extends NodeComponent { + @Override + public void process() throws Exception { + + //mock下渠道3有10w条剩余量 + BatchMessageResultContext context = this.getFirstContextBean(); + context.addQueryVO(new QueryVO("channel3", 100000)); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel4Cmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel4Cmp.java new file mode 100644 index 000000000..53232a4b0 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel4Cmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent(id = "channel4", name = "返回渠道4") +public class Channel4Cmp extends NodeComponent { + @Override + public void process() throws Exception { + BatchMessageResultContext context = this.getFirstContextBean(); + context.setFinalResultChannel("channel4"); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel4QueryCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel4QueryCmp.java new file mode 100644 index 000000000..d886e3bd2 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel4QueryCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.benchmark.vo.QueryVO; +import com.yomahub.liteflow.core.NodeComponent; + +import java.util.Random; + +@LiteflowComponent(id = "channel4Query", name = "获取渠道4剩余量") +public class Channel4QueryCmp extends NodeComponent { + @Override + public void process() throws Exception { + //mock下渠道4有7w条剩余量 + BatchMessageResultContext context = this.getFirstContextBean(); + context.addQueryVO(new QueryVO("channel4", 70000)); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel5Cmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel5Cmp.java new file mode 100644 index 000000000..42553cee3 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel5Cmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent(id = "channel5", name = "返回渠道5") +public class Channel5Cmp extends NodeComponent { + @Override + public void process() throws Exception { + BatchMessageResultContext context = this.getFirstContextBean(); + context.setFinalResultChannel("channel5"); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel5QueryCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel5QueryCmp.java new file mode 100644 index 000000000..e2c39c202 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel5QueryCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.benchmark.vo.QueryVO; +import com.yomahub.liteflow.core.NodeComponent; + +import java.util.Random; + +@LiteflowComponent(id = "channel5Query", name = "获取渠道5剩余量") +public class Channel5QueryCmp extends NodeComponent { + @Override + public void process() throws Exception { + //mock下渠道5有5000条剩余量 + BatchMessageResultContext context = this.getFirstContextBean(); + context.addQueryVO(new QueryVO("channel5", 5000)); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel6Cmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel6Cmp.java new file mode 100644 index 000000000..6b870690f --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel6Cmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent(id = "channel6", name = "返回渠道6") +public class Channel6Cmp extends NodeComponent { + @Override + public void process() throws Exception { + BatchMessageResultContext context = this.getFirstContextBean(); + context.setFinalResultChannel("channel6"); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel6QueryCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel6QueryCmp.java new file mode 100644 index 000000000..52c57fdf3 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/Channel6QueryCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.benchmark.vo.QueryVO; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent(id = "channel6Query", name = "获取渠道6剩余量") +public class Channel6QueryCmp extends NodeComponent { + @Override + public void process() throws Exception { + + //mock下渠道6有3w条剩余量 + BatchMessageResultContext context = this.getFirstContextBean(); + context.addQueryVO(new QueryVO("channel6", 30000)); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/ChannelSelectorCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/ChannelSelectorCmp.java new file mode 100644 index 000000000..9e8bee369 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/ChannelSelectorCmp.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.benchmark.context.BatchMessageResultContext; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.benchmark.vo.QueryVO; +import com.yomahub.liteflow.core.NodeComponent; + +import java.util.List; + +@LiteflowComponent(id = "channelSelector", name = "渠道余量最大选择器") +public class ChannelSelectorCmp extends NodeComponent { + @Override + public void process() throws Exception { + BatchMessageResultContext context = this.getFirstContextBean(); + + List queryList = context.getQueryResultList(); + + //选择渠道余量最大的 + QueryVO vo = queryList.stream().min((o1, o2) -> o2.getAvailCount() - o1.getAvailCount()).orElse(null); + + assert vo != null; + context.setFinalResultChannel(vo.getChannel()); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF1SwitchCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF1SwitchCmp.java new file mode 100644 index 000000000..8b505aad5 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF1SwitchCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +import java.util.Random; + +@LiteflowComponent(id = "if_1", name = "业务判断1") +public class IF1SwitchCmp extends NodeSwitchComponent { + @Override + public String processSwitch() throws Exception { + //这里写死跳到并行获取剩余量那条分支,你可以改成其他分支测试 + return "branch1"; + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF2SwitchCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF2SwitchCmp.java new file mode 100644 index 000000000..d026238a8 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF2SwitchCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +import java.util.Random; + +@LiteflowComponent(id = "if_2", name = "业务判断2") +public class IF2SwitchCmp extends NodeSwitchComponent { + @Override + public String processSwitch() throws Exception { + //这里写死,你可以改成其他分支 + return "s3"; + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF3SwitchCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF3SwitchCmp.java new file mode 100644 index 000000000..b2a27da52 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/IF3SwitchCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +import java.util.Random; + +@LiteflowComponent(id = "if_3", name = "业务判断3") +public class IF3SwitchCmp extends NodeSwitchComponent { + @Override + public String processSwitch() throws Exception { + + //这里写死,你可以改成其他 + return "channel5"; + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/PackageDataCmp.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/PackageDataCmp.java new file mode 100644 index 000000000..e1648a420 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/cmp/PackageDataCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +import java.util.Random; + +@LiteflowComponent(id = "packageData", name = "组装数据") +public class PackageDataCmp extends NodeComponent { + @Override + public void process() throws Exception { + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/context/BatchMessageResultContext.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/context/BatchMessageResultContext.java new file mode 100644 index 000000000..b53142a6b --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/context/BatchMessageResultContext.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.benchmark.context; + + +import com.yomahub.liteflow.benchmark.vo.QueryVO; + +import java.util.ArrayList; +import java.util.List; + +public class BatchMessageResultContext { + + private List queryResultList; + + private String finalResultChannel; + + public List getQueryResultList() { + return queryResultList; + } + + public void setQueryResultList(List queryResultList) { + this.queryResultList = queryResultList; + } + + public String getFinalResultChannel() { + return finalResultChannel; + } + + public void setFinalResultChannel(String finalResultChannel) { + this.finalResultChannel = finalResultChannel; + } + + public void addQueryVO(QueryVO queryVO){ + if (queryResultList == null){ + queryResultList = new ArrayList<>(); + } + queryResultList.add(queryVO); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/vo/QueryVO.java b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/vo/QueryVO.java new file mode 100644 index 000000000..53096cba9 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/java/com/yomahub/liteflow/benchmark/vo/QueryVO.java @@ -0,0 +1,31 @@ +package com.yomahub.liteflow.benchmark.vo; + +public class QueryVO { + + //渠道名称 + private String channel; + + //剩余短信包数量 + private int availCount; + + public QueryVO(String channel, int availCount) { + this.channel = channel; + this.availCount = availCount; + } + + public String getChannel() { + return channel; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public int getAvailCount() { + return availCount; + } + + public void setAvailCount(int availCount) { + this.availCount = availCount; + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/resources/application.properties b/liteflow-benchmark/liteflow-benchmark-compile/src/test/resources/application.properties new file mode 100644 index 000000000..c1d4f7007 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/resources/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=flow.xml +liteflow.fast-load=true \ No newline at end of file diff --git a/liteflow-benchmark/liteflow-benchmark-compile/src/test/resources/flow.xml b/liteflow-benchmark/liteflow-benchmark-compile/src/test/resources/flow.xml new file mode 100644 index 000000000..c8564c4b7 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-compile/src/test/resources/flow.xml @@ -0,0 +1,8 @@ + + + + selectBestChannel = THEN(WHEN(channel1Query, channel2Query, channel3Query,channel4Query, channel5Query, channel6Query),channelSelector).id("branch1"); + selectBizChannel = THEN(biz1,SWITCH(if_2).to(channel3,channel4,SWITCH(if_3).to(channel5, channel6).id("s3")).id("s2")).id("branch2"); + THEN(packageData,SWITCH(if_1).to(channel1,channel2,selectBestChannel,selectBizChannel),batchSender); + + \ No newline at end of file diff --git a/liteflow-benchmark/liteflow-benchmark-script-groovy/pom.xml b/liteflow-benchmark/liteflow-benchmark-script-groovy/pom.xml index b2e0ea09a..441950941 100644 --- a/liteflow-benchmark/liteflow-benchmark-script-groovy/pom.xml +++ b/liteflow-benchmark/liteflow-benchmark-script-groovy/pom.xml @@ -16,7 +16,7 @@ com.yomahub liteflow-script-groovy - ${revision} + ${liteflow-version} test diff --git a/liteflow-benchmark/liteflow-benchmark-script-java/pom.xml b/liteflow-benchmark/liteflow-benchmark-script-java/pom.xml index 139f0c987..8b4d9c8d6 100644 --- a/liteflow-benchmark/liteflow-benchmark-script-java/pom.xml +++ b/liteflow-benchmark/liteflow-benchmark-script-java/pom.xml @@ -16,7 +16,7 @@ com.yomahub liteflow-script-java - ${revision} + ${liteflow-version} test diff --git a/liteflow-benchmark/liteflow-benchmark-script-javax-pro/pom.xml b/liteflow-benchmark/liteflow-benchmark-script-javax-pro/pom.xml index a2ef8108b..63f7e85ab 100644 --- a/liteflow-benchmark/liteflow-benchmark-script-javax-pro/pom.xml +++ b/liteflow-benchmark/liteflow-benchmark-script-javax-pro/pom.xml @@ -16,7 +16,7 @@ com.yomahub liteflow-script-javax-pro - ${revision} + ${liteflow-version} test diff --git a/liteflow-benchmark/liteflow-benchmark-script-javax/pom.xml b/liteflow-benchmark/liteflow-benchmark-script-javax/pom.xml index 30405bb4c..5e3cc15f5 100644 --- a/liteflow-benchmark/liteflow-benchmark-script-javax/pom.xml +++ b/liteflow-benchmark/liteflow-benchmark-script-javax/pom.xml @@ -16,7 +16,7 @@ com.yomahub liteflow-script-javax - ${revision} + ${liteflow-version} test diff --git a/liteflow-benchmark/pom.xml b/liteflow-benchmark/pom.xml index 4a57df63d..94183e710 100644 --- a/liteflow-benchmark/pom.xml +++ b/liteflow-benchmark/pom.xml @@ -16,13 +16,14 @@ 1.37 + 2.15.2 com.yomahub liteflow-spring-boot-starter - ${revision} + ${liteflow-version} org.springframework.boot @@ -48,5 +49,6 @@ liteflow-benchmark-script-groovy liteflow-benchmark-common liteflow-benchmark-common-example + liteflow-benchmark-compile \ No newline at end of file diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index 2479619b1..f495a4840 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -371,7 +371,7 @@ public class LiteFlowChainELBuilder { // 解析el成为一个Condition // 为什么这里只是一个Condition,而不是一个List呢 // 这里无论多复杂的,外面必定有一个最外层的Condition,所以这里只有一个,内部可以嵌套很多层,这点和以前的不太一样 - QLResult expressResult = EXPRESS_RUNNER.execute(chain.getEl(), context, QLOptions.DEFAULT_OPTIONS); + QLResult expressResult = EXPRESS_RUNNER.execute(chain.getEl(), context, QLOptions.builder().cache(true).build()); Condition condition = (Condition) expressResult.getResult(); if (Objects.isNull(condition)){ @@ -431,8 +431,7 @@ public class LiteFlowChainELBuilder { // 解析el成为一个Condition // 为什么这里只是一个Condition,而不是一个List呢 // 这里无论多复杂的,外面必定有一个最外层的Condition,所以这里只有一个,内部可以嵌套很多层,这点和以前的不太一样 - - QLResult expressResult = EXPRESS_RUNNER.execute(elStr, context, QLOptions.DEFAULT_OPTIONS); + QLResult expressResult = EXPRESS_RUNNER.execute(elStr, context, QLOptions.builder().cache(true).build()); return (T) expressResult.getResult(); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/QlExpressUtils.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/QlExpressUtils.java index 7cf64cad1..8828d99c2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/QlExpressUtils.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/QlExpressUtils.java @@ -17,11 +17,13 @@ public class QlExpressUtils { /** * EL解析引擎 + * InterpolationMode.DISABLE意思是不对插值表达式进行处理 */ private final static Express4Runner EXPRESS_RUNNER = new Express4Runner(InitOptions.builder().interpolationMode(InterpolationMode.DISABLE).build()); /** * 上下文搜索解析引擎 + * QLSecurityStrategy.open()意思是将安全策略设置为开放 */ private final static Express4Runner CONTEXT_SEARCH_EXPRESS_RUNNER = new Express4Runner(InitOptions.builder().securityStrategy(QLSecurityStrategy.open()).build());