mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
multisocket plugin (#6882)
* multisocket plugin improves performance in multiprocessor systems Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * - refactoring - update doc Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * remove port from reuseport plugin README Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * rename reuseport plugin to numsockets plugin Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * Add Recommendations to numsockets README Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * added numsockets test; made NUM_SOCKETS mandatory in doc Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * restart and whoami tests for numsockets plugin Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * default value for numsockets Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * caddy up Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * add numsockets to plugin.cfg Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * - rename numsockets plugin to multisocket - default as GOMAXPROCS - update README Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> * resolve conflicts Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com> --------- Signed-off-by: Viktor Rodionov <33463837+Shmillerov@users.noreply.github.com>
This commit is contained in:
51
plugin/multisocket/multisocket.go
Normal file
51
plugin/multisocket/multisocket.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package multisocket
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"github.com/coredns/caddy"
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
)
|
||||
|
||||
const pluginName = "multisocket"
|
||||
|
||||
func init() { plugin.Register(pluginName, setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
err := parseNumSockets(c)
|
||||
if err != nil {
|
||||
return plugin.Error(pluginName, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseNumSockets(c *caddy.Controller) error {
|
||||
config := dnsserver.GetConfig(c)
|
||||
c.Next() // "multisocket"
|
||||
|
||||
args := c.RemainingArgs()
|
||||
|
||||
if len(args) > 1 || c.Next() {
|
||||
return c.ArgErr()
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
// Nothing specified; use default that is equal to GOMAXPROCS.
|
||||
config.NumSockets = runtime.GOMAXPROCS(0)
|
||||
return nil
|
||||
}
|
||||
|
||||
numSockets, err := strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid num sockets: %w", err)
|
||||
}
|
||||
if numSockets < 1 {
|
||||
return fmt.Errorf("num sockets can not be zero or negative: %d", numSockets)
|
||||
}
|
||||
config.NumSockets = numSockets
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user