我试图完全按照the instructions from the online docs的顺序,甚至在每一行都包含了System.identityHashCode(this)
,以确保它是同一个对象,并且没有被垃圾收集:
public class MyLambdaHandler extends AppConfigHelper implements RequestStreamHandler, Resource {
public MyLambdaHandler() {
System.out.println("Constructor called: " + System.identityHashCode(this));
Core.getGlobalContext().register(this);
}
@Override
public void beforeCheckpoint(org.crac.Context<? extends Resource> context) throws Exception {
System.out.println("Before checkpoint: " + System.identityHashCode(this));
}
@Override
public void afterRestore(org.crac.Context<? extends Resource> context) throws Exception {
System.out.println("After restore: " + System.identityHashCode(this));
}
@Override
public void handleRequest(final InputStream input, final OutputStream output, final Context context) throws IOException {
System.out.println("Request handler called: " + System.identityHashCode(this));
}
}
但是在第一次调用时,可以看到beforeCheckpoint()
和afterRestore()
都没有被调用:
Constructor called: 91912419
START RequestId: b56b282f-4712-4d18-b300-f6e031c9468a Version: $LATEST
Request handler called: 91912419
END RequestId: b56b282f-4712-4d18-b300-f6e031c9468a
REPORT RequestId: b56b282f-4712-4d18-b300-f6e031c9468a Duration: 173.24 ms Billed Duration: 174 ms Memory Size: 1024 MB Max Memory Used: 196 MB Init Duration: 2084.86 ms
在第二次调用时,可以看到同一个对象91912419
被重用,但同样没有调用任何一个运行时钩子:
START RequestId: b1ca407e-725c-4c17-93aa-46251f1c65a6 Version: $LATEST
Request handler called: 91912419
END RequestId: b1ca407e-725c-4c17-93aa-46251f1c65a6
REPORT RequestId: b1ca407e-725c-4c17-93aa-46251f1c65a6 Duration: 1.58 ms Billed Duration: 2 ms Memory Size: 1024 MB Max Memory Used: 195 MB
1条答案
按热度按时间h5qlskok1#
您需要手动发布一个版本才能使用SnapStart,您无法在
$LATEST
上使用SnapStart。请参阅文档(https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html#snapstart-runtimes):只能对已发布的函数版本和指向版本的别名使用SnapStart。不能对函数的未发布版本($LATEST)使用SnapStart。