Browse Source

Moved the RNG out of the transaction

Andreas C. Osowski 12 years ago
parent
commit
3907b01cfa

+ 14 - 10
lift-stateless/src/main/scala/Benchmark.scala

@@ -23,7 +23,7 @@ object JsonBenchmark {
     }
     }
 
 
   def sayHello() = Full(JsonResponse(
   def sayHello() = Full(JsonResponse(
-    JE.JsObj("message" -> "Hello World!")
+    JObject(List(JField("message", JString("Hello World!"))))
   ))
   ))
 }
 }
 
 
@@ -37,24 +37,28 @@ object DbBenchmark {
             case r @ Req("db" :: queries :: Nil, _ , _) => () => customQuery(queries.toInt)
             case r @ Req("db" :: queries :: Nil, _ , _) => () => customQuery(queries.toInt)
     }
     }
 
 
-  def customQuery(count: Int) : Box[LiftResponse] = DB.exec {
+  def customQuery(count: Int) : Box[LiftResponse] = {
     val tlc = ThreadLocalRandom.current()
     val tlc = ThreadLocalRandom.current()
     val randoms = for(i <- (1 to count)) yield tlc.nextLong(DB_ROWS)
     val randoms = for(i <- (1 to count)) yield tlc.nextLong(DB_ROWS)
-    val result = (for {
-      w <- WorldTable
-      if w.id inSetBind randoms
-    } yield w).list
+    val result = DB.exec {
+      (for {
+        w <- WorldTable
+        if w.id inSetBind randoms
+      } yield w).list
+    }
 
 
     Full(JsonResponse(JArray(result.map(_.toJson))))
     Full(JsonResponse(JArray(result.map(_.toJson))))
   }
   }
 
 
-  def singleQuery() : Box[LiftResponse] = DB.exec {
+  def singleQuery() : Box[LiftResponse] = {
     val tlc = ThreadLocalRandom.current()
     val tlc = ThreadLocalRandom.current()
     val random = tlc.nextLong(DB_ROWS)
     val random = tlc.nextLong(DB_ROWS)
 
 
-    val result  = (for {
-      w <- WorldTable if w.id === random
-    } yield w).list
+    val result = DB.exec {
+      (for {
+        w <- WorldTable if w.id === random
+      } yield w).list
+    }
 
 
 
 
     Full(JsonResponse(result(0).toJson))
     Full(JsonResponse(result(0).toJson))

+ 2 - 0
lift-stateless/src/main/scala/Boot.scala

@@ -19,6 +19,8 @@ class Boot {
     LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
     LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
 
 
 
 
+    LiftRules.setSiteMap(SiteMap())
+
     lib.JsonBenchmark.init()
     lib.JsonBenchmark.init()
     lib.DbBenchmark.init()
     lib.DbBenchmark.init()
 
 

+ 6 - 7
lift-stateless/src/main/scala/DB.scala

@@ -8,7 +8,6 @@ import Main.config
 import scala.slick.driver.MySQLDriver.simple._
 import scala.slick.driver.MySQLDriver.simple._
 
 
 import Database.threadLocalSession
 import Database.threadLocalSession
-import net.liftweb.json.Extraction
 
 
 
 
 object DB {
 object DB {
@@ -41,15 +40,15 @@ object DB {
     database withTransaction {
     database withTransaction {
       fn
       fn
     }
     }
-
-
-
-
 }
 }
 
 
   case class World(id: Option[Long], randomNumber: Long) {
   case class World(id: Option[Long], randomNumber: Long) {
-    private implicit val formats = net.liftweb.json.DefaultFormats
-    def toJson = Extraction.decompose(this)
+    import net.liftweb.json._
+
+    def toJson = JObject(List(
+      JField("id", JInt(id.get)),
+      JField("randomNumber", JInt(randomNumber))
+    ))
   }
   }
 
 
    object WorldTable extends Table[World]("World") {
    object WorldTable extends Table[World]("World") {