Java IBM云功能CORS支持中的性能差异
我正在将CORS支持添加到我的OpenWhisk/IBM云功能中。 但是在对函数进行修改(-一个web自定义选项true)后,我注意到性能下降。 为了解决这个问题,我创建了一个简单的函数,如下所示:Java IBM云功能CORS支持中的性能差异,java,cors,openwhisk,ibm-cloud-functions,Java,Cors,Openwhisk,Ibm Cloud Functions,我正在将CORS支持添加到我的OpenWhisk/IBM云功能中。 但是在对函数进行修改(-一个web自定义选项true)后,我注意到性能下降。 为了解决这个问题,我创建了一个简单的函数,如下所示: public static JsonObject main(JsonObject args) throws IOException { String method = args.get("__ow_method").getAsString(); System.ou
public static JsonObject main(JsonObject args) throws IOException {
String method = args.get("__ow_method").getAsString();
System.out.println(method+" handle");
if (method.equalsIgnoreCase("OPTIONS")) {
JsonObject responseJSON = new JsonObject();
//add CORS headers
JsonObject headers = new JsonObject();
headers.addProperty("Access-Control-Allow-Headers", "*");
headers.addProperty("Access-Control-Allow-Origin", "https://mjonker.github.io");
headers.addProperty("Access-Control-Allow-Credentials", "true");
responseJSON.add("headers", headers);
responseJSON.addProperty("statusCode", 200);
return responseJSON;
} else {
JsonObject responseJSON = new JsonObject();
JsonObject headers = new JsonObject();
headers.addProperty("Access-Control-Allow-Headers", "*");
headers.addProperty("Access-Control-Allow-Origin", "https://mjonker.github.io");
headers.addProperty("Access-Control-Allow-Credentials", "true");
headers.addProperty("Content-Type", "application/json");
responseJSON.add("headers", headers);
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD HH:mm:ss");
JsonObject answerJSON=new JsonObject();
JsonArray timeArray = new JsonArray();
timeArray.add( "It is "+sdf.format(now));
answerJSON.add("text",timeArray);
responseJSON.add("body",answerJSON );
responseJSON.addProperty("statusCode", 200);
return responseJSON;
}
}
有两种情况
1.http端点和web自定义选项为true
2.json端点和web自定义选项为false
从截图中可以看出,选项的差异很大,但帖子回复的差异也很明显。
我能做些什么来获得CORS的性能支持吗?
我是否在JAVA代码中做错了什么
创建带有自定义选项响应的web操作时,相应的函数将执行并生成选项响应。但是,如果允许默认选项响应生效,则不会执行任何函数,默认响应由API主机提供 默认响应如下所示:
因为您正在执行Java操作,所以启动时间可以解释您看到的性能。我看到一个313ms的初始时间和342ms的持续时间只是执行一个冷启动(当然,这绝对不是代表性的)。移动到eu gb,并且没有更多的性能问题我也将该功能部署到eu gb区域,在那里速度要快得多?这(几秒钟)是不是由延迟引起的?我没有其他美国南方服务的经验…谢谢,但这并不能解释7到10秒的响应时间。de-eu gb区域的性能要好得多,所以现在我可以继续使用它,但它仍然是一种奇怪的行为。请查看激活记录(wsk activation list/get),看看等待时间、初始时间和持续时间是多少。由于迁移到eu gb区域,我的性能很好,对我来说,这很有效。激活记录确实显示了数百毫秒,这对我们来说很好。您能否确认,如果我们切换到Python或Node,我们可能会有更短的激活时间。我可以想象,启动JVM需要更多的时间?
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH
Access-Control-Allow-Headers: Authorization, Content-Type