Переглянути джерело

fasthttp: remove prefork mode (#2380)

knewmanTE 8 роки тому
батько
коміт
13f41cdcbb

+ 3 - 23
frameworks/Go/fasthttp/benchmark_config.json

@@ -25,31 +25,11 @@
       "notes": "",
       "versus": "go"
     },
-    "mysql-prefork": {
-      "setup_file": "setup-mysql-prefork",
-      "db_url": "/db",
-      "query_url": "/queries?queries=",
-      "update_url": "/update?queries=",
-      "port": 8080,
-      "approach": "Realistic",
-      "classification": "Platform",
-      "database": "MySQL",
-      "framework": "None",
-      "language": "Go",
-      "flavor": "None",
-      "orm": "Raw",
-      "platform": "None",
-      "webserver": "None",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "FastHTTP",
-      "notes": "",
-      "versus": "go"
-    },
-    "postgresql-prefork": {
-      "setup_file": "setup-postgresql-prefork",
+    "postgresql": {
+      "setup_file": "setup-postgresql",
       "db_url": "/db",
       "query_url": "/queries?queries=",
+      "fortune_url": "/fortune",
       "update_url": "/update?queries=",
       "port": 8080,
       "approach": "Realistic",

+ 0 - 14
frameworks/Go/fasthttp/setup-mysql-prefork.sh

@@ -1,14 +0,0 @@
-#!/bin/bash
-
-sed -i 's|tcp(.*:3306)|tcp('"${DBHOST}"':3306)|g' src/server-mysql/server.go
-
-fw_depends go
-
-GOPATH=`pwd` go get -u github.com/go-sql-driver/mysql
-GOPATH=`pwd` go get -u github.com/valyala/fasthttp/...
-GOPATH=`pwd` go get -u github.com/valyala/quicktemplate/qtc
-
-rm -f ./server-mysql
-GOPATH=`pwd` go generate templates
-GOPATH=`pwd` go build server-mysql
-./server-mysql -prefork &

+ 0 - 14
frameworks/Go/fasthttp/setup-postgresql-prefork.sh

@@ -1,14 +0,0 @@
-#!/bin/bash
-
-sed -i 's|localhost|'"${DBHOST}"'|g' src/server-postgresql/server.go
-
-fw_depends go
-
-GOPATH=`pwd` go get -u github.com/jackc/pgx
-GOPATH=`pwd` go get -u github.com/valyala/fasthttp/...
-GOPATH=`pwd` go get -u github.com/valyala/quicktemplate/qtc
-
-rm -f ./server-postgresql
-GOPATH=`pwd` go generate templates
-GOPATH=`pwd` go build server-postgresql
-./server-postgresql -prefork &

+ 2 - 39
frameworks/Go/fasthttp/src/common/common.go

@@ -6,13 +6,9 @@ import (
 	"log"
 	"math/rand"
 	"net"
-	"os"
-	"os/exec"
-	"runtime"
 	"sync"
 
 	"github.com/valyala/fasthttp"
-	"github.com/valyala/fasthttp/reuseport"
 
 	"templates"
 )
@@ -28,11 +24,7 @@ type World struct {
 	RandomNumber int32 `json:"randomNumber"`
 }
 
-var (
-	listenAddr = flag.String("listenAddr", ":8080", "Address to listen to")
-	Prefork    = flag.Bool("prefork", false, "use prefork")
-	child      = flag.Bool("child", false, "is child proc")
-)
+var listenAddr = flag.String("listenAddr", ":8080", "Address to listen to")
 
 func JSONHandler(ctx *fasthttp.RequestCtx) {
 	r := jsonResponsePool.Get().(*JSONResponse)
@@ -86,36 +78,7 @@ func (w WorldsByID) Swap(i, j int)      { w[i], w[j] = w[j], w[i] }
 func (w WorldsByID) Less(i, j int) bool { return w[i].Id < w[j].Id }
 
 func GetListener() net.Listener {
-	if !*Prefork {
-		runtime.GOMAXPROCS(runtime.NumCPU())
-		ln, err := net.Listen("tcp4", *listenAddr)
-		if err != nil {
-			log.Fatal(err)
-		}
-		return ln
-	}
-
-	if !*child {
-		children := make([]*exec.Cmd, runtime.NumCPU())
-		for i := range children {
-			children[i] = exec.Command(os.Args[0], "-prefork", "-child")
-			children[i].Stdout = os.Stdout
-			children[i].Stderr = os.Stderr
-			if err := children[i].Start(); err != nil {
-				log.Fatal(err)
-			}
-		}
-		for _, ch := range children {
-			if err := ch.Wait(); err != nil {
-				log.Print(err)
-			}
-		}
-		os.Exit(0)
-		panic("unreachable")
-	}
-
-	runtime.GOMAXPROCS(1)
-	ln, err := reuseport.Listen("tcp4", *listenAddr)
+	ln, err := net.Listen("tcp4", *listenAddr)
 	if err != nil {
 		log.Fatal(err)
 	}

+ 2 - 7
frameworks/Go/fasthttp/src/server-mysql/server.go

@@ -4,7 +4,6 @@ import (
 	"database/sql"
 	"flag"
 	"log"
-	"runtime"
 	"sort"
 
 	_ "github.com/go-sql-driver/mysql"
@@ -38,12 +37,8 @@ func main() {
 		log.Fatalf("Cannot connect to db: %s", err)
 	}
 
-	dbConnCount := maxConnectionCount
-	if *common.Prefork {
-		dbConnCount = (dbConnCount + runtime.NumCPU() - 1) / runtime.NumCPU()
-	}
-	db.SetMaxIdleConns(dbConnCount)
-	db.SetMaxOpenConns(dbConnCount)
+	db.SetMaxIdleConns(maxConnectionCount)
+	db.SetMaxOpenConns(maxConnectionCount)
 
 	worldSelectStmt = mustPrepare(db, "SELECT id, randomNumber FROM World WHERE id = ?")
 	worldUpdateStmt = mustPrepare(db, "UPDATE World SET randomNumber = ? WHERE id = ?")

+ 1 - 6
frameworks/Go/fasthttp/src/server-postgresql/server.go

@@ -4,7 +4,6 @@ import (
 	"flag"
 	"fmt"
 	"log"
-	"runtime"
 	"sort"
 
 	"github.com/jackc/pgx"
@@ -29,11 +28,7 @@ func main() {
 
 	var err error
 
-	dbConns := maxConnectionCount
-	if *common.Prefork {
-		dbConns = (maxConnectionCount + runtime.NumCPU() - 1) / runtime.NumCPU()
-	}
-	if db, err = initDatabase("localhost", "benchmarkdbuser", "benchmarkdbpass", "hello_world", 5432, dbConns); err != nil {
+	if db, err = initDatabase("localhost", "benchmarkdbuser", "benchmarkdbpass", "hello_world", 5432, maxConnectionCount); err != nil {
 		log.Fatalf("Error opening database: %s", err)
 	}