[英]Spring RestTemplate slow response time
尝试在Spring 3.2上使用RestTemplate POST对象时,平均响应时间为8秒
使用卷曲
time curl -X POST -H "Content-Type: application/xml" -T request.xml https://x.y.com:20000/rest
我的平均时间约为4秒。 我不明白为什么。
我的配置:
<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>x.y.z.Request</value>
<value>x.y.z.Response</value>
<value>x.y.z.AnotherRequest</value>
<value>x.y.z.AnotherResponse</value>
</list>
</property>
</bean>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"
scope="prototype">
<constructor-arg>
<bean
class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<property name="readTimeout" value="${application.urlReadTimeout}" />
<property name="connectTimeout" value="${application.urlConnectionTimeout}" />
</bean>
</constructor-arg>
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="jaxb2Marshaller" />
<property name="unmarshaller" ref="jaxb2Marshaller" />
</bean>
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean
class="org.springframework.http.converter.StringHttpMessageConverter" />
</list>
</property>
</bean>
然后我简单地自动接线:
@Autowired
RestTemplate restTemplate;
public Response getXml(Request request){
Response response = restTemplate.postForObject(httpUrl,request, Response.class);
}
PS:作为一种替代方案,我尝试使用JaxB解析Request / Response对象,然后使用org.apache.http.client.HttpClient
发送该对象,平均时间约为7秒,这远远不够。
这可能是ipv4 / 6问题。 尝试
curl -4 -X POST -H "Content-Type: application/xml" -T request.xml https://x.y.com:20000/rest
如果适合您,请使用param运行Java cmd
-Djava.net.preferIPv4Stack=true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.