Skip to content

Add initial-inflight-factor option to vespa-feed-client to mitigate the slow start #34247

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vespa-feed-client-api/abi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"public abstract ai.vespa.feed.client.FeedClientBuilder setEndpointUris(java.util.List)",
"public abstract ai.vespa.feed.client.FeedClientBuilder setProxy(java.net.URI)",
"public abstract ai.vespa.feed.client.FeedClientBuilder setCompression(ai.vespa.feed.client.FeedClientBuilder$Compression)",
"public abstract ai.vespa.feed.client.FeedClientBuilder setInitialInflightFactor(int)",
"public abstract ai.vespa.feed.client.FeedClient build()"
],
"fields" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ static void setFeedClientBuilderSupplier(Supplier<FeedClientBuilder> supplier) {

enum Compression { auto, none, gzip }

/**
* Sets the initial inflight factor for this client.
*
* This determines the initial targetInflight,
* which is {@code minInflight * initialInflightFactor}.
*/
FeedClientBuilder setInitialInflightFactor(int factor);

/** Constructs instance of {@link FeedClient} from builder configuration */
FeedClient build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class CliArguments {
private static final String PROXY_OPTION = "proxy";
private static final String COMPRESSION = "compression";
private static final String LOG_CONFIG_OPTION = "log-config";
private static final String INITIAL_INFLIGHT_FACTOR_OPTION = "initial-inflight-factor";

private final CommandLine arguments;

Expand Down Expand Up @@ -227,6 +228,8 @@ private Optional<Path> fileValue(String option) throws CliArgumentsException {
}
}

OptionalInt initialInflightFactor() throws CliArgumentsException { return intValue(INITIAL_INFLIGHT_FACTOR_OPTION); }

private Optional<String> stringValue(String option) { return Optional.ofNullable(arguments.getOptionValue(option)); }

private OptionalDouble doubleValue(String option) throws CliArgumentsException {
Expand Down Expand Up @@ -384,6 +387,12 @@ private static Options createOptions() {
"VESPA_HOME/conf/vespa-feed-client/logging.properties")
.hasArg()
.type(File.class)
.build())
.addOption(Option.builder()
.longOpt(INITIAL_INFLIGHT_FACTOR_OPTION)
.desc("Multiplier for minInflight to determine the initial targetInflight")
.hasArg()
.type(Number.class)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private static FeedClient createFeedClient(CliArguments cliArgs) throws CliArgum
cliArgs.doomSeconds().ifPresent(doom -> builder.setCircuitBreaker(new GracePeriodCircuitBreaker(Duration.ofSeconds(10),
Duration.ofSeconds(doom))));
cliArgs.proxy().ifPresent(builder::setProxy);
cliArgs.initialInflightFactor().ifPresent(builder::setInitialInflightFactor);
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void parses_parameters_correctly() throws CliArguments.CliArgumentsException {
"--show-errors",
"--show-all",
"--max-failure-seconds", "30",
"--proxy", "https://myproxy:1234"});
"--proxy", "https://myproxy:1234",
"--initial-inflight-factor", "64"});
assertEquals(URI.create("https://vespa.ai:4443/"), args.endpoint());
assertEquals(Paths.get("feed.json"), args.inputFile().get());
assertEquals(10, args.connections().getAsInt());
Expand All @@ -70,6 +71,7 @@ void parses_parameters_correctly() throws CliArguments.CliArgumentsException {
assertFalse(args.showProgress());
assertEquals(Compression.gzip, args.compression());
assertEquals(URI.create("https://myproxy:1234"), args.proxy().orElse(null));
assertEquals(64, args.initialInflightFactor().getAsInt());
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions vespa-feed-client-cli/src/test/resources/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Vespa feed client
--header <arg> HTTP header on the form 'Name:
value'
--help
--initial-inflight-factor <arg> Multiplier for minInflight to
determine the initial
targetInflight
--log-config <arg> Specify a path to a Java Util
Logging properties file.
Overrides the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public class DynamicThrottler extends StaticThrottler {

public DynamicThrottler(FeedClientBuilderImpl builder) {
super(builder);
targetInflight = new AtomicLong(minInflight);
long calculatedInflight = minInflight * builder.initialInflightFactor;
long cappedInflight = Math.min(calculatedInflight, maxInflight);
targetInflight = new AtomicLong(cappedInflight);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class FeedClientBuilderImpl implements FeedClientBuilder {
URI proxy;
Duration connectionTtl = Duration.ZERO;
LongSupplier nanoClock = System::nanoTime;
int initialInflightFactor = 1;

public FeedClientBuilderImpl() { }

Expand Down Expand Up @@ -257,6 +258,13 @@ FeedClientBuilderImpl setNanoClock(LongSupplier nanoClock) {
return this;
}

@Override
public FeedClientBuilderImpl setInitialInflightFactor(int factor) {
if (factor < 1) throw new IllegalArgumentException("Initial inflight factor must be at least 1, but was " + factor);
this.initialInflightFactor = factor;
return this;
}

/** Constructs instance of {@link ai.vespa.feed.client.FeedClient} from builder configuration */
@Override
public FeedClient build() {
Expand Down
Loading