C# 中的多线程序列化

发布于 2024-10-13 14:52:30 字数 265 浏览 2 评论 0原文

问题: 我有大量的大消息需要序列化并通过网络发送。 我想最大限度地提高性能,因此我正在考虑创建多个线程用于消息序列化和一个线程用于发送数据。想法是根据网络性能动态确定序列化的线程数。如果数据发送速度很快并且序列化是瓶颈,请添加更多线程来提高序列化。如果网络速度慢,请使用较少的线程,如果发送缓冲区已满,则完全停止。

有什么想法如何做到这一点吗?

决定是否需要更多或更少线程的最佳算法是什么?

如何正确连接多个线程的序列化结果?

请回答以下任何问题?谢谢

Problem:
I have large number of big messages to serialize and send over network.
I would like to maximize performance, so I'm thinking about creating multiple threads for message serialization and one thread for sending the data. Idea is to dynamically determine number of threads for serialization based on network performance. If data is sent fast and serialization is bottleneck, add more threads to boost serialization. If network is slow, use less threads and stop completely if send buffer is full.

Any ideas how to do that?

What would be the best algorithm to decide if more or less threads are needed?

How to correctly concatenate serialization results from multiple threads?

Please answer to any of this questions? Thanks

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

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

发布评论

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

评论(2

爱给你人给你 2024-10-20 14:52:30

它可以被视为生产者/消费者问题,在 Fx4 中您可以使用 BlockingCollection。

但坦率地说,我希望(网络)I/O 成为瓶颈,而不是序列化。你必须测量。

It can be treated as a Producer/Consumer problem, In Fx4 you can use a BlockingCollection.

But frankly I would expect the (network) I/O to be the bottleneck, not the serialization. You will have to measure.

手心的海 2024-10-20 14:52:30

您可以将数据分成数据包并将数据包放入队列中。查看网络性能的进程将查看队列并决定发送多少数据包。此实现的缺点是您需要在接收端组装数据包,但可能无法按正确的顺序接收数据包。

You can chunk the data into packets and place the packets into a queue. The process that looks at network performance would look at the queue and decide how many packets to send. The downside to this implementation is that you will need to assemble the packets on the receiving end where they may not be received in the proper order.

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