Browse Source

Merge branch 'master' of te.github.com:TechEmpower/FrameworkBenchmarks

Patrick Falls 12 years ago
parent
commit
3cd4aebf83

+ 4 - 2
framework_test.py

@@ -10,7 +10,9 @@ class FrameworkTest:
   ##########################################################################################
   # Class variables
   ##########################################################################################
-  headers = "-H 'Host: localhost' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) Gecko/20130501 Firefox/30.0 AppleWebKit/600.00 Chrome/30.0.0000.0 Trident/10.0 Safari/600.00' -H 'Cookie: uid=12345678901234567890; __utma=1.1234567890.1234567890.1234567890.1234567890.12; wd=2560x1600' -H 'Connection: keep-alive'"
+  headers = "-H 'Host: localhost' -H 'Accept: text/html,application/xhtml+xml,application/xml' -H 'Connection: keep-alive'"
+  headers_full = "-H 'Host: localhost' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) Gecko/20130501 Firefox/30.0 AppleWebKit/600.00 Chrome/30.0.0000.0 Trident/10.0 Safari/600.00' -H 'Cookie: uid=12345678901234567890; __utma=1.1234567890.1234567890.1234567890.1234567890.12; wd=2560x1600' -H 'Connection: keep-alive'"
+ 
   concurrency_template = """
     
     echo ""
@@ -35,7 +37,7 @@ class FrameworkTest:
       echo ""
       echo "---------------------------------------------------------"
       echo " Concurrency: $c for {name}"
-      echo " {wrk} {headers} -d {duration} -c $c -t $(($c>{max_threads}?{max_threads}:$c)) http://{server_host}:{port}{url}"
+      echo " {wrk} {headers} {pipeline} -d {duration} -c $c -t $(($c>{max_threads}?{max_threads}:$c)) http://{server_host}:{port}{url}"
       echo "---------------------------------------------------------"
       echo ""
       {wrk} {headers} {pipeline} -d {duration} -c "$c" -t "$(($c>{max_threads}?{max_threads}:$c))" http://{server_host}:{port}{url}

+ 1 - 0
spray/benchmark_config

@@ -4,6 +4,7 @@
         "default" : {
             "setup_file" : "setup",
             "json_url" : "/json",
+            "plaintext_url": "/plaintext",
             "port": 8080,
             "sort": 114
             }

+ 1 - 1
spray/build.sbt

@@ -15,7 +15,7 @@ resolvers ++= Seq(
 
 libraryDependencies ++= Seq(
   "io.spray" %% "spray-json" % "1.2.4",
-  "io.spray" % "spray-can" % "1.1-20130513",
+  "io.spray" % "spray-can" % "1.1-M8",
   "com.typesafe.akka" %%  "akka-actor" % "2.1.2",
   "com.typesafe.akka" %%  "akka-slf4j" % "2.1.2",
   "ch.qos.logback"% "logback-classic" % "1.0.12" % "runtime"

+ 16 - 8
spray/src/main/scala/spray/examples/BenchmarkService.scala

@@ -5,6 +5,7 @@ import scala.concurrent.duration._
 import spray.can.Http
 import spray.json._
 import spray.http._
+import spray.util._
 import MediaTypes._
 import HttpMethods._
 import StatusCodes._
@@ -13,11 +14,21 @@ class BenchmarkService extends Actor {
   import context.dispatcher
   import Uri._
   import Uri.Path._
+  val message = "Hello, World!".getAsciiBytes
+  val unknownResource = HttpResponse(NotFound, entity = "Unknown resource!")
 
   def fastPath: Http.FastPath = {
-    case HttpRequest(GET, Uri(_, _, Slash(Segment("json", Path.Empty)), _, _), _, _, _) =>
-      val json = JsObject("message" -> JsString("Hello, World!"))
-      HttpResponse(entity = HttpEntity(ContentType.`application/json`, json.compactPrint))
+    case HttpRequest(GET, Uri(_, _, Slash(Segment(x, Path.Empty)), _, _), _, _, _) =>
+      x match {
+        case "json" =>
+          val json = JsObject("message" -> JsString("Hello, World!"))
+          HttpResponse(entity = HttpEntity(ContentTypes.`application/json`, json.compactPrint))
+        case "plaintext" => HttpResponse(entity = HttpEntity(ContentTypes.`text/plain`, message))
+        case "stop" =>
+          context.system.scheduler.scheduleOnce(1.second) { context.system.shutdown() }
+          HttpResponse(entity = "Shutting down in 1 second ...")
+        case _ => unknownResource
+      }
   }
 
   def receive = {
@@ -32,6 +43,7 @@ class BenchmarkService extends Actor {
             <p>Defined resources:</p>
             <ul>
               <li><a href="/json">/json</a></li>
+              <li><a href="/plaintext">/plaintext</a></li>
               <li><a href="/stop">/stop</a></li>
             </ul>
           </body>
@@ -39,10 +51,6 @@ class BenchmarkService extends Actor {
       )
     )
 
-    case HttpRequest(GET, Path("/stop"), _, _, _) =>
-      sender ! HttpResponse(entity = "Shutting down in 1 second ...")
-      context.system.scheduler.scheduleOnce(1.second) { context.system.shutdown() }
-
-    case _: HttpRequest => sender ! HttpResponse(NotFound, entity = "Unknown resource!")
+    case _: HttpRequest => sender ! unknownResource
   }
 }