-
Notifications
You must be signed in to change notification settings - Fork 66
Warmup java worker before specialization #672
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
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6fad957
add warm up logics
kaibocai 443ed6f
update warm up request
kaibocai 1455c1f
minor updates
kaibocai 2fe4b0e
update logs
kaibocai 7573f8b
add warm up jar
kaibocai 5cdf082
add more logs for env testing
kaibocai 4415613
remove test logs
kaibocai d1d1d0d
refractor code
kaibocai aa7616a
add warm up log
kaibocai e01c23f
add fix for java8 systemclassloader - add warmup funciton
kaibocai 4be1995
revert pipeline change - add logs
kaibocai 95165a4
restrucer warmup handler
kaibocai 081a863
stop system classloader load java library in warmup process
kaibocai cf66c80
update warmup function
kaibocai 906ce3f
update log messages
kaibocai 6bdc34a
adjust logs
kaibocai 3921196
fix warmup jar
kaibocai 47e5747
refactor code
kaibocai 66cced2
update warm up jar
kaibocai 7208163
style refactoring
kaibocai 1be13b1
Rename to worker warmup and added capability
shreyas-gopalakrishna eb6f5ac
Updating tests
shreyas-gopalakrishna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/java/com/microsoft/azure/functions/worker/handler/WorkerWarmupHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.microsoft.azure.functions.worker.handler; | ||
|
|
||
| import com.microsoft.azure.functions.rpc.messages.*; | ||
| import com.microsoft.azure.functions.worker.WorkerLogManager; | ||
| import com.microsoft.azure.functions.worker.broker.JavaFunctionBroker; | ||
| import com.microsoft.azure.functions.worker.reflect.FactoryClassLoader; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import static com.microsoft.azure.functions.worker.Constants.JAVA_LIBRARY_DIRECTORY; | ||
|
|
||
|
|
||
| public class WorkerWarmupHandler extends MessageHandler<WorkerWarmupRequest, WorkerWarmupResponse.Builder> { | ||
|
|
||
| private static final String WARM_UP_FUNCTION_NAME = "WarmupFunc"; | ||
| private static final String WARM_UP_FUNCTION_ENTRY_POINT = "com.microsoft.azure.functions.warmup.java.Function.run"; | ||
| private static final String WARM_UP_FUNCTION_SCRIPT_FILE = JAVA_LIBRARY_DIRECTORY + "/warmup-httptrigger.jar"; | ||
| private final JavaFunctionBroker javaFunctionBroker = new JavaFunctionBroker(new FactoryClassLoader().createClassLoaderProvider()); | ||
|
|
||
| public WorkerWarmupHandler() { | ||
| super(StreamingMessage::getWorkerWarmupRequest, | ||
| WorkerWarmupResponse::newBuilder, | ||
| WorkerWarmupResponse.Builder::setResult, | ||
| StreamingMessage.Builder::setWorkerWarmupResponse); | ||
| } | ||
|
|
||
| @Override | ||
| String execute(WorkerWarmupRequest workerWarmupRequest, WorkerWarmupResponse.Builder builder) { | ||
| try { | ||
| WorkerLogManager.getSystemLogger().info("azure function java worker warm up start."); | ||
| this.javaFunctionBroker.setWorkerDirectory(workerWarmupRequest.getWorkerDirectory()); | ||
| warmupFunctionEnvironmentReload(); | ||
| UUID functionId = warmupFunctionLoad(workerWarmupRequest); | ||
| warmupInvocation(functionId); | ||
| WorkerLogManager.getSystemLogger().info("azure function java worker warm up completed successfully."); | ||
| } catch (Exception e) { | ||
| WorkerLogManager.getSystemLogger().severe("warm up process failed with exception: " + e.getMessage()); | ||
| throw new RuntimeException(e); | ||
| } | ||
| return "azure function java worker warm up completed"; | ||
| } | ||
|
|
||
| private void warmupFunctionEnvironmentReload() throws Exception { | ||
| FunctionEnvironmentReloadRequest functionEnvironmentReloadRequest = FunctionEnvironmentReloadRequest.newBuilder() | ||
| .putAllEnvironmentVariables(System.getenv()) | ||
| .build(); | ||
| new FunctionEnvironmentReloadRequestHandler(this.javaFunctionBroker).execute(functionEnvironmentReloadRequest, null); | ||
| WorkerLogManager.getSystemLogger().info("finish warm up FunctionEnvironmentReloadRequestHandler"); | ||
| } | ||
|
|
||
| private UUID warmupFunctionLoad(WorkerWarmupRequest workerWarmupRequest) throws Exception { | ||
| Map<String, BindingInfo> map = new HashMap<>(); | ||
| BindingInfo httpTrigger = BindingInfo.newBuilder().setDirection(BindingInfo.Direction.in).setDataType(BindingInfo.DataType.undefined).setType("httpTrigger").build(); | ||
| map.put("req", httpTrigger); | ||
| BindingInfo http = BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).setDataType(BindingInfo.DataType.undefined).setType("http").build(); | ||
| map.put("$return", http); | ||
| RpcFunctionMetadata rpcFunctionMetadata = RpcFunctionMetadata.newBuilder() | ||
| .setName(WARM_UP_FUNCTION_NAME) | ||
| .setEntryPoint(WARM_UP_FUNCTION_ENTRY_POINT) | ||
| .setScriptFile(workerWarmupRequest.getWorkerDirectory() + WARM_UP_FUNCTION_SCRIPT_FILE) | ||
| .putAllBindings(map) | ||
| .build(); | ||
| final UUID functionId = UUID.randomUUID(); | ||
| FunctionLoadRequest functionLoadRequest = FunctionLoadRequest.newBuilder() | ||
| .setFunctionId(functionId.toString()) | ||
| .setMetadata(rpcFunctionMetadata) | ||
| .build(); | ||
| String loadRequestResult = new FunctionLoadRequestHandler(this.javaFunctionBroker, true).execute(functionLoadRequest, FunctionLoadResponse.newBuilder()); | ||
| WorkerLogManager.getSystemLogger().info("finish warm up FunctionLoadRequestHandler with result: " + loadRequestResult); | ||
| return functionId; | ||
| } | ||
|
|
||
| private void warmupInvocation(UUID functionId) throws Exception { | ||
| List<ParameterBinding> inputDataList = new ArrayList<>(); | ||
| ParameterBinding parameterBinding = ParameterBinding.newBuilder() | ||
| .setName("req") | ||
| .setData(TypedData.newBuilder().setHttp(RpcHttp.newBuilder().setMethod("GET"))) | ||
| .build(); | ||
| inputDataList.add(parameterBinding); | ||
| InvocationRequest invocationRequest = InvocationRequest.newBuilder() | ||
| .setFunctionId(functionId.toString()) | ||
| .setInvocationId(UUID.randomUUID().toString()) | ||
| .addAllInputData(inputDataList) | ||
| .build(); | ||
| String invocationResult = new InvocationRequestHandler(this.javaFunctionBroker).execute(invocationRequest, InvocationResponse.newBuilder()); | ||
| WorkerLogManager.getSystemLogger().info("finish warm up InvocationRequestHandler with result: " + invocationResult); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.