-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (47 loc) · 1.19 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"log"
"net"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
"github.com/jackc/pgproto3/v2"
"github.com/coder543/roundabout/backend"
"github.com/coder543/roundabout/config"
"github.com/coder543/roundabout/frontend"
)
func main() {
// Performance testing has shown almost a +70% performance boost
// for roundabout just by limiting GOMAXPROCS to 1.
//
// It is possible that it will perform better with more procs in
// certain environments, so we simply change the default here,
// but still respect any override placed in the environment.
if os.Getenv("GOMAXPROCS") == "" {
runtime.GOMAXPROCS(1)
}
log.SetFlags(log.LstdFlags | log.Lshortfile)
frontend.LaunchAll()
// launch debug pprof server
if config.PprofAddr != "" {
go func() {
err := http.ListenAndServe(config.PprofAddr, nil)
if err != nil {
log.Panicln("could not start debug server:", err)
}
}()
}
ln, err := net.Listen("tcp", config.Virtual.Listen)
if err != nil {
log.Panicln(err)
}
for {
conn, err := ln.Accept()
if err != nil {
log.Panicln(err)
}
protoBackend := pgproto3.NewBackend(pgproto3.NewChunkReader(conn), conn)
go backend.Launch(conn, protoBackend)
}
}