Skip to content

[SCB-444]try to optimize autoDiscovery function#625

Closed
mt-monster wants to merge 6 commits intoapache:masterfrom
mt-monster:master
Closed

[SCB-444]try to optimize autoDiscovery function#625
mt-monster wants to merge 6 commits intoapache:masterfrom
mt-monster:master

Conversation

@mt-monster
Copy link

@mt-monster mt-monster commented Mar 29, 2018

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

--- @WillemJiang @wujimin @liubao68
This PR is intend to optimize autoDiscovery function. as we know ,now we use retry at the first time sdk fail to register sc . when deployed in multi sc ( more than one sc instance ) enviroment , one sc instance breakup, this stategy exhausts lot of time to switch ip to next one , so i think it better to retry all the loop-ips in enviroment so that sdk can meet the health sc intance.

default

this.retry = retry;
}

public int getRetryTimes() {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can make this as a default retry mechanism, and remove setRetry.

private boolean autoDiscoveryInited = false;

public ArrayList<IpPort> getDefaultIpPort() {
return defaultIpPort;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add a method such as getMaxRetryTimes based on available ips(not defaultIpPort), and minimum value is 2.

String.format(Const.REGISTRY_API.MICROSERVICE_HEARTBEAT, microserviceId, microserviceInstanceId),
new RequestParam().setTimeout(ServiceRegistryConfig.INSTANCE.getHeartBeatRequestTimeout()),
syncHandler(countDownLatch, HttpClientResponse.class, holder));
syncHandlerForHeartbeat(countDownLatch, HttpClientResponse.class, holder));
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not duplicate this code as mentioned above.

Copy link
Author

Choose a reason for hiding this comment

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

ok. i fix it

@coveralls
Copy link

coveralls commented Mar 30, 2018

Coverage Status

Coverage increased (+0.04%) to 87.443% when pulling 2a3bc6a on mt-monster:master into ae28a9f on apache:master.


public void setRetry(boolean retry) {
this.retry = retry;
public void setRetryTimes(int retryTimes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

using a incrementRetryTimes makes logic simpler

private boolean autoDiscoveryInited = false;

public int getMaxRetryTimes() {
return currentAvailableIndex.get() < 2 ? 2 : currentAvailableIndex.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic is not correct. Assume current index is 2, and failed, index becomes 0. In this situation, only retried 2 and you expect 3 times

public void setRetry(boolean retry) {
this.retry = retry;
public void incrementRetryTimes(int retryTimes) {
this.retryTimes = retryTimes + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

++this.retryTimes is more simple, and you do not need a input parameter

LOGGER.warn("invoke service [{}] failed, retry.", requestContext.getUri());
requestContext.setIpPort(ipPortManager.getNextAvailableAddress(requestContext.getIpPort()));
requestContext.setRetry(true);
requestContext.incrementRetryTimes(requestContext.getRetryTimes());
Copy link
Contributor

Choose a reason for hiding this comment

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

See comments above, this code is quite bad, difficult to understand

}
int initialIndex = new Random().nextInt(defaultIpPort.size());
currentAvailableIndex = new AtomicInteger(initialIndex);
maxRetryTimes = defaultIpPort.size() + (getDiscoveredIpPort() == null ? 0 : getDiscoveredIpPort().size());
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is not correct. maxRetryTimes is dynamically change and you can not getDiscoveryIpPort when initialize IpPortManager

@mt-monster mt-monster closed this Mar 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants