Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

[nginx-ingress-controller]: Improve performance (listen backlog=net.core.somaxconn) #1350

Merged
merged 4 commits into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
659 changes: 342 additions & 317 deletions ingress/Godeps/Godeps.json

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions ingress/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 ingress/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 ingress/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 ingress/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 ingress/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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please log it too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

glog.Warningf("system net.core.somaxconn=%v. Using NGINX default (511)", maxConns)
return 511
}

return maxConns
}
1 change: 1 addition & 0 deletions ingress/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 ingress/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 ingress/vendor/github.com/Sirupsen/logrus/LICENSE

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

Loading