Merge pull request #1138 from hzxuzhonghu/master
update nginx.go: preformance improve
This commit is contained in:
commit
6438c9f6fe
1 changed files with 16 additions and 14 deletions
|
@ -268,6 +268,10 @@ func (n NGINXController) BackendDefaults() defaults.Backend {
|
||||||
// printDiff returns the difference between the running configuration
|
// printDiff returns the difference between the running configuration
|
||||||
// and the new one
|
// and the new one
|
||||||
func (n NGINXController) printDiff(data []byte) {
|
func (n NGINXController) printDiff(data []byte) {
|
||||||
|
if !glog.V(2) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
in, err := os.Open(cfgPath)
|
in, err := os.Open(cfgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -296,10 +300,9 @@ func (n NGINXController) printDiff(data []byte) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if glog.V(2) {
|
|
||||||
glog.Infof("NGINX configuration diff\n")
|
glog.Infof("NGINX configuration diff\n")
|
||||||
glog.Infof("%v", string(diffOutput))
|
glog.Infof("%v", string(diffOutput))
|
||||||
}
|
|
||||||
os.Remove(tmpfile.Name())
|
os.Remove(tmpfile.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -410,15 +413,6 @@ func (n *NGINXController) UpdateIngressStatus(*extensions.Ingress) []api_v1.Load
|
||||||
// returning nill implies the backend will be reloaded.
|
// returning nill implies the backend will be reloaded.
|
||||||
// if an error is returned means requeue the update
|
// if an error is returned means requeue the update
|
||||||
func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
|
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 := ngx_template.ReadConfig(n.configmap.Data)
|
||||||
cfg.Resolver = n.resolver
|
cfg.Resolver = n.resolver
|
||||||
|
|
||||||
|
@ -470,8 +464,16 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
|
||||||
// if is required.
|
// if is required.
|
||||||
// https://trac.nginx.org/nginx/ticket/352
|
// https://trac.nginx.org/nginx/ticket/352
|
||||||
// https://trac.nginx.org/nginx/ticket/631
|
// 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 {
|
if cfg.ServerNameHashBucketSize == 0 {
|
||||||
|
nameHashBucketSize := nginxHashBucketSize(longestName)
|
||||||
glog.V(3).Infof("adjusting ServerNameHashBucketSize variable to %v", nameHashBucketSize)
|
glog.V(3).Infof("adjusting ServerNameHashBucketSize variable to %v", nameHashBucketSize)
|
||||||
cfg.ServerNameHashBucketSize = nameHashBucketSize
|
cfg.ServerNameHashBucketSize = nameHashBucketSize
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue