Permalink
Browse files

remove all PAIR sockets, Merge registration+query

  • Loading branch information...
1 parent 1f49077 commit 6115ed93855e41c05ad696bfdb3f8a90d72700b1 @minrk minrk committed Mar 21, 2011
Showing with 83 additions and 88 deletions.
  1. +17 −16 IPython/zmq/parallel/client.py
  2. +16 −6 IPython/zmq/parallel/engine.py
  3. +50 −66 IPython/zmq/parallel/hub.py
@@ -265,7 +265,7 @@ class Client(HasTraits):
_context = Instance('zmq.Context')
_config = Dict()
_engines=Instance(ReverseDict, (), {})
- _registration_socket=Instance('zmq.Socket')
+ # _hub_socket=Instance('zmq.Socket')
_query_socket=Instance('zmq.Socket')
_control_socket=Instance('zmq.Socket')
_iopub_socket=Instance('zmq.Socket')
@@ -339,12 +339,12 @@ def __init__(self, url_or_file=None, profile='default', cluster_dir=None, ipytho
self.session = ss.StreamSession(**key_arg)
else:
self.session = ss.StreamSession(username, **key_arg)
- self._registration_socket = self._context.socket(zmq.XREQ)
- self._registration_socket.setsockopt(zmq.IDENTITY, self.session.session)
+ self._query_socket = self._context.socket(zmq.XREQ)
+ self._query_socket.setsockopt(zmq.IDENTITY, self.session.session)
if self._ssh:
- tunnel.tunnel_connection(self._registration_socket, url, sshserver, **ssh_kwargs)
+ tunnel.tunnel_connection(self._query_socket, url, sshserver, **ssh_kwargs)
else:
- self._registration_socket.connect(url)
+ self._query_socket.connect(url)
self.session.debug = self.debug
@@ -449,38 +449,38 @@ def connect_socket(s, url):
else:
return s.connect(url)
- self.session.send(self._registration_socket, 'connection_request')
- idents,msg = self.session.recv(self._registration_socket,mode=0)
+ self.session.send(self._query_socket, 'connection_request')
+ idents,msg = self.session.recv(self._query_socket,mode=0)
if self.debug:
pprint(msg)
msg = ss.Message(msg)
content = msg.content
self._config['registration'] = dict(content)
if content.status == 'ok':
if content.mux:
- self._mux_socket = self._context.socket(zmq.PAIR)
+ self._mux_socket = self._context.socket(zmq.XREQ)
self._mux_socket.setsockopt(zmq.IDENTITY, self.session.session)
connect_socket(self._mux_socket, content.mux)
if content.task:
self._task_scheme, task_addr = content.task
- self._task_socket = self._context.socket(zmq.PAIR)
+ self._task_socket = self._context.socket(zmq.XREQ)
self._task_socket.setsockopt(zmq.IDENTITY, self.session.session)
connect_socket(self._task_socket, task_addr)
if content.notification:
self._notification_socket = self._context.socket(zmq.SUB)
connect_socket(self._notification_socket, content.notification)
- self._notification_socket.setsockopt(zmq.SUBSCRIBE, "")
- if content.query:
- self._query_socket = self._context.socket(zmq.PAIR)
- self._query_socket.setsockopt(zmq.IDENTITY, self.session.session)
- connect_socket(self._query_socket, content.query)
+ self._notification_socket.setsockopt(zmq.SUBSCRIBE, b'')
+ # if content.query:
+ # self._query_socket = self._context.socket(zmq.XREQ)
+ # self._query_socket.setsockopt(zmq.IDENTITY, self.session.session)
+ # connect_socket(self._query_socket, content.query)
if content.control:
- self._control_socket = self._context.socket(zmq.PAIR)
+ self._control_socket = self._context.socket(zmq.XREQ)
self._control_socket.setsockopt(zmq.IDENTITY, self.session.session)
connect_socket(self._control_socket, content.control)
if content.iopub:
self._iopub_socket = self._context.socket(zmq.SUB)
- self._iopub_socket.setsockopt(zmq.SUBSCRIBE, '')
+ self._iopub_socket.setsockopt(zmq.SUBSCRIBE, b'')
self._iopub_socket.setsockopt(zmq.IDENTITY, self.session.session)
connect_socket(self._iopub_socket, content.iopub)
self._update_engines(dict(content.engines))
@@ -496,6 +496,7 @@ def connect_socket(s, url):
def _unwrap_exception(self, content):
"""unwrap exception, and remap engineid to int."""
e = error.unwrap_exception(content)
+ print e.traceback
if e.engine_info:
e_uuid = e.engine_info['engine_uuid']
eid = self._engines[e_uuid]
@@ -41,7 +41,7 @@ def __init__(self, **kwargs):
super(EngineFactory, self).__init__(**kwargs)
ctx = self.context
- reg = ctx.socket(zmq.PAIR)
+ reg = ctx.socket(zmq.XREQ)
reg.setsockopt(zmq.IDENTITY, self.ident)
reg.connect(self.url)
self.registrar = zmqstream.ZMQStream(reg, self.loop)
@@ -74,16 +74,26 @@ def complete_registration(self, msg):
task_addr = msg.content.task
if task_addr:
shell_addrs.append(str(task_addr))
- shell_streams = []
+
+ # Uncomment this to go back to two-socket model
+ # shell_streams = []
+ # for addr in shell_addrs:
+ # stream = zmqstream.ZMQStream(ctx.socket(zmq.XREP), loop)
+ # stream.setsockopt(zmq.IDENTITY, identity)
+ # stream.connect(disambiguate_url(addr, self.location))
+ # shell_streams.append(stream)
+
+ # Now use only one shell stream for mux and tasks
+ stream = zmqstream.ZMQStream(ctx.socket(zmq.XREP), loop)
+ stream.setsockopt(zmq.IDENTITY, identity)
+ shell_streams = [stream]
for addr in shell_addrs:
- stream = zmqstream.ZMQStream(ctx.socket(zmq.PAIR), loop)
- stream.setsockopt(zmq.IDENTITY, identity)
stream.connect(disambiguate_url(addr, self.location))
- shell_streams.append(stream)
+ # end single stream-socket
# control stream:
control_addr = str(msg.content.control)
- control_stream = zmqstream.ZMQStream(ctx.socket(zmq.PAIR), loop)
+ control_stream = zmqstream.ZMQStream(ctx.socket(zmq.XREP), loop)
control_stream.setsockopt(zmq.IDENTITY, identity)
control_stream.connect(disambiguate_url(control_addr, self.location))
Oops, something went wrong.

0 comments on commit 6115ed9

Please sign in to comment.