mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
allow more socket listeners per instance for multi-core setups (#13385)
This commit is contained in:
parent
60f961dfe8
commit
acc9645249
@ -260,8 +260,16 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
|
|||||||
getCert = globalTLSCerts.GetCertificate
|
getCert = globalTLSCerts.GetCertificate
|
||||||
}
|
}
|
||||||
|
|
||||||
httpServer := xhttp.NewServer([]string{globalMinioAddr},
|
listeners := ctx.Int("listeners")
|
||||||
criticalErrorHandler{corsHandler(router)}, getCert)
|
if listeners == 0 {
|
||||||
|
listeners = 1
|
||||||
|
}
|
||||||
|
addrs := make([]string, 0, listeners)
|
||||||
|
for i := 0; i < listeners; i++ {
|
||||||
|
addrs = append(addrs, globalMinioAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
httpServer := xhttp.NewServer(addrs, criticalErrorHandler{corsHandler(router)}, getCert)
|
||||||
httpServer.BaseContext = func(listener net.Listener) context.Context {
|
httpServer.BaseContext = func(listener net.Listener) context.Context {
|
||||||
return GlobalContext
|
return GlobalContext
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,11 @@ var ServerFlags = []cli.Flag{
|
|||||||
Value: ":" + GlobalMinioDefaultPort,
|
Value: ":" + GlobalMinioDefaultPort,
|
||||||
Usage: "bind to a specific ADDRESS:PORT, ADDRESS can be an IP or hostname",
|
Usage: "bind to a specific ADDRESS:PORT, ADDRESS can be an IP or hostname",
|
||||||
},
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "listeners",
|
||||||
|
Value: 1,
|
||||||
|
Usage: "bind N number of listeners per ADDRESS:PORT",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "console-address",
|
Name: "console-address",
|
||||||
Usage: "bind to a specific ADDRESS:PORT for embedded Console UI, ADDRESS can be an IP or hostname",
|
Usage: "bind to a specific ADDRESS:PORT for embedded Console UI, ADDRESS can be an IP or hostname",
|
||||||
@ -497,8 +502,16 @@ func serverMain(ctx *cli.Context) {
|
|||||||
getCert = globalTLSCerts.GetCertificate
|
getCert = globalTLSCerts.GetCertificate
|
||||||
}
|
}
|
||||||
|
|
||||||
httpServer := xhttp.NewServer([]string{globalMinioAddr},
|
listeners := ctx.Int("listeners")
|
||||||
criticalErrorHandler{corsHandler(handler)}, getCert)
|
if listeners == 0 {
|
||||||
|
listeners = 1
|
||||||
|
}
|
||||||
|
addrs := make([]string, 0, listeners)
|
||||||
|
for i := 0; i < listeners; i++ {
|
||||||
|
addrs = append(addrs, globalMinioAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
httpServer := xhttp.NewServer(addrs, criticalErrorHandler{corsHandler(handler)}, getCert)
|
||||||
httpServer.BaseContext = func(listener net.Listener) context.Context {
|
httpServer.BaseContext = func(listener net.Listener) context.Context {
|
||||||
return GlobalContext
|
return GlobalContext
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
type acceptResult struct {
|
type acceptResult struct {
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
err error
|
err error
|
||||||
|
lidx int
|
||||||
}
|
}
|
||||||
|
|
||||||
// httpListener - HTTP listener capable of handling multiple server addresses.
|
// httpListener - HTTP listener capable of handling multiple server addresses.
|
||||||
@ -47,38 +48,24 @@ func (listener *httpListener) start() {
|
|||||||
// Successfully written to acceptCh
|
// Successfully written to acceptCh
|
||||||
return true
|
return true
|
||||||
case <-listener.ctx.Done():
|
case <-listener.ctx.Done():
|
||||||
// As stop signal is received, close accepted connection.
|
|
||||||
if result.conn != nil {
|
|
||||||
result.conn.Close()
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Closure to handle single connection.
|
|
||||||
handleConn := func(tcpConn *net.TCPConn) {
|
|
||||||
tcpConn.SetKeepAlive(true)
|
|
||||||
send(acceptResult{tcpConn, nil})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Closure to handle TCPListener until done channel is closed.
|
// Closure to handle TCPListener until done channel is closed.
|
||||||
handleListener := func(tcpListener *net.TCPListener) {
|
handleListener := func(idx int, tcpListener *net.TCPListener) {
|
||||||
for {
|
for {
|
||||||
tcpConn, err := tcpListener.AcceptTCP()
|
tcpConn, err := tcpListener.AcceptTCP()
|
||||||
if err != nil {
|
if tcpConn != nil {
|
||||||
// Returns when send fails.
|
tcpConn.SetKeepAlive(true)
|
||||||
if !send(acceptResult{nil, err}) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
go handleConn(tcpConn)
|
|
||||||
}
|
}
|
||||||
|
send(acceptResult{tcpConn, err, idx})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start separate goroutine for each TCP listener to handle connection.
|
// Start separate goroutine for each TCP listener to handle connection.
|
||||||
for _, tcpListener := range listener.tcpListeners {
|
for idx, tcpListener := range listener.tcpListeners {
|
||||||
go handleListener(tcpListener)
|
go handleListener(idx, tcpListener)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user