Browse Source

🐱‍🚀 Fiber 1.12.6 (#5859)

* Update Fiber v1.10.0

* Fiber: Bump v1.12.0

* Update constant

* Fiber optimization

* v1.12.1

* Update dependencies

* Update cached worlds test

* Update cached test

* Update cached test

* Update cache test

* Fix cache test

* Update cache test

* Update cache test

* Fix panic

* 🧹 Fix test-requirements

* 👩‍🚀 Optimize response

* 🐛 Fix typo

* 📦 Update test

* 📦 Bump v1.12.6

* 🐛 Fix test

* 🐛 Fix test

* 🧹

Co-authored-by: Fenny <Fenny>
fenny 5 years ago
parent
commit
68b7b54ce9

+ 24 - 0
frameworks/Go/fiber/benchmark_config.json

@@ -49,6 +49,30 @@
         "display_name": "Fiber",
         "notes": "",
         "versus": "go"
+      },
+      "nogc": {
+        "json_url": "/json",
+        "db_url": "/db",
+        "query_url": "/queries?q=",
+        "fortune_url": "/fortunes",
+        "cached_query_url": "/cached-worlds?q=",
+        "update_url": "/update?q=",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Platform",
+        "database": "Postgres",
+        "framework": "fiber",
+        "language": "Go",
+        "flavor": "None",
+        "orm": "Raw",
+        "platform": "None",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Fiber",
+        "notes": "",
+        "versus": "go"
       }
     }
   ]

+ 12 - 0
frameworks/Go/fiber/fiber-nogc.dockerfile

@@ -0,0 +1,12 @@
+FROM golang:1.14
+
+WORKDIR /fiber
+
+COPY ./src /fiber
+
+RUN go get github.com/valyala/quicktemplate/qtc
+
+RUN go generate ./templates
+RUN go build -ldflags="-s -w" -o app .
+
+CMD ./app -prefork -nogc

+ 2 - 1
frameworks/Go/fiber/src/go.mod

@@ -3,7 +3,8 @@ module fiber/src
 go 1.14
 
 require (
-	github.com/gofiber/fiber v1.12.5
+	github.com/gofiber/fiber v1.12.6
+	github.com/gofiber/utils v0.0.9
 	github.com/jackc/pgx/v4 v4.7.1
 	github.com/valyala/quicktemplate v1.5.0
 )

+ 2 - 2
frameworks/Go/fiber/src/go.sum

@@ -10,8 +10,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
-github.com/gofiber/fiber v1.12.5 h1:xEeONOLf3nzWkartpTw9TzCpF+QXZjVPVpJWpx5bCP0=
-github.com/gofiber/fiber v1.12.5/go.mod h1:e+Ur2pP2rb5xKtiHATgfQpSwBR0z9q8Mar9+XfYxpOY=
+github.com/gofiber/fiber v1.12.6 h1:Ca/vuticUkHLz9BDZZ8ZNGXMtdY/VOHqw/jYZ427xis=
+github.com/gofiber/fiber v1.12.6/go.mod h1:e+Ur2pP2rb5xKtiHATgfQpSwBR0z9q8Mar9+XfYxpOY=
 github.com/gofiber/utils v0.0.9 h1:Bu4grjEB4zof1TtpmPCG6MeX5nGv8SaQfzaUgjkf3H8=
 github.com/gofiber/utils v0.0.9/go.mod h1:9J5aHFUIjq0XfknT4+hdSMG6/jzfaAgCu4HEbWDeBlo=
 github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=

+ 18 - 14
frameworks/Go/fiber/src/server.go

@@ -4,8 +4,8 @@ import (
 	"context"
 	"fmt"
 	"math/rand"
-	"os"
 	"runtime"
+	"runtime/debug"
 	"sort"
 	"strconv"
 	"sync"
@@ -13,6 +13,7 @@ import (
 	"fiber/src/templates"
 
 	"github.com/gofiber/fiber"
+	"github.com/gofiber/utils"
 	pgx "github.com/jackc/pgx/v4"
 	"github.com/jackc/pgx/v4/pgxpool"
 )
@@ -25,8 +26,8 @@ var (
 
 const (
 	queryparam       = "q"
-	worldcount       = 10000
 	helloworld       = "Hello, World!"
+	worldcount       = 10000
 	worldselectsql   = "SELECT id, randomNumber FROM World WHERE id = $1"
 	worldupdatesql   = "UPDATE World SET randomNumber = $1 WHERE id = $2"
 	worldcachesql    = "SELECT * FROM World LIMIT $1"
@@ -34,12 +35,6 @@ const (
 )
 
 func main() {
-	for _, arg := range os.Args[1:] {
-		if arg == "-child" {
-			child = true
-		}
-	}
-
 	initDatabase()
 
 	app := fiber.New(&fiber.Settings{
@@ -49,6 +44,13 @@ func main() {
 		ServerHeader:             "go",
 	})
 
+	if utils.GetArgument("-prefork-child") {
+		child = true
+	}
+	if utils.GetArgument("-nogc") {
+		debug.SetGCPercent(-1)
+	}
+
 	app.Get("/plaintext", plaintextHandler)
 	app.Get("/json", jsonHandler)
 	app.Get("/db", dbHandler)
@@ -172,7 +174,7 @@ func populateCache() {
 func jsonHandler(c *fiber.Ctx) {
 	m := AcquireJSON()
 	m.Message = helloworld
-	c.JSON(m)
+	c.JSON(&m)
 	ReleaseJSON(m)
 }
 
@@ -180,7 +182,7 @@ func jsonHandler(c *fiber.Ctx) {
 func dbHandler(c *fiber.Ctx) {
 	w := AcquireWorld()
 	db.QueryRow(context.Background(), worldselectsql, RandomWorld()).Scan(&w.ID, &w.RandomNumber)
-	c.JSON(w)
+	c.JSON(&w)
 	ReleaseWorld(w)
 }
 
@@ -216,7 +218,7 @@ func queriesHandler(c *fiber.Ctx) {
 		w := &worlds[i]
 		db.QueryRow(context.Background(), worldselectsql, RandomWorld()).Scan(&w.ID, &w.RandomNumber)
 	}
-	c.JSON(worlds)
+	c.JSON(&worlds)
 	ReleaseWorlds(worlds)
 }
 
@@ -239,13 +241,15 @@ func updateHandler(c *fiber.Ctx) {
 		batch.Queue(worldupdatesql, w.RandomNumber, w.ID)
 	}
 	db.SendBatch(context.Background(), &batch).Close()
-	c.JSON(worlds)
+	c.JSON(&worlds)
 	ReleaseWorlds(worlds)
 }
 
+var helloworldRaw = []byte("Hello, World!")
+
 // plaintextHandler :
 func plaintextHandler(c *fiber.Ctx) {
-	c.SendString(helloworld)
+	c.SendBytes(helloworldRaw)
 }
 
 // cachedHandler :
@@ -255,7 +259,7 @@ func cachedHandler(c *fiber.Ctx) {
 	for i := 0; i < n; i++ {
 		worlds[i] = cachedWorlds[RandomWorld()-1]
 	}
-	c.JSON(worlds)
+	c.JSON(&worlds)
 	ReleaseWorlds(worlds)
 }