From 7b7f5b40c31acb89d92cc5e4d0518d1ef7237094 Mon Sep 17 00:00:00 2001 From: naleeha Date: Tue, 6 Feb 2024 00:47:51 +0000 Subject: [PATCH] #989 ignite vuu main to start as server and load test orders --- .../vuu/example/ignite/IgniteVuuMain.scala | 14 +++++-- .../ignite/loader/IgniteOrderGenerator.scala | 40 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/loader/IgniteOrderGenerator.scala diff --git a/example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/IgniteVuuMain.scala b/example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/IgniteVuuMain.scala index 59ad56a56..9d42fb482 100644 --- a/example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/IgniteVuuMain.scala +++ b/example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/IgniteVuuMain.scala @@ -14,6 +14,7 @@ import org.finos.vuu.core.module.price.PriceModule import org.finos.vuu.core.module.simul.SimulationModule import org.finos.vuu.core.module.typeahead.TypeAheadModule import org.finos.vuu.core.module.vui.VuiStateModule +import org.finos.vuu.example.ignite.loader.IgniteOrderGenerator import org.finos.vuu.example.ignite.module.IgniteOrderDataModule import org.finos.vuu.net.auth.AlwaysHappyAuthenticator import org.finos.vuu.net.http.VuuHttp2ServerOptions @@ -54,6 +55,11 @@ object IgniteVuuMain extends App with StrictLogging { val certPath = defaultConfig.getString("vuu.certPath") val keyPath = defaultConfig.getString("vuu.keyPath") + logger.info("[Ignite] Starting ignite in server mode") + private val igniteOrderStore = IgniteOrderStore(clientMode = false) + private val igniteOrderGenerator = new IgniteOrderGenerator(igniteOrderStore) + igniteOrderGenerator.save() + val config = VuuServerConfig( VuuHttp2ServerOptions() //only specify webroot if we want to load the source locally, we'll load it from the jar @@ -75,9 +81,10 @@ object IgniteVuuMain extends App with StrictLogging { VuuThreadingOptions() .withViewPortThreads(4) .withTreeThreads(4) - ).withModule(MetricsModule()) - .withModule(IgniteOrderDataModule(IgniteOrderStore())) - .withPlugin(VirtualizedTablePlugin) + ).withModule(TypeAheadModule()) + .withModule(MetricsModule()) + .withModule(IgniteOrderDataModule(igniteOrderStore)) + .withPlugin(VirtualizedTablePlugin) val vuuServer = new VuuServer(config) @@ -86,4 +93,5 @@ object IgniteVuuMain extends App with StrictLogging { logger.info("[VUU] Ready.") vuuServer.join() + } diff --git a/example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/loader/IgniteOrderGenerator.scala b/example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/loader/IgniteOrderGenerator.scala new file mode 100644 index 000000000..a892cc741 --- /dev/null +++ b/example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/loader/IgniteOrderGenerator.scala @@ -0,0 +1,40 @@ +package org.finos.vuu.example.ignite.loader + +import com.typesafe.scalalogging.StrictLogging +import org.finos.toolbox.lifecycle.LifecycleContainer +import org.finos.toolbox.time.Clock +import org.finos.vuu.core.module.simul.model.{ChildOrder, OrderStore} +import org.finos.vuu.core.module.simul.provider.{ParentChildOrdersModel, SeededRandomNumbers} + +import java.util.concurrent.Executors +import java.util.concurrent.atomic.LongAdder + +class IgniteOrderGenerator(orderStore: OrderStore) (implicit clock: Clock, lifecycleContainer: LifecycleContainer) extends StrictLogging{ + + implicit val randomNumbers: SeededRandomNumbers = new SeededRandomNumbers(clock.now()) + private val ordersModel = new ParentChildOrdersModel() + private val childOrderCounter = new LongAdder() + private val executor = Executors.newWorkStealingPool() + + def save(): Unit = { + + logger.info("[Ignite] Saving orders to ignite.") + (0 until 4_000).foreach(i => + executor.execute { () => + val parent = ordersModel.createParent() + val childrenToCreate = randomNumbers.seededRand(100, 250) + + val children = (0 until childrenToCreate) + .map(_ => ordersModel.createChild(parent)) + .foldLeft(List[ChildOrder]())((acc, child) => acc :+ child) + + orderStore.storeParentOrderWithChildren(parent, children) + childOrderCounter.add(children.length) + if (i % 1000 == 0) { + println(s"[${Thread.currentThread().getName}] Loaded : $i parent orders and ${childOrderCounter.sum()} child orders") + } + }) + } + + +}