【问题标题】:Spring integration tcp factory performanceSpring集成tcp工厂性能
【发布时间】:2016-04-16 17:01:50
【问题描述】:

我在使用 spring 集成 tcp 工厂时遇到了一些性能问题。 我的应用程序有大约 70 个客户端试图通过 tcp 连接发送数据。我使用 spring 集成为 tcp 服务器使用了以下配置,但在服务器中我每 5 秒接收一次数据。但是当我在不使用 spring 集成的情况下手动实现 tcp 套接字时,我每秒收到大约 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;
   }

}

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    我怀疑您的自定义解串器 5 秒的问题是可疑的,因为您的超时也是 5 秒 - 显示代码并解释协议。

    如果反序列化器没有收到完整的消息,它将超时。

    同时打开org.springframework.integration 的 TRACE 级别日志记录以进行调试 - 如果您无法从跟踪中找出问题,请将日志文件发布到 pastebin 之类的地方,我们会看看。

    【讨论】:

    • 感谢您回复 gary ...我编辑了我的问题并添加了自定义反序列化器。关于超时,我将其更改为 10 秒,但它没有改变任何东西。回复 5 秒也是平均时间。有时需要 3 秒,有时超过 10 秒。但大多数情况下,接收每个数据大约需要 5 秒。
    • TRACE 日志有什么启示吗?
    • 到目前为止,我从 Trace 日志中了解到的一件事是消息按顺序处理。当一条消息到达时,没有其他消息到达,直到上一条消息回复客户端然后下一条消息到达(延迟约 4 秒)
    • 不使用 NIO 时,下游流在从套接字读取的同一线程上运行。但是,由于您的 requestChannel 是一个队列通道,因此应该立即释放线程以读取下一条消息。也就是说,您的配置有问题 - 服务激活器在使用 QueueChannel 时需要 &lt;poller/&gt;。调试多线程应用程序时,请务必包含线程(%t 和 log4j)。
    • 我的配置与我提出的问题完全相同。我也有一个用于异步通道的默认轮询器。所以我没明白。你觉得我的配置有什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 2015-04-26
    • 1970-01-01
    • 2017-03-21
    • 2018-11-01
    • 1970-01-01
    相关资源
    最近更新 更多