|
@@ -2,62 +2,14 @@ package controllers
|
|
|
|
|
|
import (
|
|
import (
|
|
"math/rand"
|
|
"math/rand"
|
|
- "runtime"
|
|
|
|
"sort"
|
|
"sort"
|
|
|
|
|
|
"benchmark/app/db"
|
|
"benchmark/app/db"
|
|
- "github.com/revel/revel"
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
-type MessageStruct struct {
|
|
|
|
- Message string `json:"message"`
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-type World struct {
|
|
|
|
- Id uint16 `json:"id"`
|
|
|
|
- RandomNumber uint16 `json:"randomNumber"`
|
|
|
|
-}
|
|
|
|
|
|
|
|
-type Fortune struct {
|
|
|
|
- Id uint16 `json:"id"`
|
|
|
|
- Message string `json:"message"`
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const (
|
|
|
|
- WorldSelect = `SELECT id, randomNumber FROM World WHERE id = ?`
|
|
|
|
- WorldUpdate = `UPDATE World SET randomNumber = ? WHERE id = ?`
|
|
|
|
- FortuneSelect = `SELECT id, message FROM Fortune`
|
|
|
|
- WorldRowCount = 10000
|
|
|
|
- MaxConnectionCount = 260
|
|
|
|
|
|
+ "github.com/revel/revel"
|
|
)
|
|
)
|
|
|
|
|
|
-func init() {
|
|
|
|
- revel.Filters = []revel.Filter{
|
|
|
|
- revel.RouterFilter,
|
|
|
|
- revel.ParamsFilter,
|
|
|
|
- revel.ActionInvoker,
|
|
|
|
- }
|
|
|
|
- revel.OnAppStart(func() {
|
|
|
|
- runtime.GOMAXPROCS(runtime.NumCPU())
|
|
|
|
- db.Init()
|
|
|
|
- db.Jet.SetMaxIdleConns(MaxConnectionCount)
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-type App struct {
|
|
|
|
- *revel.Controller
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (c App) Json() revel.Result {
|
|
|
|
- c.Response.ContentType = "application/json"
|
|
|
|
- return c.RenderJson(MessageStruct{"Hello, world"})
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (c App) Plaintext() revel.Result {
|
|
|
|
- return c.RenderText("Hello, World!")
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (c App) Db(queries int) revel.Result {
|
|
|
|
|
|
+func (c App) JetDb(queries int) revel.Result {
|
|
if queries <= 1 {
|
|
if queries <= 1 {
|
|
var w World
|
|
var w World
|
|
err := db.Jet.Query(WorldSelect, rand.Intn(WorldRowCount)+1).Rows(&w)
|
|
err := db.Jet.Query(WorldSelect, rand.Intn(WorldRowCount)+1).Rows(&w)
|
|
@@ -77,7 +29,7 @@ func (c App) Db(queries int) revel.Result {
|
|
return c.RenderJson(ww)
|
|
return c.RenderJson(ww)
|
|
}
|
|
}
|
|
|
|
|
|
-func (c App) Update(queries int) revel.Result {
|
|
|
|
|
|
+func (c App) JetUpdate(queries int) revel.Result {
|
|
if queries <= 1 {
|
|
if queries <= 1 {
|
|
var w World
|
|
var w World
|
|
err := db.Jet.Query(WorldSelect, rand.Intn(WorldRowCount)+1).Rows(&w)
|
|
err := db.Jet.Query(WorldSelect, rand.Intn(WorldRowCount)+1).Rows(&w)
|
|
@@ -105,7 +57,7 @@ func (c App) Update(queries int) revel.Result {
|
|
return c.RenderJson(ww)
|
|
return c.RenderJson(ww)
|
|
}
|
|
}
|
|
|
|
|
|
-func (c App) Fortune() revel.Result {
|
|
|
|
|
|
+func (c App) JetFortune() revel.Result {
|
|
var fortunes Fortunes
|
|
var fortunes Fortunes
|
|
err := db.Jet.Query(FortuneSelect).Rows(&fortunes)
|
|
err := db.Jet.Query(FortuneSelect).Rows(&fortunes)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -113,14 +65,6 @@ func (c App) Fortune() revel.Result {
|
|
}
|
|
}
|
|
fortunes = append(fortunes, &Fortune{Message: "Additional fortune added at request time."})
|
|
fortunes = append(fortunes, &Fortune{Message: "Additional fortune added at request time."})
|
|
sort.Sort(ByMessage{fortunes})
|
|
sort.Sort(ByMessage{fortunes})
|
|
- return c.Render(fortunes)
|
|
|
|
|
|
+ c.RenderArgs["fortunes"] = fortunes
|
|
|
|
+ return c.RenderTemplate("App/Fortune.html")
|
|
}
|
|
}
|
|
-
|
|
|
|
-type Fortunes []*Fortune
|
|
|
|
-
|
|
|
|
-func (s Fortunes) Len() int { return len(s) }
|
|
|
|
-func (s Fortunes) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
|
|
|
-
|
|
|
|
-type ByMessage struct{ Fortunes }
|
|
|
|
-
|
|
|
|
-func (s ByMessage) Less(i, j int) bool { return s.Fortunes[i].Message < s.Fortunes[j].Message }
|
|
|