Spring集成tcp工厂性能

时间:2016-04-16 17:01:51

标签: spring-integration

我在spring Integration tcp factory中遇到了一些性能问题。 我的应用程序有大约70个客户端试图通过TCP连接发送数据。我使用弹簧集成在tcp服务器的下面配置,但在服务器我每5秒接收一次数据。但是当我手动实现tcp套接字而不使用spring集成时,我每秒都会收到大约5个连接。关于我的问题的任何想法?我真的想要使用spring集成,但我不知道如何才能提高我的表现。

<int:poller id="defaultPoller" default="true" tast-executor="defaultTaskExecutor"  fixed-delay="500" />
<task:executor id="defaultTaskExecutor" pool-size="5-20" queue-capacity="50"/>

<bean id="CustomeSerializerDeserializer"
    class="CustomeSerializerDeserializer" />

<task:executor id="tcpFactoryTaskExecutor" pool-size="5-20"
    queue-capacity="20000" />

<int-ip:tcp-connection-factory id="tcpConnectionFactory"
    type="server" port="5423"
    single-use="false" so-timeout="5000" task-executor="tcpFactoryTaskExecutor"
    serializer="CustomeSerializerDeserializer" deserializer="CustomeSerializerDeserializer" />

<int-ip:tcp-inbound-channel-adapter
    id="tcpInboundAdapter" channel="requestChannel" connection-factory="tcpConnectionFactory" />

<int:channel id="requestChannel">
    <int:queue capacity="50" /> 
</int:channel>

<int:service-activator input-channel="requestChannel"
    output-channel="responseChannel" ref="MessageHandler" method="parse" />

<bean id="MessageHandler"
    class="TCPMessageHandler" />

<int:channel id="responseChannel">
    <int:queue capacity="50" />
<int:channel /> 

<int-ip:tcp-outbound-channel-adapter
    id="tcpOutboundAdapter" channel="responseChannel" connection-factory="tcpConnectionFactory" />

UPDATE1:这是我的自定义序列化/反序列化程序类:

public class SerializerDeserializer extends AbstractByteArraySerializer{


   @Override
   public void serialize(byte[] object, OutputStream outputStream)
           throws IOException {
       if (object != null && object.length != 0) {
           outputStream.write(object);
           outputStream.flush();
       }
   }

   @Override
   public byte[] deserialize(InputStream inputStream) throws IOException {
       int c = inputStream.read();
           if (c!=0){
               // 2 byte
               byte[] configMessage = BinaryUtil.readNByteArrayFromStream(inputStream, c)/*(inputStream , c)*/;

               return configMessage;
           }    
           int d = inputStream.read();
           if (d==0){
               // 253 byte

               byte[] dataMessage = BinaryUtil.readNByteArrayFromStream(inputStream,253);
               return dataMessage;
           }

           // 15 byte
           byte[] hanshakeMessage = BinaryUtil.readNByteArrayFromStream(inputStream,d);
           return hanshakeMessage;
   }

}

1 个答案:

答案 0 :(得分:0)

我怀疑您的自定义反序列化程序有问题5秒是可疑的,因为您的超时也是5秒 - 显示代码并解释协议。

如果解串器没有收到完整的消息,它将超时。

同时打开org.springframework.integration的TRACE级别日志记录来调试它 - 如果你无法从跟踪中找出它,将日志文件发布到像pastebin这样的地方,我们将会看一下。