We have code that runs a couple of threads. Within the run event of the thread, we call 2 web services. We are experiencing performance issues when reaching iteration number 2000. The process runs at about 600ms per web service call and as it continues, it can go to almost 60 seconds...
The actual execution of each web service stays consistent but the port creation becomes slower:
long preStartTime = System.currentTimeMillis();
ServicePortType winPort = (ServicePortType) this.getConnector().getFactory().create();
long preEndTime = System.currentTimeMillis();
LOGGER.debug("@@@Web Service Prep work (1st service) took => " + (preEndTime - preStartTime) + "ms");
This will log at the start at around 80 milliseconds and as the process continues running, it can go up to 50 seconds when at the 2000 iteration:
(iteration 1) @@@Web Service Prep work (1st service) took => 80ms
(iteration 2000) @@@Web Service Prep work (1st service) took => 524421ms
Here is the connector setup:
@Override
public void init(Properties prop) {
LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
LOGGER.info("@@@@@@ Starting HTTPConnector @@@@@@@@@@@@@@");
LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
try {
factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ServicePortType.class);
LOGGER.debug("@@@URL : " + prop.getProperty("service.url"));
factory.setAddress(prop.getProperty("service.url"));
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
} catch (Exception ex) {
LOGGER.error(ex);
}
LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
LOGGER.info("@@@@@@ End HTTPConnector @@@@@@@@@@@@@@@@@@@");
LOGGER.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
}
Can anyone guide me here please?
EDIT
I changed this part which was called each and every time to static and it is only created once. Performance is good now, but don't know if that has an impact on anything else.
From this:
ServicePortType winPort = (ServicePortType) this.getConnector().getFactory().create();
To this:
private static UVSInterfaceExtendPortType winPort;
if (winPort == null)
{
winPort = (UVSInterfaceExtendPortType) this.getConnector().getFactory().create();
}
The solution for me was to instantiate the portType only once instead of each and every time (As discussed in my edit).
We do about 100k transactions per day and the speed stays below a second for the complete transaction which consists of 2 web service calls and a couple of database calls.