为什么使用Jersey REST Web服务进行XML响应会花费更多时间并增加负载(在虚拟机上托管的Docker容器中的Tomcat 8上部署)。
服务的实际处理时间大约是12-20毫秒左右,但是在Tomcat访问日志中打印该请求所花费的时间时,它承受的负载有时为200〜250毫秒。 在最初的低负载下,一切都很好。 Tomcat连接已经微调到适当的线程等。
版本:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
Tomcat 8 代码段:
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@POST
@Path("/xml")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public MyResponse processRequest(MyRequest request) {
long starttime = Calendar.getInstance().getTimeInMillis();
MyResponse response = bussiness logic using request goes here
long endtime = Calendar.getInstance().getTimeInMillis();
response.setProcessingTime(endtime - starttime);
*//This ProcessingTime looks okay, but while the response is automatically unmarshalled by Jersey API and send over, the Tomcat access log shows more time to process the request. From other monitoring tool also we see the same pattern.*
return response;
}
一些高响应堆栈:可能不是根本原因。
java.lang.Thread:run:745 (method time = 0 ms, total time = 365 ms)
HTTPServlet:service:729 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.spi.container.servlet.ServletContainer:service:733 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.spi.container.servlet.ServletContainer:service:558 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.spi.container.servlet.WebComponent:service:409 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.application.WebApplicationImpl:handleRequest:1409 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.application.WebApplicationImpl:handleRequest:1419 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.application.WebApplicationImpl:_handleRequest:1473 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.application.WebApplicationImpl:_handleRequest:1542 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule:accept:84 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule:accept:147 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.uri.rules.ResourceClassRule:accept:108 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule:accept:147 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.uri.rules.HttpMethodRule:accept:302 (method time = 0 ms, total time = 365 ms)
REST Service - com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher:dispatch:75 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker:_dispatch:203 (method time = 0 ms, total time = 365 ms)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker:getParams:153 (method time = 0 ms, total time = 358 ms)
com.sun.jersey.server.impl.inject.InjectableValuesProvider:getInjectableValues:86 (method time = 0 ms, total time = 358 ms)
com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable:getValue:123 (method time = 0 ms, total time = 358 ms)
com.sun.jersey.spi.container.ContainerRequest:getEntity:490 (method time = 0 ms, total time = 358 ms)
com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider:readFrom:111 (method time = 0 ms, total time = 358 ms)
**com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider:readFrom:115 (method time = 358 ms, total time = 358 ms)**