Skip to content

Commit

Permalink
Merge pull request kubernetes-retired#1350 from aledbf/nginx-backlog
Browse files Browse the repository at this point in the history
[nginx-ingress-controller]: Improve performance (listen backlog=net.core.somaxconn)
  • Loading branch information
bprashanth authored Jul 12, 2016
2 parents cce520a + b4f1b7c commit 1aaa63e
Show file tree
Hide file tree
Showing 774 changed files with 15,455 additions and 7,939 deletions.
659 changes: 342 additions & 317 deletions Godeps/Godeps.json

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions controllers/gce/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,20 +439,22 @@ func (lbc *LoadBalancerController) syncNodes(key string) error {
return nil
}

func nodeReady(node api.Node) bool {
for ix := range node.Status.Conditions {
condition := &node.Status.Conditions[ix]
if condition.Type == api.NodeReady {
return condition.Status == api.ConditionTrue
func getNodeReadyPredicate() cache.NodeConditionPredicate {
return func(node *api.Node) bool {
for ix := range node.Status.Conditions {
condition := &node.Status.Conditions[ix]
if condition.Type == api.NodeReady {
return condition.Status == api.ConditionTrue
}
}
return false
}
return false
}

// getReadyNodeNames returns names of schedulable, ready nodes from the node lister.
func (lbc *LoadBalancerController) getReadyNodeNames() ([]string, error) {
nodeNames := []string{}
nodes, err := lbc.nodeLister.NodeCondition(nodeReady).List()
nodes, err := lbc.nodeLister.NodeCondition(getNodeReadyPredicate()).List()
if err != nil {
return nodeNames, err
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/gce/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func getZone(n api.Node) string {

// GetZoneForNode returns the zone for a given node by looking up its zone label.
func (t *GCETranslator) GetZoneForNode(name string) (string, error) {
nodes, err := t.nodeLister.NodeCondition(nodeReady).List()
nodes, err := t.nodeLister.NodeCondition(getNodeReadyPredicate()).List()
if err != nil {
return "", err
}
Expand All @@ -382,7 +382,7 @@ func (t *GCETranslator) GetZoneForNode(name string) (string, error) {
// ListZones returns a list of zones this Kubernetes cluster spans.
func (t *GCETranslator) ListZones() ([]string, error) {
zones := sets.String{}
readyNodes, err := t.nodeLister.NodeCondition(nodeReady).List()
readyNodes, err := t.nodeLister.NodeCondition(getNodeReadyPredicate()).List()
if err != nil {
return zones.List(), err
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/nginx/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ http {

# default server, including healthcheck
server {
listen 8080 default_server reuseport;
listen 8080 default_server reuseport backlog={{ .backlogSize }};

location /healthz {
access_log off;
Expand Down
1 change: 1 addition & 0 deletions controllers/nginx/nginx/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (ngx *Manager) loadTemplate() {

func (ngx *Manager) writeCfg(cfg config.Configuration, ingressCfg IngressConfig) (bool, error) {
conf := make(map[string]interface{})
conf["backlogSize"] = sysctlSomaxconn()
conf["upstreams"] = ingressCfg.Upstreams
conf["servers"] = ingressCfg.Servers
conf["tcpUpstreams"] = ingressCfg.TCPUpstreams
Expand Down
14 changes: 14 additions & 0 deletions controllers/nginx/nginx/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/golang/glog"
"github.com/mitchellh/mapstructure"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/sysctl"

"k8s.io/contrib/ingress/controllers/nginx/nginx/config"
)
Expand Down Expand Up @@ -220,3 +221,16 @@ func diff(b1, b2 []byte) (data []byte, err error) {
}
return
}

// sysctlSomaxconn returns the value of net.core.somaxconn, i.e.
// maximum number of connections that can be queued for acceptance
// http://nginx.org/en/docs/http/ngx_http_core_module.html#listen
func sysctlSomaxconn() int {
maxConns, err := sysctl.GetSysctl("net.core.somaxconn")
if err != nil || maxConns < 512 {
glog.Warningf("system net.core.somaxconn=%v. Using NGINX default (511)", maxConns)
return 511
}

return maxConns
}
1 change: 1 addition & 0 deletions vendor/github.com/Sirupsen/logrus/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/Sirupsen/logrus/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/Sirupsen/logrus/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1aaa63e

Please sign in to comment.