apollo-java icon indicating copy to clipboard operation
apollo-java copied to clipboard

feature request: speed up user's startup time as fast as possible

Open Anilople opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. When first time load a namespace from remote,

we will get

  • 404: If namespace doesn't exists in remote, apollo-client will get 404, when first time load this namespace will be slow. fix in https://github.com/apolloconfig/apollo-java/pull/61 already, will release with 2.3.0 in the feture.
  • timeout: if apollo-configservice down, the loading of namespace will slow too.

load 10 namespaces, timeusage

  • 11494 ms when all of them meet 404
  • 65929 ms when all of them meet timeout

Describe the solution you'd like

  • decrease the total count of io
  • fast fail when meet error

Additional context

404

The code to simulate 404 when load namespace.

Main.java

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {

  private static final Logger log = LoggerFactory.getLogger(Main.class);

  public static void main(String[] args) {
    System.setProperty("app.id", "custom");
    System.setProperty("apollo.meta", "http://81.68.181.139:8080");
    // System.setProperty("apollo.loadConfigQPS", "5");
    runAndCountTime("load multiple namespace", () -> load());
  }

  static void load() {
    List<String> list = new ArrayList<>();
    for (int i = 1; i <= 10; i++) {
      list.add("ns" + i);
    }
    log.info("try to load {} namespace in list {}", list.size(), list);

    for (String ns : list) {
      runAndCountTime("load namespace " + ns, () -> {
        Config config = ConfigService.getConfig(ns);
        log.info("load namespace '{}' finished. k1 = {}", ns, config.getProperty("k1", null));
      });
    }
  }

  static void runAndCountTime(String message, Runnable runnable) {
    log.info("start {}", message);
    long s = System.currentTimeMillis();
    runnable.run();
    long end = System.currentTimeMillis();
    log.info("end {} time use {} ms", message, end - s);
  }
}

the output log before-change.log

timeout

The code to simulate timeout when load namespace.

Timeout.java

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Timeout {

  private static final Logger log = LoggerFactory.getLogger(Timeout.class);

  public static void main(String[] args) {
    System.setProperty("app.id", "custom");
    // System.setProperty("apollo.meta", "http://81.68.181.139:8080");
    // wrong meta address will cause timeout
    System.setProperty("apollo.meta", "http://81.68.181.100:8080");
    // System.setProperty("apollo.loadConfigQPS", "5");
    runAndCountTime("load multiple namespace", () -> load());
  }

  static void load() {
    List<String> list = new ArrayList<>();
    for (int i = 1; i <= 10; i++) {
      list.add("ns" + i);
    }
    log.info("try to load {} namespace in list {}", list.size(), list);

    for (String ns : list) {
      runAndCountTime("load namespace " + ns, () -> {
        Config config = ConfigService.getConfig(ns);
        log.info("load namespace '{}' finished. k1 = {}", ns, config.getProperty("k1", null));
      });
    }
  }

  static void runAndCountTime(String message, Runnable runnable) {
    log.info("start {}", message);
    long s = System.currentTimeMillis();
    runnable.run();
    long end = System.currentTimeMillis();
    log.info("end {} time use {} ms", message, end - s);
  }
}

the output log timeout-before-change.log

Anilople avatar May 07 '24 14:05 Anilople