Announcement Announcement Module
Collapse
No announcement yet.
Managing HTTP Connection over multiple Web Service calls? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Managing HTTP Connection over multiple Web Service calls?

    I am currently working on a batch application that invokes a web service on an average of 125k times. From the stress tests we are executing, we see that the web service responds in under .15 seconds. However, the following line of code takes around .85 seconds to execute...

    Code:
    wsTemplate.sendSourceAndReceiveToResult(source, result);
    Here is the code in its entire context.

    Code:
    WebServiceTemplate wsTemplate = new WebServiceTemplate();
    
    wsTemplate.setDefaultUri(uri);
    
    List<MyObject> reqList = new ArrayList<MyObject>();
    
    for (MyObject myObj : reqList) {
    	
    	// Some Marshalling Code...
    
    	StreamSource source = new StreamSource(new ByteArrayInputStream(marshalStream.toByteArray()));
    	StreamResult result = new StreamResult(baos);
    			
    	//call the web service
    	wsTemplate.sendSourceAndReceiveToResult(source, result);
    
    	// Unmarshal baos	
    }
    The code above runs inside of a jar on top of the JVM

    I have several questions which are performance related.
    1. According to the documentation I have read, it sounds like the default behavior is to open and close the web service connection every time a call is made. If this is true, wouldn't it be more efficient to manage the HTTP connection, so that multiple calls can be made using the same web service connection?
    2. It looks like the CommonsHttpMessageSender might support HTTP connection management, does anyone have an example of how to configure this in code?
    3. Should the connection get established outside of my for loop, so it can be used for each web service call?
    4. Does anyone know of a better way to address this problem

  • #2
    An example configuration of CommonsHttpMessageSender.

    Code:
    <beans:bean id="messageSender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender" destroy-method="destroy">  
            <!--  <property name="connectionTimeout"/>
            <beans:property name="readTimeout"/> -->        
        	<beans:property name="httpClient">
        		<beans:bean class="org.apache.commons.httpclient.HttpClient" >
        			<beans:property name="httpConnectionManager">
        				<beans:bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager">
        				    <beans:property name="maxConnectionsPerHost" value="10"/>
            				<beans:property name="maxTotalConnections" value="1000"/>
        				</beans:bean>	
        			</beans:property>
        		</beans:bean>
        	</beans:property>    	
        </beans:bean>

    Comment

    Working...
    X