我使用spring-integration将数据发送到服务器套接字,并从中读取数据。
问题:从接收到的套接字数据流读取需要花费1000 the!我正在对本地套接字服务器进行测试,该服务器是即时响应的。
根本原因必须在spring框架的某个地方,因为我将spring集成部分更改为本机套接字实现,并且这个实现立即工作。
@Bean
@Primary
public AbstractClientConnectionFactory clientFactory() throws Exception {
TcpConnectionFactoryFactoryBean fact = new TcpConnectionFactoryFactoryBean();
fact.setType("client");
fact.setHost("127.0.0.1");
fact.setPort("9876");
fact.setUsingNio(true); //delay is gone if I change this to false
fact.setSingleUse(true);
fact.setSoTimeout(timeout);
fact.setDeserializer(new MyDeserializer());
fact.afterPropertiesSet();
return (AbstractClientConnectionFactory) fact.getObject();
}
/**
* The same routine applied on a native java socket works instantly!
* But the time measured if used in spring-integration is always at least 1000ms!
*/
static class MyDeserializer implements Deserializer<String> {
@Override
public String deserialize(InputStream inputStream) throws IOException {
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
StopWatch w = new StopWatch();
w.start();
String str;
while ((str = br.readLine()) != null) {
sb.append(str).append("\n");
}
w.stop();
System.out.println("time taken: " + w.getTotalTimeMillis());
return sb.toString();
}
}
}大部分反序列化时间约为1005-1010毫秒。在我的原生套接字上,相同的例程是5-10 is。那么,在TcpNioConnection.ChannelInputStream的某个地方,从春天开始,一定是什么东西导致了第二次延迟?
Sidenote:我刚刚发现,如果我更改fact.setUsingNio(false),延迟就消失了。使用nio会对此产生什么影响?
发布于 2018-05-09 13:00:29
谢谢你的报道--这是个漏洞--我打开了INT-4465。
https://stackoverflow.com/questions/50251193
复制相似问题