Skip to content

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

@Anilople

Description

@Anilople

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

we will get

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions