春季启动中的WebServiceTemplate性能问题

时间:2019-12-23 12:12:30

标签: spring-boot spring-3 webservicetemplate spring-boot-2

我正在使用WebServiceTemplate来使用肥皂网络服务,它在spring3 +上运行良好且性能良好。

spring :- 3.2.4.RELEASE
spring-ws-core :- 2.1.4.RELEASE
spring-ws-support :- 2.1.4.RELEASE
spring-ws-security :-2.1.4.RELEASE

呼叫肥皂服务的类

SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance());
messageFactory.afterPropertiesSet();

WebServiceTemplate webServiceTemplate = new WebServiceTemplate(messageFactory);

Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("some package");
marshaller.afterPropertiesSet();

webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
webServiceTemplate.afterPropertiesSet();
webServiceTemplate.setInterceptors(clientInterceptors);
webServiceTemplate.setMessageSender(webServiceMessageSenderWithAuth);
webServiceTemplate.setDefaultUri(url);
Output result= ((JAXBElement<Output >) webServiceTemplate.marshalSendAndReceive(jaxbRequest)).getValue();

配置文件

@Configuration
public class WebServiceConfiguration {

    @Autowired
    private SaajSoapMessageFactory messageFactory;

    @Autowired
    private WebServiceMessageSenderWithAuth webServiceMessageSenderWithAuth;

    @Bean
    public Wss4jSecurityInterceptor getWss4jSecurityInterceptor(@Value("${WSDL.UserName}") String userName,
            @Value("${WSDL.Password}") String password) {
        Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor();
        wss4jSecurityInterceptor.setSecurementActions("UsernameToken");
        wss4jSecurityInterceptor.setSecurementPasswordType("PasswordText");
        wss4jSecurityInterceptor.setSecurementUsername(userName);
        wss4jSecurityInterceptor.setSecurementPassword(password);
        return wss4jSecurityInterceptor;
    }

    @Bean
    public SaajSoapMessageFactory getSaajSoapMessageFactory() {
        return new SaajSoapMessageFactory();
    }

    @Bean
    public ClientInterceptor[] clientInterceptors(Wss4jSecurityInterceptor wsSecurityInterceptor) {
        return new ClientInterceptor[] { wsSecurityInterceptor };
    }
}

效果结果 时间-平均时间 500ms ,最长时间:- 1秒

Spring Boot 1.5.20.RELEASE和2.2.2.RELEASE

使用spring boot时,相同的代码没有任何更改,第一次调用大约需要4秒,如果继续按相同的代码,则需要大约2秒的时间

使用弹簧靴的性能结果

首次通话:- 4秒

后续通话没有间隔(1-10秒间隔):- 2秒 800毫秒

它不断减少,同时以较小的间隔不断一次又一次击中相同的调用,并下降到spring mvc 3之类的结果,但是如果在5分钟的某个间隔后再次尝试,则再次遵循相同的模式 如果5分钟后再次尝试,则第一次和以后的通话结果相同。

注意:-使用春季靴,我也尝试了 wss4j ,而不是 wss4j2 还尝试了 AxiomSoapMessageFactory ,但没有运气

  • 我已经尝试过保持连接等活动,但是仍然没有运气

2 个答案:

答案 0 :(得分:0)

  

缓存可能是导致上述结果的因素之一

缓存是一种增强系统性能的机制。它是位于应用程序和持久数据库之间的临时内存。 Cache memory存储最近使用的数据项,以尽可能减少数据库命中次数。

  

JVM预热效果

启动基于JVM的应用程序时,它收到的第一个请求通常比平均响应时间要慢得多。该warm-up effect通常是由于在启动时加载类和字节码解释而引起的。

要进一步优化应用程序,请使用 Hypersistence Optimizer ,它可以让您通过扫描应用程序配置和映射来充分利用JPA和Spring引导。

运行Hypersitence Optimizer非常容易,因为您只需将EntityManagerFactory实例传递给HypersistenceOptimizer对象构造函数,然后调用init方法

我想您已经做过,但是如果没有,请看看Faster StartUp并实施那里建议的修复程序。

要在嵌入式tomcat中禁用扫描,请在Tomcat JarScanning

的注释中提出建议
  

在SpringBootApplication中启用异步调用

@EnableSync
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}

答案 1 :(得分:0)

所以问题不在于代码。我终于将其部署到jboss Wildfly和bang .. 无需更改任何一行,它就开始表现非常好。

现在大约需要 300ms 500ms 。因此问题在于嵌入式tomcat和嵌入式码头不好

相关问题