summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/main/Main.scala40
-rw-r--r--src/main/scala/main/domain/CpuOperations.scala2
-rw-r--r--src/main/scala/main/services/Stress.scala41
3 files changed, 22 insertions, 61 deletions
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
+ 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
+ /**
+ * 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)
- }.catchAll { error => Console.printError(s"failed: $error") }
- }.unit
}
}