Skip to content

Commit

Permalink
Merge pull request #1138 from hzxuzhonghu/master
Browse files Browse the repository at this point in the history
update nginx.go: preformance improve
  • Loading branch information
aledbf authored Aug 16, 2017
2 parents 053f665 + fb2ad65 commit 6438c9f
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions controllers/nginx/pkg/cmd/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ func (n NGINXController) BackendDefaults() defaults.Backend {
// printDiff returns the difference between the running configuration
// and the new one
func (n NGINXController) printDiff(data []byte) {
if !glog.V(2) {
return
}

in, err := os.Open(cfgPath)
if err != nil {
return
Expand Down Expand Up @@ -296,10 +300,9 @@ func (n NGINXController) printDiff(data []byte) {
return
}

if glog.V(2) {
glog.Infof("NGINX configuration diff\n")
glog.Infof("%v", string(diffOutput))
}
glog.Infof("NGINX configuration diff\n")
glog.Infof("%v", string(diffOutput))

os.Remove(tmpfile.Name())
}
}
Expand Down Expand Up @@ -410,15 +413,6 @@ func (n *NGINXController) UpdateIngressStatus(*extensions.Ingress) []api_v1.Load
// returning nill implies the backend will be reloaded.
// if an error is returned means requeue the update
func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
var longestName int
var serverNameBytes int
for _, srv := range ingressCfg.Servers {
if longestName < len(srv.Hostname) {
longestName = len(srv.Hostname)
}
serverNameBytes += len(srv.Hostname)
}

cfg := ngx_template.ReadConfig(n.configmap.Data)
cfg.Resolver = n.resolver

Expand Down Expand Up @@ -470,8 +464,16 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
// if is required.
// https://trac.nginx.org/nginx/ticket/352
// https://trac.nginx.org/nginx/ticket/631
nameHashBucketSize := nginxHashBucketSize(longestName)
var longestName int
var serverNameBytes int
for _, srv := range ingressCfg.Servers {
if longestName < len(srv.Hostname) {
longestName = len(srv.Hostname)
}
serverNameBytes += len(srv.Hostname)
}
if cfg.ServerNameHashBucketSize == 0 {
nameHashBucketSize := nginxHashBucketSize(longestName)
glog.V(3).Infof("adjusting ServerNameHashBucketSize variable to %v", nameHashBucketSize)
cfg.ServerNameHashBucketSize = nameHashBucketSize
}
Expand Down

0 comments on commit 6438c9f

Please sign in to comment.