forked from coredns/coredns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* multisocket plugin improves performance in multiprocessor systems Signed-off-by: Viktor Rodionov <[email protected]> * - refactoring - update doc Signed-off-by: Viktor Rodionov <[email protected]> * remove port from reuseport plugin README Signed-off-by: Viktor Rodionov <[email protected]> * rename reuseport plugin to numsockets plugin Signed-off-by: Viktor Rodionov <[email protected]> * Add Recommendations to numsockets README Signed-off-by: Viktor Rodionov <[email protected]> * added numsockets test; made NUM_SOCKETS mandatory in doc Signed-off-by: Viktor Rodionov <[email protected]> * restart and whoami tests for numsockets plugin Signed-off-by: Viktor Rodionov <[email protected]> * default value for numsockets Signed-off-by: Viktor Rodionov <[email protected]> * caddy up Signed-off-by: Viktor Rodionov <[email protected]> * add numsockets to plugin.cfg Signed-off-by: Viktor Rodionov <[email protected]> * - rename numsockets plugin to multisocket - default as GOMAXPROCS - update README Signed-off-by: Viktor Rodionov <[email protected]> * resolve conflicts Signed-off-by: Viktor Rodionov <[email protected]> --------- Signed-off-by: Viktor Rodionov <[email protected]>
- Loading branch information
1 parent
43fdf73
commit 6c39f4b
Showing
11 changed files
with
438 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ var Directives = []string{ | |
"cancel", | ||
"tls", | ||
"timeouts", | ||
"multisocket", | ||
"reload", | ||
"nsid", | ||
"bufsize", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# multisocket | ||
|
||
## Name | ||
|
||
*multisocket* - allows to start multiple servers that will listen on one port. | ||
|
||
## Description | ||
|
||
With *multisocket*, you can define the number of servers that will listen on the same port. The SO_REUSEPORT socket | ||
option allows to open multiple listening sockets at the same address and port. In this case, kernel distributes incoming | ||
connections between sockets. | ||
|
||
Enabling this option allows to start multiple servers, which increases the throughput of CoreDNS in environments with a | ||
large number of CPU cores. | ||
|
||
## Syntax | ||
|
||
~~~ | ||
multisocket [NUM_SOCKETS] | ||
~~~ | ||
|
||
* **NUM_SOCKETS** - the number of servers that will listen on one port. Default value is equal to GOMAXPROCS. | ||
|
||
## Examples | ||
|
||
Start 5 TCP/UDP servers on the same port. | ||
|
||
~~~ corefile | ||
. { | ||
multisocket 5 | ||
forward . /etc/resolv.conf | ||
} | ||
~~~ | ||
|
||
Do not define `NUM_SOCKETS`, in this case it will take a value equal to GOMAXPROCS. | ||
|
||
~~~ corefile | ||
. { | ||
multisocket | ||
forward . /etc/resolv.conf | ||
} | ||
~~~ | ||
|
||
## Recommendations | ||
|
||
The tests of the `multisocket` plugin, which were conducted for `NUM_SOCKETS` from 1 to 10, did not reveal any side | ||
effects or performance degradation. | ||
|
||
This means that the `multisocket` plugin can be used with a default value that is equal to GOMAXPROCS. | ||
|
||
However, to achieve the best results, it is recommended to consider the specific environment and plugins used in | ||
CoreDNS. To determine the optimal configuration, it is advisable to conduct performance tests with different | ||
`NUM_SOCKETS`, measuring Queries Per Second (QPS) and system load. | ||
|
||
If conducting such tests is difficult, follow these recommendations: | ||
1. Determine the maximum CPU consumption of CoreDNS server without `multisocket` plugin. Estimate how much CPU CoreDNS | ||
actually consumes in specific environment under maximum load. | ||
2. Align `NUM_SOCKETS` with the estimated CPU usage and CPU limits or system's available resources. | ||
Examples: | ||
- If CoreDNS consumes 4 CPUs and 8 CPUs are available, set `NUM_SOCKETS` to 2. | ||
- If CoreDNS consumes 8 CPUs and 64 CPUs are available, set `NUM_SOCKETS` to 8. | ||
|
||
## Limitations | ||
|
||
The SO_REUSEPORT socket option is not available for some operating systems. It is available since Linux Kernel 3.9 and | ||
not available for Windows at all. | ||
|
||
Using this plugin with a system that does not support SO_REUSEPORT will cause an `address already in use` error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Oops, something went wrong.