Skip to content
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

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

Open
Anilople opened this issue May 7, 2024 · 0 comments · Fixed by #61 · May be fixed by #64
Open

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

Anilople opened this issue May 7, 2024 · 0 comments · Fixed by #61 · May be fixed by #64

Comments

@Anilople
Copy link
Contributor

Anilople commented May 7, 2024

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

@Anilople Anilople changed the title speed up user's startup time as fast as possible feature request: speed up user's startup time as fast as possible May 7, 2024
@Anilople Anilople reopened this May 18, 2024
@Anilople Anilople linked a pull request May 19, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant