-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
⚡ Improving performance. #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,23 +66,14 @@ func (w *SW) All() map[interface{}]int { | |
|
||
// Next returns next selected server. | ||
func (w *SW) Next() interface{} { | ||
i := w.nextWeighted() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why removed this line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because can be
|
||
if i == nil { | ||
switch w.n { | ||
case 0: | ||
return nil | ||
case 1: | ||
return w.items[0].Item | ||
default: | ||
return nextSmoothWeighted(w.items).Item | ||
} | ||
return i.Item | ||
} | ||
|
||
// nextWeighted returns next selected weighted object. | ||
func (w *SW) nextWeighted() *smoothWeighted { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be more concise to make these judgments in next. |
||
if w.n == 0 { | ||
return nil | ||
} | ||
if w.n == 1 { | ||
return w.items[0] | ||
} | ||
|
||
return nextSmoothWeighted(w.items) | ||
} | ||
|
||
//https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35 | ||
|
@@ -92,10 +83,6 @@ func nextSmoothWeighted(items []*smoothWeighted) (best *smoothWeighted) { | |
for i := 0; i < len(items); i++ { | ||
w := items[i] | ||
|
||
if w == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the parameters call into the method nextSmoothWeighted() always is greater than 1. Another way, whether it is len(items) =0; i !< 0; len(items) > 1 , items[i] != nil; So, those code never gets executed. |
||
continue | ||
} | ||
|
||
w.CurrentWeight += w.EffectiveWeight | ||
total += w.EffectiveWeight | ||
if w.EffectiveWeight < w.Weight { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if w.n == 0; just return; No additional method calls are required.