如何实现分布式信号量?

发布于 2024-10-26 13:26:45 字数 257 浏览 7 评论 0原文

我想要在多个进程之间共享一组有限的资源,而不是在多个服务器上运行。我想我需要的可以称为分布式信号量。

我找到了一个旧的 Perl 实现(基于 memcached)可以进行调整。我还没有完全调查过。

是否有库/组件/软件已经可以做到这一点?也许是一种算法? 故障转移怎么样?

I have a limited set of resources that I want to share between multiple processes than run on multiple servers. I guess what I need could be called a distributed semaphore.

I have found an old Perl implementation (based on memcached) that could be adapted. I have not fully investigated it yet.

Is there a library/component/software that already does that? An algorithm, perhaps?
How about failover?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

琴流音 2024-11-02 13:26:45

该算法称为 Paxos。还有其他算法,但它们都简化为 Paxos(或者是不正确的)。最流行的实现是 Apache Zookeeper。 Zookeeper 服务器在它们之间运行 Paxos。客户端引用命名对象并可以锁定它们等。

The algorithm for this is called Paxos. There are other algorithms, but they all reduce down to Paxos (or are incorrect). The most popular implementation of it is Apache Zookeeper. The Zookeeper servers run Paxos amongst themselves. Clients refer to named objects and can lock them etc.

意中人 2024-11-02 13:26:45

我想指出,从您描述的用例来看,信号量本身可能几乎不需要分布式。所以你不一定想要一个分布式信号量,而是一个用于分布式系统的信号量。

Throttle 可能符合此要求:https://github.com/pacman82/throttle

I want to point out that from the use case you describe there is probably little need for the semaphore itself to be distributed. So you do not necessarily want a distributed semaphore, but a semaphore a for distributed system.

Throttle might fit this bill: https://github.com/pacman82/throttle

陌若浮生 2024-11-02 13:26:45

为了实现分布式信号量,您需要在节点集群中定义一个权限,然后一旦选择它,您需要将请求集中到它。处理锁请求很容易,选择领导者则更复杂。

Paxos 将为您解决这个问题。我刚刚更新了 wikipedia 页面,因为算法描述不完整且具有误导性。

In order to implement a distributed semaphore, you need to define an authority amongst a cluster of node, then once it is selected, you need to centralize requests to it. Handling lock requests is a piece of cake, selecting the leader is more complicated.

Paxos will solve that for you. I have just updated the wikipedia page, because the algorithm description was incomplete and misleading.

违心° 2024-11-02 13:26:45

有一个更简单的类似于paxos的算法,叫做raft:
http://raftconsensus.github.io/

there is a simpler algorithm similar to paxos, it's called raft:
http://raftconsensus.github.io/

喜你已久 2024-11-02 13:26:45

我想建议基于领事会话实现分布式信号量。 Consul 中的会话代表具有非常特定语义的合约。

Consul 提供的契约是,在以下任何情况下,会话将失效:

  1. 节点被注销
  2. 任何健康检查被注销
  3. 任何健康检查进入临界状态
  4. 会话被显式销毁
  5. TTL 过期(如果适用)

时会话失效,被销毁并且不能再使用。

详细指南:https://www.consul.io/docs/internals/sessions.html

I'd like to suggest implement distributed semaphore based on consul sessions. A session in Consul represents a contract that has very specific semantics.

The contract that Consul provides is that under any of the following situations, the session will be invalidated:

  1. Node is deregistered
  2. Any of the health checks are deregistered
  3. Any of the health checks go to the critical state
  4. Session is explicitly destroyed
  5. TTL expires, if applicable

When a session is invalidated, it is destroyed and can no longer be used.

Detailed guide: https://www.consul.io/docs/internals/sessions.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文