Browse Source

Added test 2 to scruffy benchmarks

sksamuel 11 years ago
parent
commit
07cd26549e

+ 19 - 9
scruffy/README.md

@@ -2,23 +2,33 @@
 
 This is the Scruffy portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
 
-### JSON Encoding Test
-This example uses the built-in Jackson for json support.
-
-* [JSON test source](src/main/scala/scruffy/examples/Test1Endpoint.scala)
-
 ## Infrastructure Software Versions
+
 The tests were run with:
 
 * [Java OpenJDK 1.7.0_09](http://openjdk.java.net/)
-* [Scruffy 1.4.14](http://scruffy-project.github.io/)
+* [Scruffy 1.4.15](http://scruffy-project.github.io/)
 
 ## Test URLs
 
-### JSON Encoding Test
+### Test type 1: JSON serialization
 
 http://localhost:8080/json
 
-### Plain Text Test
+This example uses the built-in Jackson for json support.
+
+* [Test 1 source](src/main/scala/scruffy/examples/Test1Endpoint.scala)
+
+### Test type 2: Single database query
+
+This example uses casbah for Mongo queries. Future improvement would be to switch to a nonblocking library.
+
+* [Test 2 source](src/main/scala/scruffy/examples/Test2Endpoint.scala)
+
+http://localhost:8080/db
+
+### Test type 6: Plaintext
+
+http://localhost:8080/plaintext
 
-http://localhost:8080/plaintext
+* [Test 6 source](src/main/scala/scruffy/examples/Test6Endpoint.scala)

+ 3 - 3
scruffy/build.sbt

@@ -2,13 +2,13 @@ name := "scruffy-benchmark"
 
 organization := "com.sksamuel.scruffy"
 
-scalaVersion := "2.11.0"
+scalaVersion := "2.11.1"
 
 version := "1.0.1"
 
 libraryDependencies ++= Seq(
-    "com.sksamuel.scruffy" %% "scruffy-server" % "1.4.14",
-    "org.mongodb" %% "casbah-core" % "2.7.1"
+  "com.sksamuel.scruffy" %% "scruffy-server" % "1.4.14",
+  "org.mongodb" %% "casbah-core" % "2.7.1"
 )
 
 sbtassembly.Plugin.assemblySettings

+ 5 - 2
scruffy/setup.py

@@ -10,8 +10,11 @@ def start(args, logfile, errfile):
   else:
     subprocess.check_call("../sbt/sbt assembly", shell=True, cwd="scruffy", stderr=errfile, stdout=logfile)
     
-  subprocess.Popen("java -jar target/scala-2.11/scruffy-benchmark-assembly-1.0.jar", cwd="scruffy", shell=True,
-                   stderr=errfile, stdout=logfile)
+  subprocess.Popen("java -jar target/scala-2.11/scruffy-benchmark-assembly-1.0.1.jar -Dhostname" + args.database_host,
+                    cwd="scruffy",
+                    shell=True,
+                    stderr=errfile,
+                    stdout=logfile)
   time.sleep(5)
   return 0
 

+ 2 - 1
scruffy/src/main/scala/scruffy/examples/Main.scala

@@ -6,8 +6,9 @@ import com.sksamuel.scruffy.{ScruffyConfiguration, Scruffy}
 object Main extends App {
 
   val port = 8080
-  val scruffy = new Scruffy(ScruffyConfiguration.port(port))
+  val scruffy = new Scruffy(ScruffyConfiguration.port(port).compression(false))
   scruffy.mount(new Test1Endpoint)
+  scruffy.mount(new Test2Endpoint(Option(System.getProperty("hostname")).getOrElse("localhost")))
   scruffy.mount(new Test6Endpoint)
   scruffy.start().await()
 }

+ 26 - 0
scruffy/src/main/scala/scruffy/examples/Test2Endpoint.scala

@@ -0,0 +1,26 @@
+package scruffy.examples
+
+import com.mongodb.casbah.Imports._
+import com.sksamuel.scruffy.EndpointProvider
+
+/** @author Stephen Samuel */
+class Test2Endpoint(hostname: String) extends EndpointProvider {
+
+  val connection = MongoConnection(hostname, 27017)
+  val collection = connection.getDB("world").getCollection("world")
+
+  val random = new scala.util.Random(System.currentTimeMillis)
+  val fields = DBObject("_id" -> true, "randomNumber" -> true)
+
+  // uncomment to populate
+  // for ( k <- 1 to 10000 )
+  //   collection.save(DBObject("_id" -> k, "id" -> k, "randomNumber" -> random.nextInt(10000)))
+
+  get("db").json {
+    req =>
+      val id = random.nextInt(10000)
+      collection.findOne(DBObject("_id" -> id), fields)
+  }
+}
+
+