Reputation: 1350
I am consuming soap web services using WebServiceTemplate its working fine with good performance in 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
Class for calling soap service
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 File
@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 };
}
}
Performance result Timings -- around 500ms average time , max time :- 1 sec
Spring Boot 1.5.20.RELEASE and 2.2.2.RELEASE
With spring boot same code without any change takes around 4sec for first call and if continue hitting the same then takes around 2sec for
Performance result with spring boot
First Call :- 4 sec
Subsequent calls without interval (1-10 sec gap) :- 2 sec to 800 ms
Its keep on decreasing while keep hitting the same call again and again with less interval and goes down to spring mvc 3 like result but if tried again after some interval like 5 min then again follow the same pattern If same tried after 5 mins then again the result is same for first and further calls.
Note:- With spring boot i have tried wss4j as well instead of wss4j2 Also tried AxiomSoapMessageFactory but no luck
Upvotes: 0
Views: 2205
Reputation: 1
This also can be related with maxConnectionsPerHost
parameter of MessageSender
bean. Default value is 2
,which very low for lazy endpoints.
You can override
@Bean
public HttpComponentsMessageSender messageSender() {
HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender();
messageSender.setConnectionTimeout(30000);
messageSender.setReadTimeout(30000);
messageSender.setMaxConnectionsPerHost("http://some-soap-url", "20");
return messageSender;
}
Upvotes: 0
Reputation: 1350
So the issue is not with code. I finally deployed it on jboss Wildfly and bang.. It just start performing really well without a single line change.
Now its taking around 300ms to 500ms. So the problem is with embedded tomcat and embedded jetty is not good
Upvotes: 0
Reputation: 2387
Caching could be one of the factors for the results above
Caching is a mechanism to enhance the performance of a system. It is a temporary memory that lies between the application and the persistent database. Cache memory stores recently used data items in order to reduce the number of database hits as much as possible.
JVM warm-up effect
When a JVM based app is launched, the first requests it receives are generally significantly slower than the average response time. This warm-up effect is usually due to class loading and bytecode interpretation at startup.
For further optimizing the application, use the Hypersistence Optimizer, which allows you to get the most out of JPA and Spring boot by scanning your application configuration and mappings.
Running Hypersitence Optimizer is very easy, as you just have to pass the EntityManagerFactory
instance to the HypersistenceOptimizer
object constructor, and call the init method
I suppose you already did, but if you haven't, take a look at Faster StartUp and implement the fixes suggested there.
For disabling scanning with embedded tomcat, there is a suggestion in the comments here Tomcat JarScanning
Enable Asynchronous Calls in a SpringBootApplication
@EnableSync
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
Upvotes: 0