Why javax.xml.soap.SOAPConnection FIRST call takes much more time than subsequent calls?

时间:2016-11-03 15:41:00

标签: java soap delay latency

I don't get this one. I have been trying on different server and recently I have tried on my own lab/network (no network issue). I am building a request using a template xml file containing a constant SOAP request (validated with SOAPUI). I am measuring the call like this :

            long startTime = System.nanoTime();
            request.sendRequest();
            long estimatedTime = System.nanoTime() - startTime; 

I have built some kind of system monitor which sends a request every minute and measures the response time. Now when I get the results the first call takes much more longer every time. The last test I ran : First call was 320ms and the other calls are all returning around 180ms.

Here's the code snippet. As you can see, I am instantiating the SOAPConnection and Message before the measurement and call.

public void createRequest() {
    try {
        request = MessageFactory.newInstance().createMessage();
        SOAPPart soapPart = request.getSOAPPart();
        soapPart.setContent(new StreamSource(new FileInputStream(filename)));
        request.saveChanges();

        scf = SOAPConnectionFactory.newInstance();
        sc = scf.createConnection();

    } catch (SOAPException | FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}


public void sendRequest() {
    // TODO Auto-generated method stub
    try {
        response = sc.call(request, url);
    } catch (SOAPException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Any ideas ?

Thanks in advance to anyone for your contribution. It is very appreciated.

PS. Yep. I know I need to rework the code on exception... I just didn't spent the time on this part yet.

0 个答案:

没有答案