Skip to content

Commit

Permalink
DUBBO-514 重启时应降低新启机器的权重
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfei0201 committed Aug 31, 2012
1 parent 63907bc commit f2e74a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invo
protected abstract <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation);

protected int getWeight(Invoker<?> invoker, Invocation invocation) {
return invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT);
int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT);
long timestamp = invoker.getUrl().getParameter(Constants.TIMESTAMP_KEY, 0L);
if (timestamp > 0L) {
int uptime = (int) (System.currentTimeMillis() - timestamp);
int warmup = invoker.getUrl().getParameter(Constants.WARMUP_KEY, Constants.DEFAULT_WARMUP);
if (uptime > 0 && uptime < warmup) {
weight = uptime / (warmup / weight);
}
}
return weight;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ public class Constants {
public static final String PID_KEY = "pid";

public static final String TIMESTAMP_KEY = "timestamp";

public static final String WARMUP_KEY = "warmup";

public static final int DEFAULT_WARMUP = 10 * 60 * 1000;

public static final String CHECK_KEY = "check";

Expand Down

0 comments on commit f2e74a9

Please sign in to comment.