搜索模式以创建 TCP 连接池以实现高性能消息传递

发布于 2024-09-01 15:28:01 字数 263 浏览 2 评论 0原文

我正在用 C# 创建一个新的客户端/服务器应用程序,并期望有相当高的连接率。这让我想到了数据库连接池,它有助于减轻在客户端和数据库之间创建和处置连接的费用。

我想为我的应用程序创建类似的功能,但无法找到任何如何应用此模式的好示例。每次我想向服务器发送消息并接收接收消息时,是否真的需要启动 TcpClient 实例?每个连接预计传输 1-5KB 数据,每个连接接收 1KB 响应消息。

我意识到这个问题有点模糊,但我是从头开始,所以我愿意接受建议。即使这意味着我的假设都是错误的。

I'm creating a new Client / Server application in C# and expect to have a fairly high rate of connections. That made me think of database connection pools which help mitigate the expense of creating and disposing connections between the client and database.

I would like to create a similar capability for my application and haven't been able to find any good examples of how to apply this pattern. Do I really need to spin up an instance of a TcpClient every time I want to send a message to the server and receive a receipt message? Each connection is expected to transport between 1-5KB with each receiving a 1KB response message.

I realize this question is somewhat vague, but I am starting from scratch so I am open to suggestions. Even if that means my suppositions are all wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪失控 2024-09-08 15:28:01

引入连接池是一种优化。 过早优化可能会很糟糕。

我建议您在不引入连接池的情况下开始开发。当客户端和服务器代码足够稳定时,您可以创建负载测试并检测性能问题。

如果与数据传入/传出服务器的速率相比,创建连接的时间相当长(负载测试应该表明这一点),则需要连接池。

如果来自客户端的数据发送不那么频繁,您甚至可能不需要连接池。

Introducing connection pool is a sort of optimization. Premature optimization can be bad.

I would recommend you start develpment without introducing connection pool. When client and server code is stable enough you can create load tests and detect performance problems.

Connection pool is required if time to create a connection is considerable compared to the rate at which data is coming to/from server (load tests should indicate that).

If data from client is send not that often you may not even need connection pool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文