网络 I/O 序列化

发布于 2024-08-19 08:05:29 字数 28 浏览 11 评论 0原文

为什么网络 I/O 是串行化而不是并行化?

Why is network I/O serialized and not parallelized?

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

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

发布评论

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

评论(5

深陷 2024-08-26 08:05:29

嗯,实际的数据包类型是(例如,它们都可以采用不同的路线),但在某些时候,您将需要一个流,您可以按照与您相同的顺序读取数据。把它放进去——这是 TCP 的一个关键点。否则你会怎么做?

您总是可以使用单独的套接字来提供额外的并行性吗?还是我误解了你的意思?

一些网络协议确实提供“广播”,但这并不总是可用(例如,许多网络设备会故意配置为阻止 UDP 广播)

Well, the actual packets kind of are (they could all take different routes, for example), but at some point you're going to want a stream where you read the data out in the same order you put it in - that being a key point of TCP. How else would you do this?

You could always use separate sockets to give additional parallelism? Or have I misunderstood your meaning?

Some network protocols do offer "broadcast", but this is not always available (for example many network devices such will deliberately be configured to block UDP broadcasts)

╄→承喏 2024-08-26 08:05:29

苹果和橙子。

序列化是指您获取一些结构化数据并将其扁平化为可以轻松实现的单个数据序列被传输,然后在另一端反序列化以重新创建原始结构。

并行化是指将一个任务划分为多个可以同时运行的子任务,然后将它们的结果结合起来得到相同的结果,就好像任务是由单个进程运行一样。

因此,并行化不能取代串行化,因为它们用于不同的目的。

Apples and oranges.

Serializing is when you take some structured data and flattens it into a single sequence of data that can easily be transmitted and then deserialized on the other end to recreate the original structure.

Parallelizing is when you divide a task in several sub-tasks that can be run simultaneously, and then combine their results to get the same thing as if the task was run by a single process.

So, parallelizing can not replace serializing as they are used for different purposes.

盗琴音 2024-08-26 08:05:29

因为焊接电缆连接器比添加更多处理器能力(或添加更复杂的芯片以获得更高的生产线速度)更昂贵。比较多年来通常用于通信的电缆类型:

Centronics 并行电缆 - 36 针。

RS232 电缆 25 针,然后 9 针

以太网双绞线 - 两对(4 针)

USB 电缆 - 一对 + 电源。

此外,通过无线或长距离并行传输多个通道并不容易。

Because soldering cable connectors is more expensive than adding more processor power (or to add more complicated chips for greater line speed). Compare types of cables typically used for communication over years:

Centronics parallel cable - 36 pins.

RS232 cable 25 pins, then 9 pins

Ethernet twisted pair - two pairs (4 pin)

USB cable - one pair + power.

Moreover, it is not easy to transfer several channels in paralel over wireless or long distance.

蓝咒 2024-08-26 08:05:29

将其视为数据流。数据可以分块并以无序的方式发送/接收。
为了重建原始流,必须对块重新排序。

Think it as a stream of data. The data can be chunked and sent/received in an unordered way.
To reconstruct the original stream the chunks have to be reordered.

活泼老夫 2024-08-26 08:05:29

首先,我现在的 AMD 机器正在运行具有 6CPU 核心的 Ubuntu Linux,并且“ps -ef”给出:

ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Apr18 ?        00:00:01 /sbin/init
root         2     0  0 Apr18 ?        00:00:00 [kthreadd]
root         3     2  0 Apr18 ?        00:00:00 [migration/0]
root         4     2  0 Apr18 ?        00:00:00 [ksoftirqd/0]
root         5     2  0 Apr18 ?        00:00:00 [watchdog/0]
root         6     2  0 Apr18 ?        00:00:00 [migration/1]
root         7     2  0 Apr18 ?        00:00:00 [ksoftirqd/1]
root         8     2  0 Apr18 ?        00:00:00 [watchdog/1]
root         9     2  0 Apr18 ?        00:00:00 [migration/2]
root        10     2  0 Apr18 ?        00:00:00 [ksoftirqd/2]
root        11     2  0 Apr18 ?        00:00:00 [watchdog/2]
root        12     2  0 Apr18 ?        00:00:00 [migration/3]
root        13     2  0 Apr18 ?        00:00:00 [ksoftirqd/3]
root        14     2  0 Apr18 ?        00:00:00 [watchdog/3]
root        15     2  0 Apr18 ?        00:00:00 [migration/4]
root        16     2  0 Apr18 ?        00:00:00 [ksoftirqd/4]
root        17     2  0 Apr18 ?        00:00:00 [watchdog/4]
root        18     2  0 Apr18 ?        00:00:00 [migration/5]
root        19     2  0 Apr18 ?        00:00:00 [ksoftirqd/5]
root        20     2  0 Apr18 ?        00:00:00 [watchdog/5]
root        21     2  0 Apr18 ?        00:00:00 [events/0]
root        22     2  0 Apr18 ?        00:00:00 [events/1]
root        23     2  0 Apr18 ?        00:00:00 [events/2]
root        24     2  0 Apr18 ?        00:00:00 [events/3]
root        25     2  0 Apr18 ?        00:00:00 [events/4]
root        26     2  0 Apr18 ?        00:00:00 [events/5]
root        27     2  0 Apr18 ?        00:00:00 [cpuset]
root        28     2  0 Apr18 ?        00:00:00 [khelper]
root        29     2  0 Apr18 ?        00:00:00 [async/mgr]
root        30     2  0 Apr18 ?        00:00:00 [sync_supers]
root        31     2  0 Apr18 ?        00:00:00 [bdi-default]
root        32     2  0 Apr18 ?        00:00:00 [kintegrityd/0]
root        33     2  0 Apr18 ?        00:00:00 [kintegrityd/1]
root        34     2  0 Apr18 ?        00:00:00 [kintegrityd/2]
root        35     2  0 Apr18 ?        00:00:00 [kintegrityd/3]
root        36     2  0 Apr18 ?        00:00:00 [kintegrityd/4]
root        37     2  0 Apr18 ?        00:00:00 [kintegrityd/5]
root        38     2  0 Apr18 ?        00:00:00 [kblockd/0]
root        39     2  0 Apr18 ?        00:00:00 [kblockd/1]
root        40     2  0 Apr18 ?        00:00:00 [kblockd/2]
root        41     2  0 Apr18 ?        00:00:00 [kblockd/3]
root        42     2  0 Apr18 ?        00:00:00 [kblockd/4]
root        43     2  0 Apr18 ?        00:00:00 [kblockd/5]
root        44     2  0 Apr18 ?        00:00:00 [kacpid]
root        45     2  0 Apr18 ?        00:00:00 [kacpi_notify]
root        46     2  0 Apr18 ?        00:00:00 [kacpi_hotplug]
root        47     2  0 Apr18 ?        00:00:00 [ata/0]
root        48     2  0 Apr18 ?        00:00:00 [ata/1]
root        49     2  0 Apr18 ?        00:00:00 [ata/2]
root        50     2  0 Apr18 ?        00:00:00 [ata/3]
root        51     2  0 Apr18 ?        00:00:00 [ata/4]
root        52     2  0 Apr18 ?        00:00:00 [ata/5]

从上面,您可以看到很多内核进程都是每个 cpu 核心的 - 包括 ksoftirqd。查看linux内核文档,网络驱动程序使用kso​​ftirqd来实现数据的发送。所以这就是CPU核心级别的并行化。

在网卡上,有多个“通道”——特别是对于高速网卡。所有这些都可以同时处理数据的接收和传输——再次是网卡级别的并行化。例如:

http://www.colfaxdirect.com/store /pc/viewPrd.asp?idproduct=230&idcategory=0

(查找“多通道”)。

但是,当它到达以太网线时,由于它们都共享同一根电线......电线级别的序列化是必要的。但线路的带宽通常比CPU或以太网卡的处理速率高得多。

First, my present AMD machine is running Ubuntu Linux with 6CPU-core, and "ps -ef" gave:

ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Apr18 ?        00:00:01 /sbin/init
root         2     0  0 Apr18 ?        00:00:00 [kthreadd]
root         3     2  0 Apr18 ?        00:00:00 [migration/0]
root         4     2  0 Apr18 ?        00:00:00 [ksoftirqd/0]
root         5     2  0 Apr18 ?        00:00:00 [watchdog/0]
root         6     2  0 Apr18 ?        00:00:00 [migration/1]
root         7     2  0 Apr18 ?        00:00:00 [ksoftirqd/1]
root         8     2  0 Apr18 ?        00:00:00 [watchdog/1]
root         9     2  0 Apr18 ?        00:00:00 [migration/2]
root        10     2  0 Apr18 ?        00:00:00 [ksoftirqd/2]
root        11     2  0 Apr18 ?        00:00:00 [watchdog/2]
root        12     2  0 Apr18 ?        00:00:00 [migration/3]
root        13     2  0 Apr18 ?        00:00:00 [ksoftirqd/3]
root        14     2  0 Apr18 ?        00:00:00 [watchdog/3]
root        15     2  0 Apr18 ?        00:00:00 [migration/4]
root        16     2  0 Apr18 ?        00:00:00 [ksoftirqd/4]
root        17     2  0 Apr18 ?        00:00:00 [watchdog/4]
root        18     2  0 Apr18 ?        00:00:00 [migration/5]
root        19     2  0 Apr18 ?        00:00:00 [ksoftirqd/5]
root        20     2  0 Apr18 ?        00:00:00 [watchdog/5]
root        21     2  0 Apr18 ?        00:00:00 [events/0]
root        22     2  0 Apr18 ?        00:00:00 [events/1]
root        23     2  0 Apr18 ?        00:00:00 [events/2]
root        24     2  0 Apr18 ?        00:00:00 [events/3]
root        25     2  0 Apr18 ?        00:00:00 [events/4]
root        26     2  0 Apr18 ?        00:00:00 [events/5]
root        27     2  0 Apr18 ?        00:00:00 [cpuset]
root        28     2  0 Apr18 ?        00:00:00 [khelper]
root        29     2  0 Apr18 ?        00:00:00 [async/mgr]
root        30     2  0 Apr18 ?        00:00:00 [sync_supers]
root        31     2  0 Apr18 ?        00:00:00 [bdi-default]
root        32     2  0 Apr18 ?        00:00:00 [kintegrityd/0]
root        33     2  0 Apr18 ?        00:00:00 [kintegrityd/1]
root        34     2  0 Apr18 ?        00:00:00 [kintegrityd/2]
root        35     2  0 Apr18 ?        00:00:00 [kintegrityd/3]
root        36     2  0 Apr18 ?        00:00:00 [kintegrityd/4]
root        37     2  0 Apr18 ?        00:00:00 [kintegrityd/5]
root        38     2  0 Apr18 ?        00:00:00 [kblockd/0]
root        39     2  0 Apr18 ?        00:00:00 [kblockd/1]
root        40     2  0 Apr18 ?        00:00:00 [kblockd/2]
root        41     2  0 Apr18 ?        00:00:00 [kblockd/3]
root        42     2  0 Apr18 ?        00:00:00 [kblockd/4]
root        43     2  0 Apr18 ?        00:00:00 [kblockd/5]
root        44     2  0 Apr18 ?        00:00:00 [kacpid]
root        45     2  0 Apr18 ?        00:00:00 [kacpi_notify]
root        46     2  0 Apr18 ?        00:00:00 [kacpi_hotplug]
root        47     2  0 Apr18 ?        00:00:00 [ata/0]
root        48     2  0 Apr18 ?        00:00:00 [ata/1]
root        49     2  0 Apr18 ?        00:00:00 [ata/2]
root        50     2  0 Apr18 ?        00:00:00 [ata/3]
root        51     2  0 Apr18 ?        00:00:00 [ata/4]
root        52     2  0 Apr18 ?        00:00:00 [ata/5]

From above, u can see that a lot of the kernel processes are per-cpu-core - including the ksoftirqd. Look into linux kernel documentation, networking drivers are using the ksoftirqd to implement the sending out of data. So this is parallelization at the CPU core level.

At the network card, there is multiple "channel" - especially for highspeed networking cards. And all these can process receiving and transmission of data at the same time - again parallelization at the network card level. Eg:

http://www.colfaxdirect.com/store/pc/viewPrd.asp?idproduct=230&idcategory=0

(look for "multi-channel").

But when it reach the ethernet wire, since all of them are sharing the same wire.....serialization at the wire level is necessary. But then the bandwidth of wire is usually MUCH higher than the processing rate of CPU or ethernet card.

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