package prefork
import "github.com/valyala/fasthttp/prefork"
Package prefork provides a way to prefork a fasthttp server.
Index ¶
Variables ¶
var ( // ErrOverRecovery is returned when the times of starting over child prefork processes exceed // the threshold. ErrOverRecovery = errors.New("exceeding the value of RecoverThreshold") // ErrOnlyReuseportOnWindows is returned when Reuseport is false. ErrOnlyReuseportOnWindows = errors.New("windows only supports Reuseport = true") )
Functions ¶
func IsChild ¶
func IsChild() bool
IsChild checks if the current thread/process is a child.
Types ¶
type Logger ¶
type Logger interface { // Printf must have the same semantics as log.Printf. Printf(format string, args ...any) }
Logger is used for logging formatted messages.
type Prefork ¶
type Prefork struct { // By default standard logger from log package is used. Logger Logger ServeFunc func(ln net.Listener) error ServeTLSFunc func(ln net.Listener, certFile, keyFile string) error ServeTLSEmbedFunc func(ln net.Listener, certData, keyData []byte) error // The network must be "tcp", "tcp4" or "tcp6". // // By default is "tcp4" Network string // Child prefork processes may exit with failure and will be started over until the times reach // the value of RecoverThreshold, then it will return and terminate the server. RecoverThreshold int // Flag to use a listener with reuseport, if not a file Listener will be used // See: https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/ // // It's disabled by default Reuseport bool // contains filtered or unexported fields }
Prefork implements fasthttp server prefork.
Preforks master process (with all cores) between several child processes increases performance significantly, because Go doesn't have to share and manage memory between cores.
WARNING: using prefork prevents the use of any global state! Things like in-memory caches won't work.
func New ¶
New wraps the fasthttp server to run with preforked processes.
func (*Prefork) ListenAndServe ¶
ListenAndServe serves HTTP requests from the given TCP addr.
func (*Prefork) ListenAndServeTLS ¶
ListenAndServeTLS serves HTTPS requests from the given TCP addr.
certFile and keyFile are paths to TLS certificate and key files.
func (*Prefork) ListenAndServeTLSEmbed ¶
ListenAndServeTLSEmbed serves HTTPS requests from the given TCP addr.
certData and keyData must contain valid TLS certificate and key data.
Source Files ¶
- Version
- v1.62.0 (latest)
- Published
- May 7, 2025
- Platform
- windows/amd64
- Imports
- 8 packages
- Last checked
- 3 weeks ago –
Tools for package owners.