Browse Source

merge go-std-mongodb into go-std

INADA Naoki 9 years ago
parent
commit
1c2ca3796a

+ 0 - 3
frameworks/Go/go-std-mongodb/README.md

@@ -1,3 +0,0 @@
-# Go MongoDB Benchmarking Test
-
-This is the Go portion of a [benchmarking test suite](../), which uses MongoDB as its database.

+ 0 - 28
frameworks/Go/go-std-mongodb/benchmark_config.json

@@ -1,28 +0,0 @@
-{
-  "framework": "go-mongodb",
-  "tests": [{
-    "default": {
-      "setup_file": "setup",
-      "json_url": "/json",
-      "db_url": "/db",
-      "query_url": "/queries?queries=",
-      "fortune_url": "/fortune",
-      "update_url": "/update?queries=",
-      "plaintext_url": "/plaintext",
-      "port": 8080,
-      "approach": "Realistic",
-      "classification": "Platform",
-      "database": "MongoDB",
-      "framework": "go",
-      "language": "Go",
-      "orm": "Raw",
-      "platform": "Go",
-      "webserver": "None",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "go-std-mongodb",
-      "notes": "mongodb implementation for go net/http",
-      "versus": "go"
-    }
-  }]
-}

+ 0 - 2
frameworks/Go/go-std-mongodb/setup.bat

@@ -1,2 +0,0 @@
-set GOPATH=C:\FrameworkBenchmarks\go
-go run src\hello\hello.go

+ 0 - 6
frameworks/Go/go-std-mongodb/source_code

@@ -1,6 +0,0 @@
-./go/src/
-./go/src/hello
-./go/src/hello/hello.go
-./go/templates/
-./go/templates/fortune.html
-./go/templates/layout.html

+ 0 - 14
frameworks/Go/go-std-mongodb/templates/fortune.html

@@ -1,14 +0,0 @@
-{{define "content"}}
-<table>
-<tr>
-<th>id</th>
-<th>message</th>
-</tr>
-{{range .}}
-<tr>
-<td>{{.Id}}</td>
-<td>{{.Message}}</td>
-</tr>
-{{end}}
-</table>
-{{end}}

+ 0 - 9
frameworks/Go/go-std-mongodb/templates/layout.html

@@ -1,9 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<title>Fortunes</title>
-</head>
-<body>
-{{template "content" .}}
-</body>
-</html>

+ 21 - 0
frameworks/Go/go-std/benchmark_config.json

@@ -67,6 +67,27 @@
       "display_name": "go-mysql-prefork",
       "notes": "",
       "versus": "go"
+    },
+    "mongo": {
+      "setup_file": "setup_mongo",
+      "db_url": "/db",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortune",
+      "update_url": "/update?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "MongoDB",
+      "framework": "go",
+      "language": "Go",
+      "orm": "Raw",
+      "platform": "Go",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "go-mongodb",
+      "notes": "mongodb implementation for go net/http",
+      "versus": "go"
     }
   }]
 }

+ 24 - 21
frameworks/Go/go-std-mongodb/src/hello/hello.go → frameworks/Go/go-std/hello_mongo.go

@@ -2,25 +2,44 @@ package main
 
 import (
 	"encoding/json"
-	"gopkg.in/mgo.v2"
-	"gopkg.in/mgo.v2/bson"
 	"html/template"
 	"log"
 	"math/rand"
 	"net/http"
 	"sort"
 	"strconv"
+
+	"gopkg.in/mgo.v2"
+	"gopkg.in/mgo.v2/bson"
 )
 
 const (
 	connectionString = "localhost"
-	helloWorldString = "Hello, world!"
 	worldRowCount    = 10000
+	fortuneHTML      = `<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr>
+<th>id</th>
+<th>message</th>
+</tr>
+{{range .}}
+<tr>
+<td>{{.Id}}</td>
+<td>{{.Message}}</td>
+</tr>
+{{end}}
+</table>
+</body>
+</html>`
 )
 
 var (
-	tmpl            = template.Must(template.ParseFiles("templates/layout.html", "templates/fortune.html"))
-	helloWorldBytes = []byte(helloWorldString)
+	tmpl = template.Must(template.New("fortune.html").Parse(fortuneHTML))
 
 	database *mgo.Database
 	fortunes *mgo.Collection
@@ -66,22 +85,13 @@ func main() {
 	database = session.DB("hello_world")
 	worlds = database.C("world")
 	fortunes = database.C("fortune")
-	http.HandleFunc("/json", jsonHandler)
 	http.HandleFunc("/db", dbHandler)
 	http.HandleFunc("/fortune", fortuneHandler)
 	http.HandleFunc("/queries", queriesHandler)
 	http.HandleFunc("/update", updateHandler)
-	http.HandleFunc("/plaintext", plaintextHandler)
 	http.ListenAndServe(":8080", nil)
 }
 
-// Test 1: JSON serialization
-func jsonHandler(w http.ResponseWriter, r *http.Request) {
-	w.Header().Set("Content-Type", "application/json")
-	w.Header().Set("Server", "go-mongodb")
-	json.NewEncoder(w).Encode(&Message{helloWorldString})
-}
-
 // Helper for random numbers
 func getRandomNumber() uint16 {
 	return uint16(rand.Intn(worldRowCount) + 1)
@@ -169,10 +179,3 @@ func updateHandler(w http.ResponseWriter, r *http.Request) {
 	w.Header().Set("Server", "Go")
 	json.NewEncoder(w).Encode(&world)
 }
-
-// Test 6: Plaintext
-func plaintextHandler(w http.ResponseWriter, r *http.Request) {
-	w.Header().Set("Content-Type", "text/plain")
-	w.Header().Set("Server", "go-mongodb")
-	w.Write(helloWorldBytes)
-}

+ 2 - 3
frameworks/Go/go-std-mongodb/setup.sh → frameworks/Go/go-std/setup_mongo.sh

@@ -1,10 +1,9 @@
 #!/bin/bash
 
-sed -i 's|connectionString = "localhost"|connectionString = "'"${DBHOST}"'"|g' src/hello/hello.go
+sed -i 's|connectionString = "localhost"|connectionString = "'"${DBHOST}"'"|g' hello_mongo.go
 
 fw_depends go
 
 go get gopkg.in/mgo.v2
-go get ./...
 
-go run src/hello/hello.go &
+go run hello_mongo.go &

+ 1 - 0
frameworks/Go/go-std/source_code

@@ -1 +1,2 @@
 ./hello_mysql.go
+./hello_mongo.go