0

我在haskell中试验一个简单的演员模型,每个演员:

  • 是一个haskell线程
  • 有一个 zeroMQ PULL 套接字,在该套接字上接收消息

一些演员是“众所周知的”,有无限的生命周期,因此他们的套接字绑定到一个众所周知的端口。其他参与者是短暂且短暂的,因此需要分配给他们的随机自由端口。

我以前不知道 zmq3 允许绑定到临时端口的能力,如下所述:http://api.zeromq.org/3-2:zmq- tcp

因此,对于瞬态参与者,我目前有代码尝试绑定到给定范围内的空闲端口。这按预期工作,但揭示了导致我问题的 zmq 行为:如果瞬态actor关闭它的端口并退出,并且新的瞬态actor启动,它可能会绑定到旧端口的同一个端口。在这种情况下,为旧参与者排队的任何未完成或后续消息都将被新参与者接收。

我怎样才能避免这种情况?

如果我使用通配符绑定我的临时演员套接字以获取系统分配的临时端口,我仍然可能会看到这个问题吗?

如何使用保证与任何其他传输不同的 TCP 传输生成新的唯一 PULL 套接字?

4

1 回答 1

0

In general usage, you use bind() only for stable, "well known" actors, and you use connect() for transient actors. It seems a little weird if you need the port number for transient actors.

Also, perhaps you should add something to your protocol so that transient actors that are going away let the other side know, so that the other side won't continue to send them messages (which are then received by a new transient actor bound to the same port as the old one).

I think system-assigned ephemeral ports generally try not to reuse ports immediately, so that would likely also solve some of your problems.

于 2013-04-05T08:34:57.263 回答