go_reuseport

Brings SO_REUSEPORT into your Go server

  • Owner: kavu/go_reuseport
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
    go
  • Like:
    0
      Compare:

Github stars Tracking Chart

GO_REUSEPORT

Build Status
codecov
GoDoc

GO_REUSEPORT is a little expirement to create a net.Listener that supports SO_REUSEPORT socket option.

For now, Darwin and Linux (from 3.9) systems are supported. I'll be pleased if you'll test other systems and tell me the results.
documentation on godoc.org.

Example

package main

import (
  "fmt"
  "html"
  "net/http"
  "os"
  "runtime"
  "github.com/kavu/go_reuseport"
)

func main() {
  listener, err := reuseport.Listen("tcp", "localhost:8881")
  if err != nil {
    panic(err)
  }
  defer listener.Close()

  server := &http.Server{}
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Println(os.Getgid())
    fmt.Fprintf(w, "Hello, %q\n", html.EscapeString(r.URL.Path))
  })

  panic(server.Serve(listener))
}

Now you can run several instances of this tiny server without Address already in use errors.

Thanks

Inspired by Artur Siekielski post about SO_REUSEPORT.

Main metrics

Overview
Name With Ownerkavu/go_reuseport
Primary LanguageGo
Program languageGo (Language Count: 3)
Platform
License:MIT License
所有者活动
Created At2014-03-16 20:09:22
Pushed At2021-04-28 20:14:20
Last Commit At2021-04-28 21:49:04
Release Count6
Last Release Namev1.5.0 (Posted on )
First Release Namev1.0.0 (Posted on 2016-08-18 18:54:48)
用户参与
Stargazers Count571
Watchers Count21
Fork Count68
Commits Count64
Has Issues Enabled
Issues Count12
Issue Open Count1
Pull Requests Count20
Pull Requests Open Count0
Pull Requests Close Count4
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private