fasthttp: Index | Files

package prefork

import ""


Package Files



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 = errors.New("windows only supports Reuseport = true")

func IsChild Uses

func IsChild() bool

IsChild checks if the current thread/process is a child

type Logger Uses

type Logger interface {
    // Printf must have the same semantics as log.Printf.
    Printf(format string, args ...interface{})

Logger is used for logging formatted messages.

type Prefork Uses

type Prefork struct {
    // The network must be "tcp", "tcp4" or "tcp6".
    // By default is "tcp4"
    Network string

    // Flag to use a listener with reuseport, if not a file Listener will be used
    // See:
    // It's disabled by default
    Reuseport bool

    // 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

    // 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
    // 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 Uses

func New(s *fasthttp.Server) *Prefork

New wraps the fasthttp server to run with preforked processes

func (*Prefork) ListenAndServe Uses

func (p *Prefork) ListenAndServe(addr string) error

ListenAndServe serves HTTP requests from the given TCP addr

func (*Prefork) ListenAndServeTLS Uses

func (p *Prefork) ListenAndServeTLS(addr, certKey, certFile string) error

ListenAndServeTLS serves HTTPS requests from the given TCP addr

certFile and keyFile are paths to TLS certificate and key files.

func (*Prefork) ListenAndServeTLSEmbed Uses

func (p *Prefork) ListenAndServeTLSEmbed(addr string, certData, keyData []byte) error

ListenAndServeTLSEmbed serves HTTPS requests from the given TCP addr

certData and keyData must contain valid TLS certificate and key data.

Package prefork imports 9 packages (graph) and is imported by 3 packages. Updated 2020-06-08. Refresh now. Tools for package owners.