多处理模块和 Pyro 的比较?
我使用 pyro 来对计算集群上的并行作业进行基本管理。 我刚刚搬到一个集群,在那里我将负责使用每个计算节点上的所有核心。 (在以前的集群上,每个核心都是一个单独的节点。)python multiprocessing 模块似乎很适合这个。 我注意到它也可以用于远程进程通信。 如果有人使用这两个框架进行远程进程通信,我将很高兴听到它们如何相互比较。 多处理模块的明显好处是它是从 2.6 开始内置的。 除此之外,我很难说哪个更好。
I use pyro for basic management of parallel jobs on a compute cluster. I just moved to a cluster where I will be responsible for using all the cores on each compute node. (On previous clusters, each core has been a separate node.) The python multiprocessing module seems like a good fit for this. I notice it can also be used for remote-process communication. If anyone has used both frameworks for remote-process communication, I'd be grateful to hear how they stack up against each other. The obvious benefit of the multiprocessing module is that it's built-in from 2.6. Apart from that, it's hard for me to tell which is better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:我正在改变我的答案,这样你就可以避免痛苦。 多重处理还不成熟,BaseManager 上的文档不正确,如果您是一个面向对象的思考者,想要在运行时动态创建共享对象,使用 PYRO 否则您将真的很后悔!如果您只是使用共享队列进行函数式编程,那么您像所有愚蠢的示例一样预先注册,这对您有好处。
简短回答
多重处理:
Pyro:
编辑:我第一次回答这个问题时,我刚刚开始研究 2.6 多重处理。 在我下面显示的代码中,Texture 类被注册并作为代理共享,但它内部的“data”属性不是。 所以猜猜会发生什么,每个进程在纹理代理内部都有一个单独的“数据”属性副本,尽管您可能期望如此。 我只是花了无数的时间试图弄清楚如何在运行时创建共享对象的良好模式,但我一直碰壁。 这是相当令人困惑和令人沮丧的。 也许只有我这么认为,但环顾四周人们尝试过的很少的例子,它看起来并不像这样。
我不得不做出痛苦的决定,放弃多处理库并更喜欢 Pyro,直到多处理更加成熟。 虽然最初我很高兴了解 python 中内置的多处理,但现在我对它感到非常厌恶,并且宁愿多次安装 Pyro 包,并庆幸 Python 存在如此美丽的库。
长答案
我在过去的项目中使用过 Pyro,并且对它非常满意。 我也开始使用 2.6 中新的多处理功能。
对于多处理,我发现允许根据需要创建共享对象有点尴尬。 看起来,在其年轻时期,多处理模块更适合函数式编程,而不是面向对象。 然而,这并不完全正确,因为这是可能的,我只是感觉受到“注册”调用的限制。
例如:
manager.py:
server.py:
client.py:
我所描述的尴尬来自于 server.py,我在其中注册了一个 getTexture 函数以从 TextureManager 中检索某个名称的函数。 当我讨论这个问题时,如果我将 TextureManager 设为创建/检索可共享纹理的可共享对象,那么这种尴尬可能会被消除。 嗯,我还在玩,但你明白了。 我不记得使用pyro遇到过这种尴尬,但可能有一个比上面的例子更干净的解决方案。
EDIT: I'm changing my answer so you avoid pain. multiprocessing is immature, the docs on BaseManager are INCORRECT, and if you're an object-oriented thinker that wants to create shared objects on the fly at run-time, USE PYRO OR YOU WILL SERIOUSLY REGRET IT! If you are just doing functional programming using a shared queue that you register up front like all the stupid examples GOOD FOR YOU.
Short Answer
Multiprocessing:
Pyro:
Edit: The first time I answered this I had just dived into 2.6 multiprocessing. In the code I show below, the Texture class is registered and shared as a proxy, however the "data" attribute inside of it is NOT. So guess what happens, each process has a separate copy of the "data" attribute inside of the Texture proxy, despite what you might expect. I just spent untold amount of hours trying to figure out how a good pattern to create shared objects during run-time and I kept running in to brick walls. It has been quite confusing and frustrating. Maybe it's just me, but looking around at the scant examples people have attempted it doesn't look like it.
I'm having to make the painful decision of dropping multiprocessing library and preferring Pyro until multiprocessing is more mature. While initially I was excited to learn multiprocessing being built into python, I am now thoroughly disgusted with it and would rather install the Pyro package many many times with glee that such a beautiful library exists for python.
Long Answer
I have used Pyro in past projects and have been very happy with it. I have also started to work with multiprocessing new in 2.6.
With multiprocessing I found it a bit awkward to allow shared objects to be created as needed. It seems like, in its youth, the multiprocessing module has been more geared for functional programming as opposed to object-oriented. However this is not entirely true because it is possible to do, I'm just feeling constrained by the "register" calls.
For example:
manager.py:
server.py:
client.py:
The awkwardness I'm describing comes from server.py where I register a getTexture function to retrieve a function of a certain name from the TextureManager. As I'm going over this the awkwardness could probably be removed if I made the TextureManager a shareable object which creates/retrieves shareable textures. Meh I'm still playing, but you get the idea. I don't remember encountering this awkwardness using pyro, but there probably is a solution that's cleaner than the example above.