2019-08-12 11:01:15 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
2019-08-12 12:34:08 +00:00
|
|
|
|
2021-12-16 09:55:04 +00:00
|
|
|
import "fmt"
|
|
|
|
import "os"
|
2019-08-12 11:01:15 +00:00
|
|
|
import "runtime"
|
|
|
|
import "runtime/debug"
|
2021-12-19 10:35:15 +00:00
|
|
|
import "strconv"
|
2019-08-12 12:34:08 +00:00
|
|
|
import "time"
|
|
|
|
|
2019-08-12 11:01:15 +00:00
|
|
|
import "github.com/valyala/fasthttp"
|
|
|
|
import "github.com/valyala/fasthttp/reuseport"
|
|
|
|
|
|
|
|
|
2019-08-12 12:34:08 +00:00
|
|
|
|
|
|
|
|
2022-09-07 07:14:50 +00:00
|
|
|
func main () {
|
2019-08-12 11:01:15 +00:00
|
|
|
|
2019-08-12 12:34:08 +00:00
|
|
|
|
2021-12-19 10:35:15 +00:00
|
|
|
runtime.GOMAXPROCS (1)
|
2019-08-12 11:01:15 +00:00
|
|
|
|
2019-08-14 13:25:40 +00:00
|
|
|
debug.SetGCPercent (-1)
|
2019-08-12 11:01:15 +00:00
|
|
|
debug.SetMaxThreads (128)
|
|
|
|
debug.SetMaxStack (16 * 1024)
|
|
|
|
|
|
|
|
|
2021-12-16 09:55:04 +00:00
|
|
|
_endpoint := "127.0.0.1:8080"
|
2021-12-19 10:35:15 +00:00
|
|
|
_threads := 1
|
2021-12-16 09:55:04 +00:00
|
|
|
_timeouts := false
|
|
|
|
|
|
|
|
switch len (os.Args) {
|
|
|
|
case 1 :
|
|
|
|
// NOP
|
|
|
|
case 2 :
|
|
|
|
_endpoint = os.Args[1]
|
2021-12-19 10:35:15 +00:00
|
|
|
case 3 :
|
|
|
|
_endpoint = os.Args[1]
|
|
|
|
if _threads_0, _error := strconv.Atoi (os.Args[2]); (_error == nil) && (_threads > 0) {
|
|
|
|
_threads = _threads_0
|
|
|
|
} else {
|
|
|
|
panic ("[40396d14] invalid arguments!")
|
|
|
|
}
|
2021-12-16 09:55:04 +00:00
|
|
|
default :
|
|
|
|
panic ("[60023f00] invalid arguments!")
|
|
|
|
}
|
|
|
|
|
2021-12-19 10:35:15 +00:00
|
|
|
if _threads > 1 {
|
|
|
|
runtime.GOMAXPROCS (_threads)
|
|
|
|
debug.SetMaxThreads (int (128 * (_threads / 64 + 1)))
|
|
|
|
}
|
|
|
|
|
2021-12-16 09:55:04 +00:00
|
|
|
_listener, _error := reuseport.Listen ("tcp4", _endpoint)
|
|
|
|
if _error != nil {
|
|
|
|
panic (fmt.Sprintf ("[8c30a625] failed to listen: %s", _error))
|
|
|
|
}
|
|
|
|
|
2021-12-19 10:35:15 +00:00
|
|
|
fmt.Fprintf (os.Stderr, "[ii] [04fa2421] listening on `http://%s/` (using %d threads)...\n", _endpoint, _threads)
|
2019-08-12 11:01:15 +00:00
|
|
|
|
2019-08-12 12:34:08 +00:00
|
|
|
_server := & fasthttp.Server {
|
|
|
|
|
|
|
|
Name : "kawipiko",
|
|
|
|
Handler : serve,
|
|
|
|
GetOnly : true,
|
|
|
|
|
|
|
|
NoDefaultServerHeader : true,
|
|
|
|
NoDefaultContentType : true,
|
2019-08-12 17:43:30 +00:00
|
|
|
NoDefaultDate : true,
|
2019-08-12 12:34:08 +00:00
|
|
|
DisableHeaderNamesNormalizing : true,
|
|
|
|
|
2019-08-13 07:41:48 +00:00
|
|
|
Concurrency : 16 * 1024 + 128,
|
2019-08-12 12:34:08 +00:00
|
|
|
MaxRequestsPerConn : 256 * 1024,
|
|
|
|
|
|
|
|
ReadBufferSize : 16 * 1024,
|
|
|
|
WriteBufferSize : 16 * 1024,
|
|
|
|
MaxRequestBodySize : 16 * 1024,
|
|
|
|
|
2021-12-16 09:55:04 +00:00
|
|
|
ReadTimeout : 30 * time.Second,
|
|
|
|
WriteTimeout : 30 * time.Second,
|
|
|
|
IdleTimeout : 360 * time.Second,
|
2019-08-12 12:34:08 +00:00
|
|
|
|
|
|
|
TCPKeepalive : true,
|
|
|
|
TCPKeepalivePeriod : 60 * time.Second,
|
|
|
|
|
|
|
|
ReduceMemoryUsage : false,
|
2021-12-16 09:55:04 +00:00
|
|
|
|
|
|
|
CloseOnShutdown : true,
|
|
|
|
DisableKeepalive : false,
|
2019-08-12 12:34:08 +00:00
|
|
|
|
|
|
|
ErrorHandler : nil,
|
|
|
|
ConnState : nil,
|
|
|
|
HeaderReceived : nil,
|
|
|
|
|
|
|
|
Logger : nil,
|
|
|
|
LogAllErrors : true,
|
|
|
|
|
|
|
|
}
|
2019-08-12 11:01:15 +00:00
|
|
|
|
2021-12-16 09:55:04 +00:00
|
|
|
if !_timeouts {
|
|
|
|
_server.ReadTimeout = 0
|
|
|
|
_server.WriteTimeout = 0
|
|
|
|
_server.IdleTimeout = 0
|
|
|
|
}
|
|
|
|
|
2019-08-12 12:34:08 +00:00
|
|
|
_error = _server.Serve (_listener)
|
2021-12-16 09:55:04 +00:00
|
|
|
if _error != nil {
|
|
|
|
panic (fmt.Sprintf ("[ee9bc0a5] failed to serve: %s", _error))
|
|
|
|
}
|
2019-08-12 11:01:15 +00:00
|
|
|
}
|
|
|
|
|
2019-08-12 12:34:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func serve (_context *fasthttp.RequestCtx) () {
|
|
|
|
_context.Response.SetBodyRaw (serveData)
|
|
|
|
}
|
|
|
|
|
|
|
|
var serveData = []byte ("hello world!\n")
|
|
|
|
|