[英]How many years of millisecond timestamps can be represented by 41 bits?
I'm looking at the Instagram blog post about sharded ID generation . 我正在看Instagram关于分片ID生成的博客文章 。 This blog post describes generating 64-bit identifiers.
此博客文章描述了生成64位标识符。 Their mechanism allocates 41 of the 64 bits to a millisecond timestamp, and they say:
他们的机制将64位中的41位分配给毫秒时间戳,他们说:
- 41 bits for time in milliseconds (gives us 41 years of IDs with a custom epoch)
41位时间(以毫秒为单位)(使用自定义纪元为我们提供41年的ID)
Is this a typo? 这是拼写错误吗? I calculated that you can store 69 years of millisecond timestamps in 41 bits.
我计算出你可以存储41位的69年毫秒时间戳。 Here's how:
这是如何做:
So, where am I wrong? 那么,我错在哪里?
You're not wrong about the calculation. 你对计算没错。
(2^41)-1 ms
== 2199023255.551 s
== 610839.7932086 hr
== 25451.65805036 days
== 69.6828 Julian years
== 69.6843 Gregorian Years
Which lines up closely with your result ( 69 years
). 哪个与您的结果密切相关(
69 years
)。
However, the website you link to does say that 41 bits
gives them 但是,您链接到的网站确实说
41 bits
给出了它们
41 years of IDs with a custom epoch
带有自定义纪元的41年ID
"Epoch" in this context is probably referring to the start date. 在这种情况下,“Epoch”可能指的是开始日期。 Given that that article was published "3 years ago", or in
2012
, we can calculate that their epoch begins in 2012 + 41 - 69 == 1984
. 鉴于该文章发表于“3年前”或
2012
,我们可以计算出他们的时代始于2012 + 41 - 69 == 1984
。 This date was possibly chosen as a reference . 这个日期可能被选为参考 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.