diff --git a/benchmark/pom.xml b/benchmark/pom.xml new file mode 100644 index 000000000..62ae817df --- /dev/null +++ b/benchmark/pom.xml @@ -0,0 +1,496 @@ + + 4.0.0 + + + org.finos.vuu + vuu-parent + 0.4.65-SNAPSHOT + + + + 8.11.0 + benchmarks + + + benchmark + benchmark + benchmark + 2023 + jar + + + + org.finos.vuu + vuu + 0.4.65-SNAPSHOT + + + + + + org.scala-lang + scala-library + ${scala.version} + + + + org.scala-lang + scala-reflect + ${scala.version} + + + + junit + junit + 4.13.2 + test + + + + org.scalatest + scalatest_2.13 + ${scalatest.version} + test + + + org.scala-lang + scala-library + + + org.scala-lang + scala-reflect + + + + + + + + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + + + + + + + sign-it + + + sign + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.0.1 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + + + + legal-report + + + + org.scala-tools + maven-scala-plugin + ${maven.scala.plugin} + + + **/*.scala + + + + + + + + + + src/main/java + src/test/java + + + + + org.apache.maven.plugins + maven-source-plugin + + + + compile + + jar + + + + + + + org.apache.maven.plugins + maven-release-plugin + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + ${maven.compiler.source} + ${maven.compiler.target} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + + + + + + org.ow2.asm + asm + 6.2 + + + + + + + org.scala-tools + maven-scala-plugin + ${maven.scala.plugin} + + + + compile + testCompile + + + + + src/main/scala + src/test/scala + + -Xms64m + -Xmx1024m + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + generate-sources + + add-source + + + + target/generated-sources/antlr4 + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + ${uberjar.name} + + + org.openjdk.jmh.Main + + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + + test-jar + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.7 + + + + + + + org.scalatest + scalatest-maven-plugin + 2.0.2 + + ${project.build.directory}/surefire-reports + . + test-reports.txt + + + + test + + test + + + + + + + + + + + + + org.scala-tools + maven-scala-plugin + ${maven.scala.plugin} + + ${scala.version} + + + + + \ No newline at end of file diff --git a/benchmark/src/main/java/org/finos/vuu/benchmark/SortBenchmark2.java b/benchmark/src/main/java/org/finos/vuu/benchmark/SortBenchmark2.java new file mode 100644 index 000000000..c2c09ff89 --- /dev/null +++ b/benchmark/src/main/java/org/finos/vuu/benchmark/SortBenchmark2.java @@ -0,0 +1,27 @@ +package org.finos.vuu.benchmark; + +import org.openjdk.jmh.annotations.*; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +@State(Scope.Benchmark) +public class SortBenchmark2 { + + private SortBenchmark benchmark; + + @Setup + public void setup(){ + benchmark = new SortBenchmark(); + benchmark.setup(); + } + + @Benchmark + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @Warmup(iterations = 3) + @Measurement(iterations = 2) + @BenchmarkMode(Mode.AverageTime) + public void sortLargeTable() throws IOException { + benchmark.sortLargeTable(); + } +} diff --git a/benchmark/src/main/java/org/finos/vuu/benchmark/SortExample.java b/benchmark/src/main/java/org/finos/vuu/benchmark/SortExample.java new file mode 100644 index 000000000..ae8387a79 --- /dev/null +++ b/benchmark/src/main/java/org/finos/vuu/benchmark/SortExample.java @@ -0,0 +1,66 @@ +package org.finos.vuu.benchmark; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.Random; + +public class SortExample { + + private static void print(Object[][] arr){ + for(int c=0; c() { + @Override + public int compare(Object[] o1, Object[] o2) { + int res = 0; + + int i1 = (int)o1[1]; + int i2 = (int)o2[1]; + + int i3 = (int)o1[2]; + int i4 = (int)o2[2]; + + if(i1 < i2){ + res = -1; + }else if(i2 < i1){ + res = 1; + }else { + if(i3 < i4){ + res = -1; + }else if(i4 < i3){ + res = 1; + } + } + + return res; + } + }); + + //print(values); + } + + + +} diff --git a/benchmark/src/main/scala/org/finos/vuu/benchmark/SortBenchmark.scala b/benchmark/src/main/scala/org/finos/vuu/benchmark/SortBenchmark.scala new file mode 100644 index 000000000..c7fc1a80e --- /dev/null +++ b/benchmark/src/main/scala/org/finos/vuu/benchmark/SortBenchmark.scala @@ -0,0 +1,62 @@ +package org.finos.vuu.benchmark + +import org.finos.toolbox.collection.array.ImmutableArray +import org.finos.toolbox.time.{Clock, DefaultClock} +import org.finos.vuu.core.sort.{GenericSort, GenericSort2} +import org.finos.vuu.core.table.{SimpleDataTable, ViewPortColumnCreator} +import org.finos.vuu.net.{SortDef, SortSpec} +import org.openjdk.jmh.annotations._ +import org.openjdk.jmh.runner.Runner +import org.openjdk.jmh.runner.options.OptionsBuilder + +import java.io.IOException +import java.util.concurrent.TimeUnit + +@State(Scope.Benchmark) +class SortBenchmark { + + import SortBenchmarkHelper._ + + var table: SimpleDataTable = null + + @Setup(Level.Invocation) + def setup(): Unit = { + table = createBigTable(2_000_000) + } + + def doSort(table: SimpleDataTable, sort: GenericSort2): ImmutableArray[String] = { + val viewPortColumns = ViewPortColumnCreator.create(table, table.columns().filter(_.name.equals("exchange")).map(_.name).toList) + sort.doSort(table, table.primaryKeys, viewPortColumns) + } + + @Benchmark + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @Warmup(iterations = 5) + @Measurement(iterations = 10) + @BenchmarkMode(Array(Mode.AverageTime)) + @throws[IOException] + def sortLargeTable(): Unit = { + implicit val clock: Clock = new DefaultClock + val sort = GenericSort2(SortSpec(List(SortDef("exchange", 'A'))), table.getTableDef.columns.filter(_.name == "exchange").toList) + doSort(table, sort) + } + + def main(args: Array[String]): Unit = { + val opts = new OptionsBuilder() + .include(classOf[SortBenchmark].getSimpleName) + .warmupIterations(5) + .measurementIterations(5) + //.forks(1) + .build + new Runner(opts).run + } + +} + +object SortRun { + def main(args: Array[String]): Unit = { + val benchmark = new SortBenchmark() + benchmark.setup() + benchmark.sortLargeTable() + } +} \ No newline at end of file diff --git a/benchmark/src/main/scala/org/finos/vuu/benchmark/SortBenchmarkHelper.scala b/benchmark/src/main/scala/org/finos/vuu/benchmark/SortBenchmarkHelper.scala new file mode 100644 index 000000000..447d24165 --- /dev/null +++ b/benchmark/src/main/scala/org/finos/vuu/benchmark/SortBenchmarkHelper.scala @@ -0,0 +1,51 @@ +package org.finos.vuu.benchmark + +import org.finos.toolbox.jmx.MetricsProviderImpl +import org.finos.toolbox.lifecycle.LifecycleContainer +import org.finos.toolbox.time.{Clock, DefaultClock} +import org.finos.vuu.api.{Index, Indices, TableDef} +import org.finos.vuu.core.table.{Columns, DataTable, RowWithData, SimpleDataTable, TableContainer} +import org.finos.vuu.provider.JoinTableProviderImpl + +object SortBenchmarkHelper { + + def createBigTable(rows: Int): SimpleDataTable = { + implicit val clock: Clock = new DefaultClock + implicit val lifecycle: LifecycleContainer = new LifecycleContainer + implicit val metrics: MetricsProviderImpl = new MetricsProviderImpl + + val joinProvider = JoinTableProviderImpl() // new EsperJoinTableProviderImpl() + + val tableContainer = new TableContainer(joinProvider) + + // val outQueue = new OutboundRowPublishQueue() + // val highPriorityQueue = new OutboundRowPublishQueue() + // val viewPortContainer = new ViewPortContainer(tableContainer) + + val pricesDef = TableDef( + "prices", "ric", + Columns.fromNames("ric:String", "bid:Double", "ask:Double", "last:Double", "open:Double", "close:Double", "exchange:String"), + indices = Indices( + Index("exchange") + ), + "ric" + ) + + val table = new SimpleDataTable(pricesDef, joinProvider) + + (1 to rows).foreach(i => { + + val ric = "TST-" + i + + val exchange = if (i % 2 == 0) "A" + else if (i % 3 == 0) "B" + else if (i % 4 == 0) "C" + else "D" + + val row = RowWithData(ric, Map("ask" -> 100, "bid" -> 101, "last" -> 105, "exchange" -> exchange)) + + table.processUpdate(ric, row, 1l) + }) + table + } +} diff --git a/pom.xml b/pom.xml index 2c9838058..a375541fd 100644 --- a/pom.xml +++ b/pom.xml @@ -75,12 +75,14 @@ 4.4.1 1.4.2 1.2.9 + 1.36 toolbox vuu vuu-ui + benchmark diff --git a/toolbox/src/main/scala/org/finos/toolbox/collection/array/ImmutableArray.scala b/toolbox/src/main/scala/org/finos/toolbox/collection/array/ImmutableArray.scala index 8e2f2d5a3..c707a87c8 100644 --- a/toolbox/src/main/scala/org/finos/toolbox/collection/array/ImmutableArray.scala +++ b/toolbox/src/main/scala/org/finos/toolbox/collection/array/ImmutableArray.scala @@ -7,7 +7,7 @@ object ImmutableArray{ def empty[T](implicit c: ClassTag[T]): ImmutableArray[T] = { new ChunkedUniqueImmutableArraySet[T](Set(), Array(), chunkSize = 5000) } - def from[T](array: Array[T])(implicit c: ClassTag[T]) = { + def from[T](array: Array[T])(implicit c: ClassTag[T]): ImmutableArray[T] = { empty[T].addAll(new NaiveImmutableArray[T](array)) } } diff --git a/vuu/pom.xml b/vuu/pom.xml index 69c1eefae..93243431a 100644 --- a/vuu/pom.xml +++ b/vuu/pom.xml @@ -187,6 +187,18 @@ ${typesafe.conf.version} + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + + + diff --git a/vuu/src/main/resources/runconfigurations/SimulMain.run.xml b/vuu/src/main/resources/runconfigurations/SimulMain.run.xml index f522f2982..e978597db 100644 --- a/vuu/src/main/resources/runconfigurations/SimulMain.run.xml +++ b/vuu/src/main/resources/runconfigurations/SimulMain.run.xml @@ -1,6 +1,6 @@ -