在Python中建立分布式计算网络



所以我有大量的数据要处理,我正在使用我可以获得的一切,我的父母计算机,我的女友计算机,我的计算机,我的兄弟计算机。<<<<<<<<<<<<

他们可以借给我一些处理能力,而处理程序仅使用计算机的4个内核中的1个。我将设置一些将在他们的计算机启动

上启动奴隶的东西

我自己编码了这个"分布式计算程序",我刚刚与Google了解了插座,我想确保我不会犯一个大错误

我从我理解的插座是一种方法,只能将数据发送到B,如果B需要将数据发送到A,则需要打开另一个端口上的另一个套接字。

the "distributor" is the program that orchestrates the computing, it sends data to crunch to all the slaves, it is running on a cheap dedicated server
the "slaves" ask data from the distributor and compute stuff, store the result, then ask for more data to crunch
the "distributor" has a registration_port_distributor : 15555
the "slaves" have a registration_port_slave : 14444 (yes the same for each slaves)
work_port = registration_port_distributor + 1
the distributer boots
start of the loop
    wait for a slave connection
    a slave connect to port 15555 (registration_port_distributor) and tell the distributor "I am 'slave_name', give me 2 ports to work on my port 14444 (registration_port_slave)"
    the disbtributor connect to the slave on port 'registration_port_slave' and give it "work_port" (data_reception_port) for receiving data and work_port+1 (data_request_port) so that the slave can request new data to crunch
    work_port is incremented by 2

从这一点开始,从" data_reception_port'上的连接"接收数据来处理数据它可以要求新数据从" data_request_port''

上的连接中进行处理

我在这里看到的唯一问题是,如果2个奴隶尝试同时连接,但这很容易用5秒的睡眠在每个从属上使用一段段环修复,以重新设置连接。

您怎么看?

谢谢。

ps:是的,奴隶不会退回结果,我将手动获取它们,或以后实现。

pps:稍后将上传到我的github,该代码现在是一团糟,我正在测试各种事情。

从我理解的插座是一种方法中,一个只能发送数据 到B,如果B需要将数据发送到A,则在另一个插座 端口需要打开。

正如评论中几个人已经提到的那样,TCP插座是双向的,您可以将其用于两种通信。该应用程序必须以彼此相互了解的方式进行编码。

从此开始,从属可以接收数据以从连接处理 在" data_reception_port"上,它可以要求新数据从一个 连接'data_request_port'

一旦将应用程序模型更改为上述说明的方式,您就不再需要使用两个单独的端口/连接进行通信。

我在这里看到的唯一问题是,如果2个奴隶尝试在 同一时间,但这很容易使用每个从属上的时循环固定 用5秒的睡眠重新设置连接。

请阅读有关套接字通信中的积压。如果传入请求的计数超过目前可以提供的,则请求将被排队(队列中等待的确切请求数取决于积压参数(。查看socket.listen([backlog])功能的文档以获取更多信息。

我希望这可以回答您的问题。如果有任何混乱,请随时查询。

最新更新