以jar运行时的spring-boot-starter-ws性能

我们已经注意到,以下列方式运行时,SOAP Web服务的运行速度似乎更快

spring-boot:run

而不是像我们部署和运行那样打包JAR

java -jar mySpringApp.jar

速度提高了2-3倍,因此显然我们希望在我们的实时环境中使用它。

为了验证这不是我们的应用程序中的东西,我已经尝试了Spring指南中的示例应用程序

git源https://github.com/spring-guides/gs-soap-

service.git

使用JMeter进行测试可以显示相同的速度提升。我已经在Windows 7 Java 1.8.0_31和带有1.8.0_45-b14的Ubuntu

14.04平台上对此进行了测试。

肥皂服务似乎只是这种情况,简单的html在性能上没有任何显着差异。知道是什么原因造成的吗?

回答:

我对此进行了测试,看来该应用程序在以下两个代码路径中花费了大量时间:

at org.springframework.boot.loader.LaunchedURLClassLoader$1.hasMoreElements(LaunchedURLClassLoader.java:110)

at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)

at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)

at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:354)

at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)

at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)

at javax.xml.transform.FactoryFinder$1.run(FactoryFinder.java:327)

at java.security.AccessController.doPrivileged(Native Method)

at javax.xml.transform.FactoryFinder.findServiceProvider(FactoryFinder.java:323)

at javax.xml.transform.FactoryFinder.find(FactoryFinder.java:299)

at javax.xml.transform.TransformerFactory.newInstance(TransformerFactory.java:106)

at com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer.<init>(EfficientStreamingTransformer.java:68)

at com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer.newTransformer(EfficientStreamingTransformer.java:420)

at com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory.createEnvelope(EnvelopeFactory.java:106)

at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl.createEnvelopeFromSource(SOAPPart1_1Impl.java:69)

at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:128)

at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:189)

at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:60)

at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92)

at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:87)

at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:61)

at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:293)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)

at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)

at org.springframework.boot.loader.LaunchedURLClassLoader$1.hasMoreElements(LaunchedURLClassLoader.java:110)

at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)

at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)

at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:354)

at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)

at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)

at javax.xml.parsers.FactoryFinder$1.run(FactoryFinder.java:293)

at java.security.AccessController.doPrivileged(Native Method)

at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:289)

at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267)

at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:120)

at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.<init>(SAX2DOM.java:74)

at com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory.getSerializationHandler(TransletOutputHandlerFactory.java:199)

at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(TransformerImpl.java:436)

at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:342)

at com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer.transform(EfficientStreamingTransformer.java:399)

at com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory.createEnvelope(EnvelopeFactory.java:108)

at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl.createEnvelopeFromSource(SOAPPart1_1Impl.java:69)

at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:128)

at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:189)

at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:60)

at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92)

at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:87)

at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:61)

at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:293)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)

at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)

有趣的行是

at javax.xml.transform.TransformerFactory.newInstance(TransformerFactory.java:106)

at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:120)

这意味着对于每个请求,JRE中的SAAJ实现都会请求一个new TransformerFactory和一个new

DocumentBuilderFactory。这些工厂是使用JDK

1.3服务提供者发现机制定位的,该机制涉及搜索下列资源META-

INF/services。该搜索的性能对于从中查找这些资源的类加载器的特性非常敏感。这就是为什么您看到mvn spring-

boot:run与使用可执行JAR 有所不同的原因。特别地,可执行JAR包含嵌入式JAR,从这些嵌入式JAR查找资源非常昂贵。对于mvn spring-

boot:run这种情况并非如此,这可以解释为什么它更快。

由于这最终是SAAJ实现的问题,因此一种解决方案是改用Apache

Axiom。要使用Spring

Guide中的示例应用程序执行此操作,只需将以下代码添加到WebServiceConfig

    @Bean

public SoapMessageFactory messageFactory() {

return new AxiomSoapMessageFactory();

}

您还需要添加以下依赖项:

    <dependency>

<groupId>org.apache.ws.commons.axiom</groupId>

<artifactId>axiom-impl</artifactId>

<version>1.2.15</version>

</dependency>

以上是 以jar运行时的spring-boot-starter-ws性能 的全部内容, 来源链接: utcz.com/qa/404623.html

回到顶部