This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git
commit eff495dfc3cb8e7bf80af17c3772ecd0bcf4032e Author: Lei Zhang <[email protected]> AuthorDate: Thu Sep 26 17:52:53 2019 +0800 SCB-1368 Added the globalTxId prefix for concurrent --- .../pack/alpha/benchmark/SagaEventBenchmark.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/alpha/alpha-benchmark/src/main/java/org/apache/servicecomb/pack/alpha/benchmark/SagaEventBenchmark.java b/alpha/alpha-benchmark/src/main/java/org/apache/servicecomb/pack/alpha/benchmark/SagaEventBenchmark.java index 322aa54..e73ad9d 100644 --- a/alpha/alpha-benchmark/src/main/java/org/apache/servicecomb/pack/alpha/benchmark/SagaEventBenchmark.java +++ b/alpha/alpha-benchmark/src/main/java/org/apache/servicecomb/pack/alpha/benchmark/SagaEventBenchmark.java @@ -21,6 +21,7 @@ import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.List; import java.util.OptionalDouble; +import java.util.Random; import java.util.UUID; import java.util.concurrent.CountDownLatch; @@ -62,9 +63,9 @@ public class SagaEventBenchmark { CountDownLatch begin = new CountDownLatch(1); CountDownLatch end = new CountDownLatch(concurrency); begin.countDown(); + String[] id_prefixs = generateRandomIdPrefix(concurrency); for (int i = 0; i < concurrency; i++) { - String id_prefix = ""; - Execute execute = new Execute(sender, id_prefix,requests / concurrency, begin, end); + Execute execute = new Execute(sender, id_prefixs[i],requests / concurrency, begin, end); new Thread(execute).start(); } try { @@ -155,7 +156,7 @@ public class SagaEventBenchmark { for (int i = 0; i < requests; i++) { metrics.completeRequestsIncrement(); long s = System.currentTimeMillis(); - final String globalTxId = UUID.randomUUID().toString(); + final String globalTxId = id_prefix + "-" + i; final String localTxId_1 = UUID.randomUUID().toString(); final String localTxId_2 = UUID.randomUUID().toString(); final String localTxId_3 = UUID.randomUUID().toString(); @@ -209,4 +210,17 @@ public class SagaEventBenchmark { new TxEvent(EventType.SagaEndedEvent, globalTxId, globalTxId, globalTxId, "", 0, null, 0)); return sagaEvents; } + + private String[] generateRandomIdPrefix(int numberOfWords) { + String[] randomStrings = new String[numberOfWords]; + Random random = new Random(); + for (int i = 0; i < numberOfWords; i++) { + char[] word = new char[8]; + for (int j = 0; j < word.length; j++) { + word[j] = (char) ('a' + random.nextInt(26)); + } + randomStrings[i] = new String(word); + } + return randomStrings; + } }
