From f26520d7ce574486becd87d44006e0340d97d39a Mon Sep 17 00:00:00 2001 From: Abdellah El Morabit Date: Mon, 1 Dec 2025 10:28:47 +0100 Subject: checkpoint: everything is working, except for http, and a couple memory leaks --- src/main/scala/main/Main.scala | 40 ++-------------------- src/main/scala/main/domain/CpuOperations.scala | 2 +- src/main/scala/main/services/Stress.scala | 47 ++++++++++++-------------- 3 files changed, 25 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/main/scala/main/Main.scala b/src/main/scala/main/Main.scala index e1660d6..05770a9 100644 --- a/src/main/scala/main/Main.scala +++ b/src/main/scala/main/Main.scala @@ -21,44 +21,10 @@ import zio._ object Torque extends ZIOAppDefault with Runner { - - def run: ZIO[Any, Throwable, Unit] = { - - handler() - - - /** - * In case the user needs a quick basic run without running through the DIY DUI - * */ - - // args(1) match { - // case "cpu" => lightCpuRun - // case "ram" => lightRamRun - // case _ => handler() - // } - - } - - - /** - * - * Stress the given target - * Capture the information - * and send that over an API - * - * => doing these steps in a handler to be a little more modular - * */ - - def handler(): ZIO[Any, Throwable, Unit] = { + def run: ZIO[Any, Throwable, Unit] = { val v: View = new View - - for { - - _ <- ZIO.debug("started") - _ <- v.serveView.fork - _ <- ZIO.debug("finished") - - } yield () + v.serveView } + } diff --git a/src/main/scala/main/domain/CpuOperations.scala b/src/main/scala/main/domain/CpuOperations.scala index 0f4cecb..328d65e 100644 --- a/src/main/scala/main/domain/CpuOperations.scala +++ b/src/main/scala/main/domain/CpuOperations.scala @@ -38,7 +38,7 @@ trait CPU { class Prime extends CPU { def run(n: Int): Unit = { - for i <- 0 to n do if isPrime(i) == true then println("true") else println("false") + for i <- 0 to n do isPrime(i) } private def isPrime(n: Int): Boolean = { diff --git a/src/main/scala/main/services/Stress.scala b/src/main/scala/main/services/Stress.scala index 930f521..a4349f5 100644 --- a/src/main/scala/main/services/Stress.scala +++ b/src/main/scala/main/services/Stress.scala @@ -79,12 +79,12 @@ class StressRam() extends Stress { val list: List[Int] = List(2030994, 493084, 43434, 43904 ,2103092, 230932) val offset: Int = 4 - ZIO.attempt { - - memoryAllocater.setValues(list, offset) - memoryAllocater.deallocateMemory - - }.catchAll { error => Console.printError(s"failed: sequential memory error")} + /** + * The memory methods have a Unit return type so we wrap them in a + * ZIO attempt which returns a [R, E, A] + * */ + val r = ZIO.attempt { memoryAllocater.setValues(list, offset) } *> ZIO.attempt { memoryAllocater.deallocateMemory } + r.repeat(Schedule.forever.unit) } @@ -95,26 +95,21 @@ class StressRam() extends Stress { * I wanted to set affinities per core but not there yet * source: https://zio.dev/overview/basic-concurrency/ * */ - ZIO.foreachPar(1 to 8) { - /** - * no need to save wich worked were on at the moment - *so were throwing it away with _ - */ - _ => ZIO.attemptBlocking { - - val list = List.fill(6)(rand.nextInt(1000000) + 100000) - /** - * still setting an offset of 4 because - * we are filling then memory with 4 byte integers - */ - val offset = 4 - - memoryAllocater.setValues(list, offset) - memoryAllocater.deallocateMemory - - - }.catchAll { error => Console.printError(s"failed: $error") } - }.unit + val list = List.fill(6)(rand.nextInt(1000000) + 100000) + /** + * still setting an offset of 4 because + * we are filling then memory with 4 byte integers + */ + val offset = 4 + + /** + * The memory methods have a Unit return type so we wrap them in a + * ZIO attempt which returns a [R, E, A] + * */ + var r = ZIO.attempt { memoryAllocater.setValues(list, offset) } *> ZIO.attempt { memoryAllocater.deallocateMemory } + r.repeat(Schedule.forever.unit) + + } } -- cgit v1.2.3-70-g09d2