Azure / Azure/azure-functions-host
First request to a warm linux java function is slow
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
#### Repro steps
```bash
docker pull ahmelsayed/java-stuff:app
docker run -it -p 8081:80 ahmelsayed/java-stuff:app
```
then do
```bash
time curl https://localhost:8081/api/HttpTrigger-Java
# 0.01s user 0.01s system 0% cpu 5.555 total
```
#### Expected behavior
I expect it to be faster than 5 seconds. Subsequent requests finish in 0.03 seconds
```bash
time curl https://localhost:8081/api/HttpTrigger-Java
# 0.01s user 0.00s system 48% cpu 0.031 total
time curl https://localhost:8081/api/HttpTrigger-Java
# 0.01s user 0.00s system 51% cpu 0.033 total
```
#### Actual behavior
First request to the java function takes 5.5 seconds on average.
#### Related information
Dockerfile used for `ahmelsayed/java-stuff:app`
```dockerfile
FROM ahmelsayed/java-stuff:base
ENV CONTENT_URL=https://ahmelswestusstorage.blob.core.windows.net/public/java-hello.zip \
AZURE_FUNCTIONS_ENVIRONMENT=Development
RUN apt-get update && \
apt-get install -y unzip wget && \
wget --quiet -O content.zip "$CONTENT_URL" && \
mkdir -p /home/site/wwwroot && \
yes | unzip -q content.zip -d /home/site/wwwroot
```
Java function content: (it's the default httpTrigger sample)
```java
package javafunctions;
import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
/**
* Azure Functions with HTTP Trigger.
*/
public class Function {
/**
* This function listens at endpoint "/api/HttpTrigger-Java". Two ways to invoke it using "curl" command in bash:
* 1. curl -d "HTTP Body" {your host}/api/HttpTrigger-Java&code={your function key}
* 2. curl "{your host}/api/HttpTrigger-Java?name=HTTP%20Query&code={your function key}"
* Function Key is not needed when running locally, it is used to invoke function deployed to Azure.
* More details: https://aka.ms/functions_authorization_keys
*/
@FunctionName("HttpTrigger-Java")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage> request,
final ExecutionContext context) {
context.getLogger().info("Java HTTP trigger processed a request.");
// Parse query parameter
String query = request.getQueryParameters().get("name");
String name = request.getBody().orElse(query);
if (name == null) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
} else {
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.