扭曲:一个客户端,多个服务器
我正在尝试使用twisted 创建一组计算机,在较大的数据集上运行一个程序。
我的“服务器”从客户端接收大量数据并在其上运行命令 x 。
我的“客户端”连接到多个服务器,为每个服务器提供一块数据,并告诉它们运行命令 x 的参数。
我的问题是:有没有办法设置反应堆循环来连接到许多服务器:
reactor.connectTCP('localhost', PORT, BlastFactory())
reactor.run()
或者我是否必须在我的范例中交换客户端和服务器?
I'm trying to use twisted to create a cluster of computers that run one program on a piece of a larger dataset.
My "servers" receive a chunk of data from the client and run command x on it.
My "client" connects to multiple servers giving them each a chunk of data and telling them what parameters to run command x with.
My question is: is there a way to set up the reactor loop to connect to many servers:
reactor.connectTCP('localhost', PORT, BlastFactory())
reactor.run()
or do I have to swap client and server in my paradigm?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需多次调用
connectTCP
即可。当然,诀窍在于
reactor.run()
会“永远”阻塞(程序的整个运行时),因此您不想调用它多次。您有多种选择;您可以设置定时调用以建立未来连接,也可以从连接上的事件(例如
connectionLost
或clientConnectionFailed
)启动新连接。或者,最简单的是,您可以在 Reactor.run() 开始整个表演之前设置多次连接尝试,如下所示:
Just call
connectTCP
multiple times.The trick, of course, is that
reactor.run()
blocks "forever" (the entire run-time of your program) so you don't want to call that multiple times.You have several options; you can set up a timed call to make future connections, or you can start new connections from events on your connection (like
connectionLost
orclientConnectionFailed
).Or, at the simplest, you can just set up multiple connection attempts before
reactor.run()
kicks off the whole show, like this: