Skip to content

caser789/justhttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

justhttp

Fast HTTP library for Go

https://godoc.org/github.com/caser789/justhttp

  • Request cookie

  • Limit max connection from the same IP

    • connection pool
  • Load balancing client for multiple upstream hosts.

  • Client with requests' pipelining support.

  • Reuse-port listner

  • Trade memory usage with CPU usage for too much keep-alive connections.

  • Connection: Upgrade

  • WebSockets

  • HTTP/2.0

  • Uploaded files' parsing support

  • Features

    • Handle static files
      • Handle large file
    • Middleware friendly
      • a {k: v} store inside RequestCtx
    • hijack request
    • handle Connection: close
    • shadow to handle timeout
    • 100-continue
    • Header: Content-Range
    • Header: Range: bytes=startPos-endPos
    • Inmemory Listener
    • TLS
      • TLSConnectionState
    • Client
      • LB among multiple upstream hosts
      • Max duration for each keep-alive connection
      • SessionClient with referer and cookies support
      • pipeline requests
    • Virtual hosting
    • prefork
  • Performance

    • Use sendfile syscall
    • connection pool
      • server worker pool
    • compress response
    • stackless writer
    • TCP
      • reuseport
      • defer accept
      • fastopen

Performance optimization tips for multi-core systems.

  • Use reuseport listener.
  • Run a separate server instance per CPU core with GOMAXPROCS=1.
  • Attach each server instance to a separate CPU core using taskset.
  • Ensure the interrupts of multiqueue network card are evenly distributed between CPU cores. See this article for details.

Fasthttp best practicies

  • Do not allocate objects and buffers - just reuse them as much as possible. Fasthttp API design encourages this.
  • sync.Pool is your best friend.
  • Either do not keep references to RequestCtx members after returning from RequestHandler or call RequestCtx.TimeoutError() before returning from RequestHandler.
  • Profile your program in production. go tool pprof --alloc_objects your-program mem.pprof usually gives better insights for optimization than go tool pprof your-program cpu.pprof.
  • Avoid conversion between []byte and string, since this may result in memory allocation+copy. Fasthttp API provides functions for both []byte and string - use these functions instead of converting manually between []byte and string.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages