Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions scruffy/.gitignore
Original file line number Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions scruffy/README.md
Original file line number Diff line number Diff line change
@@ -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)
Empty file added scruffy/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions scruffy/benchmark_config
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions scruffy/build.sbt
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions scruffy/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

fw_depends scala
1 change: 1 addition & 0 deletions scruffy/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.2
1 change: 1 addition & 0 deletions scruffy/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
35 changes: 35 additions & 0 deletions scruffy/setup.py
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions scruffy/source_code
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions scruffy/src/main/scala/scruffy/examples/Main.scala
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions scruffy/src/main/scala/scruffy/examples/Test1Endpoint.scala
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions scruffy/src/main/scala/scruffy/examples/Test2Endpoint.scala
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions scruffy/src/main/scala/scruffy/examples/Test6Endpoint.scala
Original file line number Diff line number Diff line change
@@ -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)
}

}