Skip to content

Commit

Permalink
fix: use environment variables to tune async init - and not system pr…
Browse files Browse the repository at this point in the history
…operties (#450)
  • Loading branch information
deki committed Apr 27, 2022
1 parent b192b2d commit 78a35ce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class AsyncInitializationWrapper extends InitializationWrapper {
private static final int DEFAULT_INIT_GRACE_TIME_MS = 150;
private static final String INIT_GRACE_TIME_ENVIRONMENT_VARIABLE_NAME = "AWS_SERVERLESS_JAVA_CONTAINER_INIT_GRACE_TIME";
private static final int INIT_GRACE_TIME_MS = Integer.parseInt(System.getProperty(
private static final int INIT_GRACE_TIME_MS = Integer.parseInt(System.getenv().getOrDefault(
INIT_GRACE_TIME_ENVIRONMENT_VARIABLE_NAME, Integer.toString(DEFAULT_INIT_GRACE_TIME_MS)));
private static final int LAMBDA_MAX_INIT_TIME_MS = 10_000;

Expand Down Expand Up @@ -75,7 +75,8 @@ public void start(LambdaContainerHandler handler) throws ContainerInitialization
long curTime = Instant.now().toEpochMilli();
// account for the time it took to call the various constructors with the actual start time + a grace time
long awaitTime = (actualStartTime + LAMBDA_MAX_INIT_TIME_MS) - curTime - INIT_GRACE_TIME_MS;
log.info("Async initialization will wait for " + awaitTime + "ms");
log.info("Async initialization will wait for {}ms (init grace time is configured to {})",
awaitTime, INIT_GRACE_TIME_MS);
if (!initializationLatch.await(awaitTime, TimeUnit.MILLISECONDS)) {
log.info("Initialization took longer than " + LAMBDA_MAX_INIT_TIME_MS + ", setting new CountDownLatch and " +
"continuing in event handler");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ContainerConfig {
private static final List<String> DEFAULT_FILE_PATHS = new ArrayList<String>() {{ add("/tmp"); add("/var/task"); }};
private static final int DEFAULT_MAX_INIT_TIMEOUT_MS = 20_000;
private static final String MAX_INIT_TIMEOUT_ENVIRONMENT_VARIABLE_NAME = "AWS_SERVERLESS_JAVA_CONTAINER_MAX_INIT_TIMEOUT";
private static final int MAX_INIT_TIMEOUT_MS = Integer.parseInt(System.getProperty(
private static final int MAX_INIT_TIMEOUT_MS = Integer.parseInt(System.getenv().getOrDefault(
MAX_INIT_TIMEOUT_ENVIRONMENT_VARIABLE_NAME, Integer.toString(DEFAULT_MAX_INIT_TIMEOUT_MS)));

public static ContainerConfig defaultConfig() {
Expand Down

0 comments on commit 78a35ce

Please sign in to comment.