Browse Source

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

Alex Schneider 11 years ago
parent
commit
c7c18d1f67

+ 48 - 0
scruffy/.gitignore

@@ -0,0 +1,48 @@
+## generic files to ignore
+*~
+*.lock
+*.DS_Store
+*.swp
+*.out
+
+# java specific
+*.class
+
+# python specific
+*.pyc
+
+# sbt specific
+target/
+project/boot
+lib_managed/*
+project/build/target
+project/build/lib_managed
+project/build/src_managed
+project/plugins/lib_managed
+project/plugins/target
+project/plugins/src_managed
+project/plugins/project
+
+core/lib_managed
+core/target
+pubsub/lib_managed
+pubsub/target
+
+# eclipse specific
+.metadata
+jrebel.lic
+.settings
+.classpath
+.project
+
+.ensime*
+*.sublime-*
+.cache
+
+# intellij
+*.eml
+*.iml
+*.ipr
+*.iws
+.*.sw?
+.idea

+ 34 - 0
scruffy/README.md

@@ -0,0 +1,34 @@
+#Scruffy Benchmarking Test
+
+This is the Scruffy portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+## Infrastructure Software Versions
+
+The tests were run with:
+
+* [Java OpenJDK 1.7.0_09](http://openjdk.java.net/)
+* [Scruffy 1.4.15](http://scruffy-project.github.io/)
+
+## Test URLs
+
+### Test type 1: JSON serialization
+
+http://localhost:8080/json
+
+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
+
+* [Test 6 source](src/main/scala/scruffy/examples/Test6Endpoint.scala)

+ 0 - 0
scruffy/__init__.py


+ 25 - 0
scruffy/benchmark_config

@@ -0,0 +1,25 @@
+{
+  "framework": "scruffy",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "MongoDB",
+      "framework": "scruffy",
+      "language": "Scala",
+      "orm": "Raw",
+      "platform": "Netty",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "scruffy",
+      "notes": "",
+      "versus": "Netty"
+    }
+  }]
+}

+ 14 - 0
scruffy/build.sbt

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

+ 3 - 0
scruffy/install.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+fw_depends java

+ 1 - 0
scruffy/project/build.properties

@@ -0,0 +1 @@
+sbt.version=0.13.2

+ 1 - 0
scruffy/project/plugins.sbt

@@ -0,0 +1 @@
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")

+ 35 - 0
scruffy/setup.py

@@ -0,0 +1,35 @@
+
+import subprocess
+import sys
+import time
+import os
+
+def start(args, logfile, errfile):
+  if os.name == 'nt':
+    subprocess.check_call('"..\\sbt\\sbt.bat" assembly', shell=True, cwd="scruffy", stderr=errfile, stdout=logfile)
+  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.1.jar -Dhostname" + args.database_host,
+                    cwd="scruffy",
+                    shell=True,
+                    stderr=errfile,
+                    stdout=logfile)
+  time.sleep(5)
+  return 0
+
+def stop(logfile, errfile):
+  if os.name == 'nt':
+    subprocess.check_call("wmic process where \"CommandLine LIKE '%scruffy-benchmark%'\" call terminate", stderr=errfile, stdout=logfile)
+  else:
+    p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
+    out, err = p.communicate()
+    for line in out.splitlines():
+      if 'scruffy-benchmark' in line:
+        try:
+          pid = int(line.split(None, 2)[1])
+          os.kill(pid, 15)
+        except OSError:
+          pass
+  
+  return 0

+ 4 - 0
scruffy/source_code

@@ -0,0 +1,4 @@
+./scruffy/src/main/scala/scruffy/examples/
+./scruffy/src/main/scala/scruffy/examples/Main.scala
+./scruffy/src/main/scala/scruffy/examples/Test1Route.scala
+./scruffy/src/main/scala/scruffy/examples/Test6Route.scala

+ 17 - 0
scruffy/src/main/scala/scruffy/examples/Main.scala

@@ -0,0 +1,17 @@
+package scruffy.examples
+
+import com.sksamuel.scruffy.{ScruffyConfiguration, Scruffy}
+
+/** @author Stephen Samuel */
+object Main extends App {
+
+  val port = 8080
+  val scruffy = new Scruffy(ScruffyConfiguration.port(port).compression(false).requestLogging(false))
+  scruffy.mount(new Test1Endpoint)
+  scruffy.mount(new Test2Endpoint(Option(System.getProperty("hostname")).getOrElse("localhost")))
+  scruffy.mount(new Test6Endpoint)
+  println("Starting Scruffy...")
+  val lifecycle = scruffy.start()
+  println(s"Started on port [$port]. Interrupt to exit.")
+  lifecycle.await()
+}

+ 13 - 0
scruffy/src/main/scala/scruffy/examples/Test1Endpoint.scala

@@ -0,0 +1,13 @@
+package scruffy.examples
+
+import com.sksamuel.scruffy.EndpointProvider
+
+/** @author Stephen Samuel */
+class Test1Endpoint extends EndpointProvider {
+
+  get("json").complete {
+    req => json(Message("Hello, World!"))
+  }
+}
+
+case class Message(message: String)

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

@@ -0,0 +1,28 @@
+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("hello_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).toDouble))
+
+  get("db").json {
+    req =>
+      val id = random.nextInt(10000)
+      val dbo = collection.findOne(DBObject("_id" -> id), fields)
+      val randomNumber = Math.round(dbo.get("randomNumber").toString.toFloat)
+      Output(id, randomNumber)
+  }
+}
+
+case class Output(id: Int, randomNumber: Int)

+ 13 - 0
scruffy/src/main/scala/scruffy/examples/Test6Endpoint.scala

@@ -0,0 +1,13 @@
+package scruffy.examples
+
+import com.sksamuel.scruffy.EndpointProvider
+import com.sksamuel.scruffy.http.MediaType
+
+/** @author Stephen Samuel */
+class Test6Endpoint extends EndpointProvider {
+
+  get("plaintext").complete {
+    req => entity("Hello, World!", MediaType.TextPlain)
+  }
+
+}