为什么 Redlock 算法说“It tries to acquire the lock in all the N instances sequentially” - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
/div> 已注册用户请  登录
JasonLaw
V2EX    数据库

为什么 Redlock 算法说“It tries to acquire the lock in all the N instances sequentially”

  •  
  •   JasonLaw 2021-10-21 12:36:03 +08:00 1146 次点击
    这是一个创建于 1456 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Distributed locks with Redis Redis - The Redlock algorithm中,它说

    It tries to acquire the lock in all the N instances sequentially, using the same key name and random value in all the instances. During step 2, when setting the lock in each instance, the client uses a timeout which is small compared to the total lock auto-release time in order to acquire it. For example if the auto-release time is 10 seconds, the timeout could be in the ~ 5-50 milliseconds range. This prevents the client from remaining blocked for a long time trying to talk with a Redis node which is down: if an instance is not available, we should try to talk with the next instance ASAP.

    sequentially 是什么含义?为什么要 sequentially 呢?

    然后在Distributed locks with Redis Redis - Retry on failure中,它又说

    When a client is unable to acquire the lock, it should try again after a random delay in order to try to desynchronize multiple clients trying to acquire the lock for the same resource at the same time (this may result in a split brain condition where nobody wins). Also the faster a client tries to acquire the lock in the majority of Redis instances, the smaller the window for a split brain condition (and the need for a retry), so ideally the client should try to send the SET commands to the N instances at the same time using multiplexing.

    这不是互相矛盾吗?还是我哪里理解错了?

    3 条回复    2022-03-23 18:26:37 +08:00
    lance6716
        1
    lance6716  
       2021-10-22 18:08:25 +08:00 via iPhone
    一上来并发请求锁,在并发高的时候冲突会很大吧。重试的时候由于随机 delay 冲突就变小了
    yibo2018
        2
    yibo2018  
       2022-03-23 17:39:32 +08:00
    最近也在看,也不知道是不是英文,所以争议才会这么大。我也提供一个佐证楼主的证据
    https://redis.io/topics/distlock#:~:text=In%20order%20to%20meet,each%20instance%20is%20similar).

    In order to meet this requirement, the strategy to talk with the N Redis servers to reduce latency is definitely multiplexing (or poor man's multiplexing, which is, putting the socket in non-blocking mode, send all the commands, and read all the commands later, assuming that the RTT between the client and each instance is similar).

    这里的 multiplexing 是不是也是同时发送的意思?而不是依次
    JasonLaw
        3
    JasonLaw  
    OP
       2022-03-23 18:26:37 +08:00
    @yibo2018 #2 我也是这么理解的
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2731 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 14:54 PVG 22:54 LAX 07:54 JFK 10:54
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86