如何计算分布式系统中发送的消息数量?
假设我们有 n 个进程形成一个通用网络。我们不知道哪些进程连接在一起,但我们知道进程的数量 (n)。如果在每一轮,一个进程向它连接的所有进程发送一条消息,从每个进程接收 1 条消息,并且程序执行了r轮,有没有办法知道程序执行期间发送了多少条消息?
Suppose we have n processes forming a general network. We don't know which are connected together, but we know the number of the processes (n).If at each round, a process sends a message to all processes it is connected to, receives 1 message from each of them, and the program executes for r rounds, is there a way to find how many messages have been sent during the program execution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所指出的,如果没有确切的网络结构,就不可能对发送的消息数量给出具体的值。相反,我们可以看看它的 Big-O 值。
现在要清楚我们所说的 Big-O 的含义:
所以让我们假设最坏的情况,其中每个进程都连接到 N - 1 个其他进程。
我们还定义一些变量:
S
:= 进程集合N
:=S
中的进程数量我们可以表示集合 < code>S 作为一个完整的(每个节点都连接到每个其他节点)无向图,其中图中的每个节点对应一个进程,图中的每条边对应于 2 个发送的消息(1 个传出传输和一个回复)。
从此处,我们看到完整图中的边数为
(N( N-1))/2
所以在最坏的情况下,发送的消息数量是
N(N-1)
,或者N^2 - N
。现在,因为我们正在处理 Big-O 表示法,所以我们感兴趣的是这个值如何作为
N
的函数增长。通过三角不等式,我们可以看出
O(N^2 - N)
是O(N^2)
的一个元素。因此,在最坏的情况下,发送的消息数量会增长为
N^2
。也可以使用邻接矩阵得出此结果,即一个
N x N
矩阵,其中(i, j)
中的1
code>th 元素指的是从节点i
到节点j
的边。因为在最初的问题中,每个进程都会向所有连接的进程发送一条消息,而这些进程则用一条消息进行响应,因此我们可以看到,对于每对
(i, j)
和(j, i )
将有一条边(一条代表传出消息,一条代表回复)。例外情况是i = j
的对,即。我们的进程不会向自己发送消息。因此,除了对角线之外,矩阵将完全被
1
填充。上图:N = 4 的邻接矩阵。
因此,我们首先要确定一个公式,将发送的消息总数作为节点数量的函数。
通过矩形的面积,我们可以看到矩阵中
1
的数量(忽略对角线)将为N x N = N^2
。现在我们必须考虑对角线。可以存在的对
(x, x)
的数量由函数f(i)给出,其中Z(N) -> Z(N) x Z(N) : f(i) = (i, i)
——这意味着该函数将有 N 个不同的解。因此,总体结果是,当考虑对角线时,我们有
N^2 - N
消息。现在,我们使用与上面相同的 Big-O 推理来得出相同的结论,消息数量在最坏的情况下增长为
O(N^2)
。因此,现在您只需要考虑已发生的轮数,剩下的就是 O(RN^2)。
当然现在你必须考虑你是否真的遇到了最坏的情况......
As you have pointed out, without the exact network structure it is impossible to put a specific value on the number of messages sent. Instead, we can look at its Big-O value.
Now just to be clear what we mean by Big-O:
N / 2
other processes) we must assume the worst caseSo let us assume the worst case, in which each process is connected to
N - 1
other processes.Let us also define some variables:
S
:= the set of processesN
:= the number of processes inS
We can represent the set
S
as a complete (every node connects to every other node), undirected graph in which each node in the graph corresponds to a process and each edge in the graph corresponds to 2 messages sent (1 outgoing transmission and one reply).From here, we see that the number of edges in a complete graph is
(N(N-1))/2
So in the worst case, the number of messages sent is
N(N-1)
, orN^2 - N
.Now because we are dealing with Big-O notation, we are interested in how this value grows as a function of
N
.By the triangle inequality, we can see that
O(N^2 - N)
is an element ofO(N^2)
.So the number of messages sent grows as
N^2
in the worst case.It is also possible to arrive at this result using an adjacency matrix, that is an
N x N
matrix where a1
in the(i, j)
th element refers to an edge from nodei
to nodej
.Because in the original problem each process sends a single message to all connected processes, who respond with a single message, we can see that for every pair
(i, j)
and(j, i)
there will be an edge (one representing an outgoing message, one a reply). The exception to this will be pairs wherei = j
, ie. we a process doesn't send itself a message.So the matrix will be completely filled with
1
s with the exception of the diagonal.Above: the adjacency matrix for N = 4.
So we first want to determine a formula for the total number of messages sent as a function of the number of nodes.
By the area of a rectangle we can see that the number of
1
s in the matrix (ignoring the diagonal) would beN x N = N^2
.Now we must consider the diagonal. The number of pairs
(x, x)
that can exist is given by the functionf(i) where Z(N) -> Z(N) x Z(N) : f(i) = (i, i)
-- this means that there will be exactly N distinct solutions to this function.So the overall result is that we have
N^2 - N
messages when the diagonal is considered.Now, we use the same Big-O reasoning from above to arrive at the same conclusion, the number of messages grows in the worst case as
O(N^2)
.So, now you need only take into consideration the number of rounds that have occured, leaving you with O(RN^2).
Of course now you must consider whether you really do have the worst case ...