【问题标题】:should I use Instagram postgressql id generator techniques for my project我应该为我的项目使用 Instagram postgressql id 生成器技术吗
【发布时间】:2020-02-15 15:50:17
【问题描述】:

如果我的纪元时间是 2019-11-11。多少年来,我可以使用 Instagram 技术生成独一无二的作品。有人可以解释这个算法是如何工作的。 https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c?gi=a23b1b9c6107

【问题讨论】:

    标签: django postgresql amazon-web-services web-development-server


    【解决方案1】:

    您喜欢的文章中的此信息:

    我们的每个 ID 都包含:

    • 41 位以毫秒为单位的时间(为我们提供 41 年的自定义纪元 ID)

    因此:

    • 41 位给出 2^41=2199023255552 种可能性,
    • 每天有1000*60*60*24=86400000毫秒,
    • 他们可以生成 2199023255552/86400000≈25451 天,
    • 表示 25451/365.25≈69 年。

    如果您需要确切的答案 - 纪元为“2019-11-11 00:00 UTC”的算法在 2089 年 7 月 17 日下午之前有效:

    => select '2019-11-11 00:00 UTC'::timestamptz+2^41*'1ms'::interval;
    2089-07-17 15:47:35.552+00
    

    【讨论】:

      猜你喜欢
      • 2011-02-25
      • 2010-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-18
      • 1970-01-01
      • 2010-12-28
      • 2011-05-27
      相关资源
      最近更新 更多