重用连接还是为了频繁发送数据而更新它们会更好吗? [英] Is it better to reuse connections, or renew them for sending data frequently?

查看:60
本文介绍了重用连接还是为了频繁发送数据而更新它们会更好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TCP服务器应用程序,它侦听来自客户端的连接,这些客户端以相当小的间隔(约20秒)频繁发送心跳"数据包.有几百个这样的客户,最多为1000个.

I have a TCP server application which listens for connections from clients that send "heartbeat" packets frequently in rather small intervals, around 20 seconds. There are a few hundred such clients, 1000 at most.

先前已实现(不是由我执行),以便为每个心跳建立一个新的TCP连接,然后将其关闭.

It has previously been implemented (not by me) such that a new TCP connection is established for every heartbeat, then it is closed.

在我看来,保持连接打开并将其重新用于通信会更好,但是我不确定.重新建立连接是否浪费时间和带宽并保持数百个打开的连接(对于服务器而言)不是问题,或者相反,不关闭它们会浪费大量资源吗?

It seems to me that it would be better to keep the connection open and reuse it for the communication, but I'm not sure. Is re-establishing the connections a waste of time and bandwidth and keeping a few hundred open connections (in the server's case) not a problem, or, on the contrary, is it a big waste of resources not to close them?

推荐答案

最好的选择取决于您拥有的内存量,连接的延迟时间和心跳的频率:

It depends on the amount of memory you have, of the latency of the connection and of the frequency of the heartbeat what the best options is:

  • 每个TCP连接都需要1xRTT的时间来建立,因此每次创建一个新的连接都花费大量的时间,但没有资源.
  • 每个打开的TCP连接的状态都需要保留在系统上,这意味着它占用了内存资源.

这篇关于重用连接还是为了频繁发送数据而更新它们会更好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆