Browse Source

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

Patrick Falls 12 years ago
parent
commit
011bdc6046

+ 34 - 0
http-kit/README.md

@@ -0,0 +1,34 @@
+# Compojure Benchmarking Test
+
+This is the Compojure (using http-kit) portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### JSON Encoding Test
+
+* [JSON test source](hello/src/hello/handler.clj)
+
+### Data-Store/Database Mapping Test
+
+* [Database test source](hello/src/hello/handler.clj)
+
+## Infrastructure Software Versions
+The dependencies are documented in [project.clj](hello/project.clj),
+but the main ones are:
+
+* [Clojure 1.4.0](http://clojure.org/)
+* [Compojure 1.1.5](https://github.com/weavejester/compojure)
+* [Ring-JSON 0.1.2](https://github.com/ring-clojure/ring-json), which in turn uses [Cheshire](https://github.com/dakrone/cheshire), which in turn uses [Jackson](http://jackson.codehaus.org/)
+* [http-kit](http://http-kit.org)
+* [dbcp.clj](https://github.com/http-kit/dbcp.clj)
+
+## Test URLs
+### JSON Encoding Test
+
+http://localhost/http-kit/json
+
+### Data-Store/Database Mapping Test
+
+http://localhost/http-kit/db
+
+### Variable Query Test
+
+http://localhost/http-kit/db/2

+ 0 - 0
http-kit/__init__.py


+ 13 - 0
http-kit/benchmark_config

@@ -0,0 +1,13 @@
+{
+  "framework": "http-kit",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/http-kit/json",
+      "db_url": "/http-kit/db/1",
+      "query_url": "/http-kit/db/",
+      "port": 8080,
+      "sort": 36
+    }
+  }]
+}

+ 11 - 0
http-kit/hello/.gitignore

@@ -0,0 +1,11 @@
+/target
+/lib
+/classes
+/checkouts
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
+.lein-env

+ 19 - 0
http-kit/hello/README.md

@@ -0,0 +1,19 @@
+# hello
+
+FIXME
+
+## Prerequisites
+
+You will need [Leiningen][1] 1.7.0 or above installed.
+
+[1]: https://github.com/technomancy/leiningen
+
+## Running
+
+To start a web server for the application, run:
+
+    lein ring server
+
+## License
+
+Copyright © 2013 FIXME

+ 13 - 0
http-kit/hello/project.clj

@@ -0,0 +1,13 @@
+(defproject hello "compojure"
+  :description "JSON/Database tests"
+  :url "http://example.com/FIXME"
+  :dependencies [[org.clojure/clojure "1.5.1"]
+                 [compojure "1.1.5"]
+                 [ring/ring-json "0.2.0"]
+                 [org.clojure/tools.cli "0.2.1"]
+                 [http-kit/dbcp "0.1.0"]
+                 [http-kit "2.0.0-RC4"]
+                 [log4j "1.2.15" :exclusions [javax.mail/mail javax.jms/jms com.sun.jdmk/jmxtools com.sun.jmx/jmxri]]
+                 [mysql/mysql-connector-java "5.1.6"]]
+  :main hello.handler
+  :profiles {:dev {:dependencies [[ring-mock "0.1.3"]]}})

+ 58 - 0
http-kit/hello/src/hello/handler.clj

@@ -0,0 +1,58 @@
+(ns hello.handler
+  (:gen-class)
+  (:use compojure.core
+        ring.middleware.json
+        org.httpkit.server
+        [clojure.tools.cli :only [cli]]
+        ring.util.response)
+  (:require [compojure.handler :as handler]
+            [org.httpkit.dbcp :as db]
+            [compojure.route :as route]))
+
+;;; convert to int
+(defn to-int [s] (cond
+                  (string? s) (Integer/parseInt s)
+                  (instance? Integer s) s
+                  (instance? Long s) (.intValue ^Long s)
+                  :else 0))
+
+;; Query a random World record from the database
+(defn get-world []
+  (let [id (inc (rand-int 9999))] ; Num between 1 and 10,000
+    (db/query "select id randomNumber from world where id = ?" id)))
+
+;; Run the specified number of queries, return the results
+(defn run-queries [queries]
+  (vec ; Return as a vector
+   (flatten ; Make it a list of maps
+    (take
+     queries ; Number of queries to run
+     (repeatedly get-world)))))
+
+;; Define route handlers
+(defroutes app-routes
+  (GET "/http-kit/" [] "Hello, World!")
+  (GET "/http-kit/json" [] (response {:message "Hello, World!"}))
+  (GET "/http-kit/db/:queries" [queries]
+       (response (run-queries (Integer/parseInt queries))))
+  (route/not-found "Not Found"))
+
+
+(defn start-server [{:keys [port worker db-host]}]
+  (db/use-database! (str "jdbc:mysql://" db-host "/hello_world")
+                    "benchmarkdbuser"
+                    "benchmarkdbpass")
+  ;; Format responses as JSON
+  (let [handler (wrap-json-response app-routes)]
+    (run-server handler {:port port :worker worker})))
+
+
+(defn -main [& args]
+  (let [[options _ banner]
+        (cli args
+             ["-p" "--port" "Port to listen" :default 8080 :parse-fn to-int]
+             ["--worker" "Http worker thread count" :default 6 :parse-fn to-int]
+             ["--db-host" "MySQL database host" :default "localhost"]
+             ["--[no-]help" "Print this help"])]
+    (when (:help options) (println banner) (System/exit 0))
+    (start-server options)))

+ 7 - 0
http-kit/hello/src/log4j.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+  <logger name="com.mchange">
+    <level value="WARN"/>
+  </logger>
+</log4j:configuration>

+ 23 - 0
http-kit/setup.py

@@ -0,0 +1,23 @@
+
+import subprocess
+import sys
+import setup_util
+
+def start(args):
+
+  try:
+    subprocess.check_call("lein deps", shell=True, cwd="http-kit/hello")
+    # lein run -- --help for more options
+    command = "lein run -- --db-host " + args.database_host
+    subprocess.Popen(command, shell=True, cwd="http-kit/hello")
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+
+def stop():
+  try:
+    # listen on 8080
+    subprocess.check_call("lsof -t -sTCP:LISTEN -i:8080 | xargs kill", shell=True)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1