Browse Source

Merge branch 'jmgao-play-scala'

Patrick Falls 12 years ago
parent
commit
14a01d9f6b

+ 2 - 2
play-java/setup.py

@@ -17,7 +17,7 @@ def stop():
   p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
   p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
   out, err = p.communicate()
   out, err = p.communicate()
   for line in out.splitlines():
   for line in out.splitlines():
-    if 'play' in line and 'java' in line:
+    if './start' in line or ('play' in line and 'java' in line):   
       pid = int(line.split(None, 2)[1])
       pid = int(line.split(None, 2)[1])
       os.kill(pid, 9)
       os.kill(pid, 9)
   try:
   try:
@@ -25,4 +25,4 @@ def stop():
   except OSError:
   except OSError:
     pass
     pass
     
     
-  return 0
+  return 0

+ 7 - 0
play-scala/.gitignore

@@ -0,0 +1,7 @@
+logs
+project/project
+project/target
+target
+tmp
+.history
+dist

+ 28 - 0
play-scala/README.md

@@ -0,0 +1,28 @@
+#Play Benchmarking Test
+
+This is the Play portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### JSON Encoding Test
+
+* [JSON test source](app/controllers/Application.java)
+
+### Data-Store/Database Mapping Test
+
+* [Database test controller](app/controllers/Application.scala)
+* [Database test model](app/models/World.java)
+
+## Infrastructure Software Versions
+The tests were run with:
+
+* [Java OpenJDK 1.7.0_09](http://openjdk.java.net/)
+* [Resin 4.0.34](http://www.caucho.com/)
+* [Play 2.1.0](http://http://www.playframework.com/)
+
+## Test URLs
+### JSON Encoding Test
+
+http://localhost/json
+
+### Data-Store/Database Mapping Test
+
+http://localhost/db?queries=5

+ 0 - 0
play-scala/__init__.py


+ 40 - 0
play-scala/app/controllers/Application.scala

@@ -0,0 +1,40 @@
+package controllers
+
+import play._
+import play.api.libs.concurrent._
+import play.api.mvc._
+import play.libs.Json
+import org.codehaus.jackson.node.ObjectNode
+import views.html._
+import models._
+import java.util._
+import java.util.concurrent.ThreadLocalRandom
+import scala.concurrent._
+
+object Application extends Controller {
+  private val TEST_DATABASE_ROWS = 10000
+
+  def json() = Action {
+    val result = Json.newObject()
+    result.put("message", "Hello World!")
+    Ok(result.toString)
+  }
+
+  def db(queries: Int) = Action {
+    import play.api.libs.concurrent.Execution.Implicits._
+
+    val random = ThreadLocalRandom.current()
+
+    Async {
+      Future {
+        (1 to queries) map {
+          _ =>
+            World.find.byId(random.nextInt(TEST_DATABASE_ROWS) + 1)
+        }
+      } map {
+        worlds =>
+          Ok(Json.toJson(worlds).toString())
+      }
+    }
+  }
+}

+ 24 - 0
play-scala/app/models/World.java

@@ -0,0 +1,24 @@
+package models;
+
+import java.util.*;
+import javax.persistence.*;
+
+import play.db.ebean.*;
+import play.db.ebean.Model.Finder;
+import play.data.format.*;
+import play.data.validation.*;
+
+@Entity
+public class World extends Model {
+
+  @Id
+  public Long id;
+
+  @Column(name = "randomNumber")
+  public Long randomNumber;
+
+  public static Finder<Long,World> find = new Finder<Long,World>(
+    Long.class, World.class
+  );
+
+}

+ 13 - 0
play-scala/benchmark_config

@@ -0,0 +1,13 @@
+{
+  "framework": "play-scala",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "port": 9000,
+      "sort": 32
+    }
+  }]
+}

+ 74 - 0
play-scala/conf/application.conf

@@ -0,0 +1,74 @@
+# This is the main configuration file for the application.
+# ~~~~~
+
+# Secret key
+# ~~~~~
+# The secret key is used to secure cryptographics functions.
+# If you deploy your application to several instances be sure to use the same key!
+application.secret="RItx1I:80?W@]8GAtPDuF8Ydd3mXM85p/<7og]Q;uBOdijQAauRDgu73B6`wQP59"
+
+# The application languages
+# ~~~~~
+application.langs="en"
+
+# Global object class
+# ~~~~~
+# Define the Global object class for this application.
+# Default to Global in the root package.
+# global=Global
+
+# Database configuration
+# ~~~~~ 
+# You can declare as many datasources as you want.
+# By convention, the default datasource is named `default`
+#
+# db.default.driver=org.h2.Driver
+# db.default.url="jdbc:h2:mem:play"
+# db.default.user=sa
+# db.default.password=
+#
+# You can expose this datasource via JNDI if needed (Useful for JPA)
+# db.default.jndiName=DefaultDS
+db.default.driver= com.mysql.jdbc.Driver
+db.default.url="jdbc:mysql://localhost:3306/hello_world"
+db.default.user=benchmarkdbuser
+db.default.password=benchmarkdbpass
+db.default.jndiName=DefaultDS
+
+db.default.partitionCount=2
+
+# The number of connections to create per partition. Setting this to 
+# 5 with 3 partitions means you will have 15 unique connections to the 
+# database. Note that BoneCP will not create all these connections in 
+# one go but rather start off with minConnectionsPerPartition and 
+# gradually increase connections as required.
+db.default.maxConnectionsPerPartition=5
+
+# The number of initial connections, per partition.
+db.default.minConnectionsPerPartition=5
+
+# Evolutions
+# ~~~~~
+# You can disable evolutions if needed
+# evolutionplugin=disabled
+
+# Ebean configuration
+# ~~~~~
+# You can declare as many Ebean servers as you want.
+# By convention, the default server is named `default`
+#
+ebean.default="models.*"
+
+# Logger
+# ~~~~~
+# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory .
+
+# Root logger:
+logger.root=ERROR
+
+# Logger used by the framework:
+logger.play=ERROR
+
+# Logger provided to your application:
+logger.application=ERROR
+

+ 10 - 0
play-scala/conf/routes

@@ -0,0 +1,10 @@
+# Routes
+# This file defines all application routes (Higher priority routes first)
+# ~~~~
+
+# Home page
+GET     /json                           controllers.Application.json
+GET     /db                             controllers.Application.db(queries: Int ?= 1)
+
+# Map static resources from the /public folder to the /assets URL path
+GET     /assets/*file               controllers.Assets.at(path="/public", file)

+ 23 - 0
play-scala/project/Build.scala

@@ -0,0 +1,23 @@
+import sbt._
+import Keys._
+import PlayProject._
+
+object ApplicationBuild extends Build {
+
+    val appName         = "play-scala"
+    val appVersion      = "1.0-SNAPSHOT"
+
+    val appDependencies = Seq(
+      // Add your project dependencies here,
+      javaCore,
+      javaJdbc,
+      javaEbean,
+      "mysql" % "mysql-connector-java" % "5.1.22"
+
+    )
+
+    val main = play.Project(appName, appVersion, appDependencies).settings(
+      // Add your own project settings here
+    )
+
+}

+ 1 - 0
play-scala/project/build.properties

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

+ 8 - 0
play-scala/project/plugins.sbt

@@ -0,0 +1,8 @@
+// Comment to get more information during initialization
+logLevel := Level.Warn
+
+// The Typesafe repository 
+resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
+
+// Use the Play sbt plugin for Play projects
+addSbtPlugin("play" % "sbt-plugin" % "2.1.0")

+ 28 - 0
play-scala/setup.py

@@ -0,0 +1,28 @@
+
+import subprocess
+import sys
+import setup_util
+import os
+
+def start(args):
+  setup_util.replace_text("play-scala/conf/application.conf", "jdbc:mysql:\/\/.*:3306", "jdbc:mysql://" + args.database_host + ":3306")
+
+  subprocess.check_call("play dist", shell=True, cwd="play-scala")
+  subprocess.check_call("unzip play-scala-1.0-SNAPSHOT.zip", shell=True, cwd="play-scala/dist")
+  subprocess.check_call("chmod +x start", shell=True, cwd="play-scala/dist/play-scala-1.0-SNAPSHOT")
+  subprocess.Popen("./start", shell=True, cwd="play-scala/dist/play-scala-1.0-SNAPSHOT")
+
+  return 0
+def stop():
+  p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
+  out, err = p.communicate()
+  for line in out.splitlines():
+    if './start' in line or ('play' in line and 'java' in line):
+      pid = int(line.split(None, 2)[1])
+      os.kill(pid, 9)
+  try:
+    os.remove("play-scala/RUNNING_PID")
+  except OSError:
+    pass
+
+  return 0