Documentation ¶
Overview ¶
使用一个简单实现的 Bloom Filter 实现了分享ID 生成器 ID 生成的过程:
1.随机生成 3 个 byte 2.将随 bytes 进行 hash 产生 Bloom Filter 所需要的 hash 数目 3.由 Bloom Filter 进行过滤,如不存在则插入过滤器,否则返回 ErrKeyExist 4.将随机 bytes 转换成字符串 ID 返回
注意:
因为采取了随机字符串,当 ID 分配数接近 1000W 时性能会开始剧烈恶化。 可以通过修改代码提高元素空间数解决。
性能:
因为预计使用量不大,所以没有做太仔细的优化。简单的测试结果如下 单线程连续请求: 产生约 1400W ID 99% 的请求延迟低于 1ms。 使用 wrk2 进行 5 线程, 10 连接, 1000 QPS 测试: 99% 请求延迟低于 100ms,99.9% 请求延时低于 380ms。 使用 wrk2 进行 6 线程, 40 连接, 80 QPS 测试: 99% 请求延迟低于 6ms, 99.9% 请求延时低于 9ms。 以上测试均在 2014 款 MacBook Pro 15 上进行。
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrKeyExist = errors.New("this key exist") ErrTooManyRetry = errors.New("too many retry") ErrBadValue = errors.New(`id or num cannot be "" or 0`) )
Errors
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.