pycasbin icon indicating copy to clipboard operation
pycasbin copied to clipboard

Process support

Open Zwujun opened this issue 2 years ago • 7 comments

The current use of SyncedEnforcer can meet the multi-threaded situation, And is it possible for Casbin to support multi-process use in the future?

I try to modify on the basis of SyncedEnforcer. (The data mentioned below refers to the data in the memory)

  1. Modify _rwlock, replace the thread read-write lock with the process read-write lock;
  2. Multi-process data synchronization (addition, deletion and modification);

For 1, try to use the Redis module to replace the use of the RWLockWrite internal thread module. For 2, there can be multiple implementation methods:

  1. Consider rewriting Watcher, and modify the update method, internally use the form of message subscription publication for multi-process data synchronization;(No parameters are passed in watcher.update in the project)
  2. Use Redis as data storage to achieve data synchronization;

The above ideas were partially implemented and then interrupted. Because of insufficient personal ability, I felt that such implementation would cause the program to be complicated.

So I want to ask whether it will support multi-process use in the future, or Casbin is for multi-threaded service from the beginning.

Zwujun avatar Dec 24 '21 10:12 Zwujun

@ffyuanda @Zxilly @techoner @elfisworking

casbin-bot avatar Dec 24 '21 10:12 casbin-bot

@pppigg Watcher is the correct mechanism for multiple Casbin instances' usage. For Redis, you just need to use: https://github.com/ScienceLogic/pycasbin-redis-watcher

hsluoyz avatar Dec 24 '21 11:12 hsluoyz

Will you consider supporting multiple processes in the future (similar to SyncedEnforcer), because it also involves operation synchronization.

pycasbin-redis-watcher can solve the problem of data synchronization.

Zwujun avatar Dec 27 '21 02:12 Zwujun

@pppigg Currently I'm working to bring an official support for PyCasbin Redis Watcher, it is in progress. You can also refer to the pycasbin-redis-watcher for now, though its implementation somehow differs from how Go implements the Watcher.

The work has been suspended for quite a while coz I'm busy these days. Will resume the work around this month.

ffyuanda avatar Dec 27 '21 02:12 ffyuanda

@ffyuanda Very much looking forward to it.

Zwujun avatar Dec 27 '21 02:12 Zwujun

How i can start contribute

SidharajYadav avatar Feb 07 '22 04:02 SidharajYadav

@Abingcbc @fabian4

hsluoyz avatar Feb 07 '22 04:02 hsluoyz

@zhang-wujun we already have the official Redis watcher for PyCasbin, please use it: https://github.com/pycasbin/redis-watcher

hsluoyz avatar Nov 23 '22 14:11 hsluoyz