Python中的分布式读者-作家锁定 [英] Distributed readers-writer lock in python
问题描述
我正在寻找读者-作家锁在分布式系统中的python中使用.
I am looking for a readers-writer lock that can be used in python in a distributed system.
到目前为止,我已经发现:
So far I've found:
- redlock ,它基于redis.不提供读者-作者锁定.
- dask的分布式软件包提供了锁,但同样,没有读者-作者锁定. 与Zookeeper配合使用的
- kazoo,提供读者-作者锁定.但是Zookeeper是一个非常重的依赖项,因为它是用Java编写的,因此需要JDK.
- redlock, which is based on redis. Does not provide a readers-writer lock.
- The distributed package of dask offers a lock, but again, no readers-writer lock.
- kazoo, which works with Zookeeper, offers a readers-writer lock. However Zookeeper is an extremely heavy dependency, as it written in Java and therefore requires the JDK.
kazoo/Zookeeper是否有更轻巧的替代品?理想情况下,是否经过战斗测试的纯python解决方案?
Is there a more lightweight alternative to kazoo / Zookeeper? Ideally a pure python solution that is nevertheless battle tested?
推荐答案
Redis是单线程的,读/写操作是原子的;这意味着多个同时进行的读/写操作将不会成功,并且读取器和写入器将以原子方式顺序访问资源.我相信,如果将资源作为Redis数据结构之一保存,这将解决您的问题.当使用redis和python作为组合将资源保存在redis中时,不需要单独的读写器锁定机制.
Redis is single-threaded and read/write operations are atomic; which means multiple simultaneous read/write operations will not succeed and readers and writer(s) will be obtaining access to the resource sequentially in atomic fashion. I believe this would solve your problem if the resource is kept in as one of the redis data structures. You do not need a separate reader-writer lock mechanism when using redis and python as combination where the resource is kept within redis.
希望有帮助
这篇关于Python中的分布式读者-作家锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!