Giter VIP home page Giter VIP logo

yitter / idgenerator Goto Github PK

View Code? Open in Web Editor NEW
2.3K 29.0 331.0 7.71 MB

💎多语言实现,高性能生成唯一数字ID。 💎优化的雪花算法(SnowFlake)——雪花漂移算法,在缩短ID长度的同时,具备极高瞬时并发处理能力(50W/0.1s)。 💎原生支持 C#/Java/Go/Rust/C/JavaScript/TypeScript/Python/Pascal 多语言,提供其它适用于其它语言的多线程安全调用动态库(FFI)。💎支持容器环境自动扩容(自动注册 WorkerId ),单机或分布式唯一IdGenerator。💎顶尖优化,超强效能。

License: MIT License

C# 13.18% CMake 0.44% C 15.67% Go 10.18% Java 7.84% Rust 5.92% V 3.34% Batchfile 0.05% M4 1.02% JavaScript 4.08% PHP 1.37% Makefile 0.41% Shell 0.16% D 8.76% Verilog 0.40% TSQL 0.66% TypeScript 5.43% Python 4.28% Pascal 10.97% C++ 5.85%
snowflake idgenerator dotnet rust java go twritter-snowflake c-sharp unique-id typescript

idgenerator's People

Contributors

amuluowin avatar auroratea avatar bubao avatar cmz5268885 avatar fuzhufang avatar heromyth avatar hhk-png avatar l-fushen avatar lovebefort avatar lymslive avatar snyk-bot avatar varprob avatar yitter avatar zhupengfeivip avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

idgenerator's Issues

生成id重复

c# 版本,使用两个线程模拟 程序分布式部署后,生产的雪花id情况
每个线程间隔10 毫秒生成1000个id,会出现很高的重复id,请问参数要怎么配置才不会重复?

    private static Queue<(DateTime, long)> _queue = new Queue<(DateTime, long)>();
    private static int _count = 1000;

    static void Main(string[] args)
    {
        var workerId1 = 15;
        var workerId2 = 51;
        Task.Factory.StartNew(() =>
        {
            Run(1, (ushort)workerId1);
        });
        Task.Factory.StartNew(() =>
        {
            Run(1, (ushort)workerId2);
        });
        Task.Factory.StartNew(() =>
        {
            CheckId();
        });
        Console.ReadLine();
    }

    /// <summary>
    /// 运行生成id
    /// </summary>
    /// <param name="method"></param>
    /// <param name="workerId"></param>
    private static void Run(short method, ushort workerId)
    {
        var options = new IdGeneratorOptions()
        {
            Method = method,
            WorkerId = workerId,

            //WorkerIdBitLength = 9,
           // SeqBitLength = 8,
        };

        IIdGenerator idGen = new DefaultIdGenerator(options);
        int count = _count;
        //生成一定数量的id
        while (count > 0)
        {
            _queue.Enqueue((DateTime.Now, idGen.NewLong()));
            //间隔10毫秒
            Task.Delay(10).Wait();
            count--;
        }
    }

    private static void CheckId()
    {
        Console.WriteLine("check start");
        var i = 0;
        var dict = new Dictionary<long, DateTime>();
        int error = 0;
        while (dict.Count < _count)
        {
            while (_queue.TryDequeue(out var item))
            {
                i++;

                if (dict.ContainsKey(item.Item2))
                {
                    error += 1;
                    Console.WriteLine($"{item.Item2} - { item.Item1.ToString("HH:mm:ss fffff")} | {dict[item.Item2].ToString("HH:mm:ss fffff")}");
                }
                else
                {
                    dict.Add(item.Item2, item.Item1);
                }
            }

            Task.Delay(10).Wait();
        }


        Console.WriteLine($"check end:{error}");
    }

提出一些疑问

  1. 如果在不同服务器,部署相同应用,都是采用相同WorkId,会不会导致生成ID重复
  2. 如果我想通过一个中心服务统一分配WorkId,实现逻辑是怎样呢,麻烦大佬解答

IIS下,多个工作进程,ID重复该如何解决

1、此现象出现场景 :.NetCore 6.0 部署在IIS下,应用池设置多个工作进程
2、 代码:
初始化时配置了workID
// 配置雪花Id算法机器码
YitIdHelper.SetIdGenerator(new IdGeneratorOptions
{
SeqBitLength = 10,
WorkerId = 8 // 取值范围0~63,默认1
});

在大批量非多线程插入时,调用 YitIdHelper.NextId()出现重复

生成的雪花ID长度不一样

目前有一台服务器的程序生成的雪花ID是14位,workId是1,WorkerIdBitLength是1,SeqBitLength是6

这个图中是另一个程序,有可能会放到不同的服务器,如果我也想让他的长度为14位.那应该怎么改配置..我把workId改为2,然后WorkerIdBitLength改为多少?

image

golang workID type mismatch

RegisterOne return int32

func RegisterOne(ip string, port int32, password string, maxWorkerId int32) int32 

but IdGeneratorOptions need uint16

type IdGeneratorOptions struct {
	Method            uint16 // 雪花计算方法,(1-漂移算法|2-传统算法),默认1
	BaseTime          int64  // 基础时间(ms单位),不能超过当前系统时间
	WorkerId          uint16 // 机器码,必须由外部设定,最大值 2^WorkerIdBitLength-1
	WorkerIdBitLength byte   // 机器码位长,默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22)
	SeqBitLength      byte   // 序列数位长,默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22)
	MaxSeqNumber      uint32 // 最大序列数(含),设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1])
	MinSeqNumber      uint32 // 最小序列数(含),默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位
	TopOverCostCount  uint32 // 最大漂移次数(含),默认2000,推荐范围500-10000(与计算能力有关)
}

nodejs下的demo是否有错误?

image

如上图位置的_IsOverCost是不是应该是Method?

还有nodejs中的部分函数并没有实现,也没有注释,是否未完成?
image

如上图,

NextId有重复

作者你好, 我试了发现有ID重复的情况, 不知是哪里的写法有问题吗?
image

关于根据ID获取时间戳的问题

实例中,生成的id是 129053495681099 ,默认WorkerIdBitLength是6, SeqBitLength是6,那就是 129053495681099 右移12位,结果是 31,507,201,094, 这个不是时间戳吧?是我哪里理解错了吗?

ID 使用ORM 的 default 字段生成,在几十秒内生成的 ID 都一样?

model定义:

class Profile(models.Model): id = fields.BigIntField(pk=True, default=snowflake.next_id(seq_bit_length=7))

生成代码:

 from snowflake.source import options, generator, idregister
 from settings.constants import RedisConfig


def next_id(seq_bit_length=6):
    # 连接redis
    register = idregister.Register(host=RedisConfig().redis_product_list[0], port=RedisConfig().redis_product_list[1],
                                   password=RedisConfig().redis_product_list[2])
    # 获取worker id
    worker_id = register.get_worker_id()
    option = options.IdGeneratorOptions(worker_id=worker_id, seq_bit_length=seq_bit_length)
    # option.base_time = time.time()
    idgen = generator.DefaultIdGenerator()
    idgen.set_id_generator(option)
    uid = idgen.next_id()
    register.stop()
    return uid

重复:

{ "data": {}, "message": "duplicate key value violates unique constraint \"account_verifycode_pkey\"\nDETAIL: Key (id)=(1541283244287430) already exists.", "code": 0 }

50万个id为什么生成特别慢

var options = new IdGeneratorOptions(1);
YitIdHelper.SetIdGenerator(options);
Stopwatch sw = new Stopwatch();
for (int i = 0; i < 500000; i++)
{
    //ShardingFactory.NextSnowId(); //0.15秒
    //ShardingFactory.NextObjectId(); //0.2秒
    YitIdHelper.NextId(); //8秒多
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);

同样生成50万个id
1、雪花算法只要0.15秒
2、mongodb的objectid只需要0.2秒
3、作者你的id说是比传统雪花算法快2-5倍(可结果居然用了8秒多)
C#测试就是这个结果
作者请问你是不是哪里代码出错了,怎么会慢成这样

Go 导入问题

使用导入

go get -u -v github.com/yitter/idgenerator-go

提示

github.com/yitter/idgenerator-go imports
        github.com/yitter/idgenerator-go/regworkerid: cannot find module providing package github.com/yitter/idgenerator-go/regworkerid

Maybe better to upload to Pypi / npm?

目前的使用方式, 首先作为依赖管理起来不方便, 其次clone或者download一整个Git 仓库, 其中不是所需要的语言的代码占比太大了.


The way it is currently used, it is not easy to manage as a dependency, and people who use it have to clone or download a whole Git repository, which is too large for code in a language other than the one they need.

SqlServer雪花函數生成ID重複

我特意測試了下建立一个Test表,字段有ID,Val两个字段,根据教程把ID字段默认值设置了([dbo].Fn_NextSnowId)
然后我执行以下脚本发现总有几十个ID出现重复

declare @i int =10000

while @i>0
begin
INSERT INTO [dbo].[Test]([Val])
     VALUES
           ('123')
set @i=@i-1
end 

压测结果

我压测了一下,慢的有点离谱,不知道是不是代码问题,代码如下:

    public static void main(String[] args) {
        var count = 0;

        // mybatis-plus的雪花算法
        final var sequence = new Sequence();

        // yitter-idgenerator-spring-boot-starter
//        final var options = new IdGeneratorOptions();
//            options.TopOverCostCount = 500;
//            options.Method = 2;
//        final var id = new WFGIdGenerator(options);

        // yitter-idgenerator
        IdGeneratorOptions options = new IdGeneratorOptions((short)1);
            YitIdHelper.setIdGenerator(options);

        final var start = System.currentTimeMillis();
        while (count < 3000000) {
            count++;
//            id.next();
//            sequence.nextId();
            YitIdHelper.nextId();
        }
        System.out.println(System.currentTimeMillis() - start);
    }

只有mybatis-plus的雪花算法是最快的,400/s,其他的都要50s

单线程性能很慢

随机生成10个订单号,就需要5秒,同样的雪花算法,2.5秒生成100W个订单号。我也是按照ReadMe.txt里面写的代码,我很奇怪,为啥有这么大的性能差异。

id生成速度有问题

这是我写的Java代码,生成50w条id,用时8004毫秒,而生成10w条id,用时是8ms,请问这是什么情况

IdGeneratorOptions options = new IdGeneratorOptions((short) 1);
YitIdHelper.setIdGenerator(options);
long start = System.currentTimeMillis();
for (int i = 0; i < 500000; i++) {
    YitIdHelper.nextId();
}
long end = System.currentTimeMillis();
System.out.println(end - start); // 8004

分布式可否提升性能

go 版本

我想生成 id 位数短一点,经过测试当配置为 WorkerIdBitLength = 2 & SeqBitLength = 3 时,生成 3000 个需耗时 1ms,这能满足现在的需求了

问题:程序是在 pod 中独立运行的,(每个都通过 RegisterOne 注册全局唯一 workerid),当未来需要提高 id 生成速度时,可以通过增加 pod 数量实现吗?并且 id 不重复。比如需要 6000,就将 pod 数量扩容为 2,以此类推(在 WorkerIdBitLength 范围内 range:[0, 3])

第一次生成的id会有重复的

Parallel.For(0, 10, i =>
  {

      long a = YitIdHelper.NextId();
      lock (this)
      {
          File.AppendAllText("e:\\1.txt", a.ToString() + "\r\n");
      }
  });

以上代码第一次生成的ID 中有重复的,但是后续的没有
以下是我将以上代码执行两次的文本,可以看到在第一次中,有大量的重复,但是后续永远也不会出现重复

294807880151109
294807880155205
294807880155205
294807880155205
294807880155205
294807880155205
294807880155205
294807880155205
294807880155205
294807880155205

294807939739717
294807939739718
294807939739719
294807939739720
294807939739723
294807939739722
294807939739725
294807939739721
294807939739724
294807939739726

C 库没做 C++ 兼容

我是个 C++ 开发,老板推荐使用这个雪花算法。
一开始尝试提供的 C 库,一直链接不成功,后来发现是没写 extern "C" 兼容。
标准做法是加上类似如下的宏,使其能同时用于 C 或 C++

#ifdef __cplusplus
extern "C" 
{
#endif

// C 库函数 声明

#ifdef __cplusplus
}
#endif

另外一个小问题,你这个 C 库的函数接口命名太普通,像 NextId()SetOption() 之类的函数名太常见,很可能与实际项目其他全局符号冲突,毕竟这个 id 算法库的目的是要集成到某些较大的项目中的。建议不妨统一加上 yit 前缀。

单服务多线程下生成的Id重复

服务器配置:32C64G
线程数:10个
项目配置:

        IdGeneratorOptions options = new IdGeneratorOptions();
        options.WorkerIdBitLength = 6;
        options.SeqBitLength = 6;
        options.Method = method;
        options.WorkerId = 1;
        YitIdHelper.setIdGenerator(options);

在插入数据库的时候大批量提示Id重复
请问这个问题的原因是我的配置问题吗

PHP 扩展 phpize 后报 warning 错误

语言:PHP
操作系统:docker 镜像:php:7.4-fpm-alpine
问题:
➜ PHP git:(master) ✗ phpize
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
configure.ac:18: warning: $as_echo is obsolete; use AS_ECHO(["message"]) instead
build/php.m4:2110: PHP_CONFIG_NICE is expanded from...
configure.ac:18: the top level
configure.ac:161: warning: The macro AC_LANG_C' is obsolete. configure.ac:161: You should run autoupdate. ./lib/autoconf/c.m4:72: AC_LANG_C is expanded from... build/libtool.m4:2727: _LT_AC_LANG_C_CONFIG is expanded from... build/libtool.m4:2726: AC_LIBTOOL_LANG_C_CONFIG is expanded from... build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from... build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from... build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from... configure.ac:161: the top level configure.ac:161: warning: The macro AC_LANG_C' is obsolete.
configure.ac:161: You should run autoupdate.
./lib/autoconf/c.m4:72: AC_LANG_C is expanded from...
lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from...
./lib/autoconf/general.m4:2270: AC_CACHE_CHECK is expanded from...
build/libtool.m4:561: _LT_AC_LOCK is expanded from...
build/libtool.m4:1184: AC_LIBTOOL_SYS_HARD_LINK_LOCKS is expanded from...
build/libtool.m4:2727: _LT_AC_LANG_C_CONFIG is expanded from...
build/libtool.m4:2726: AC_LIBTOOL_LANG_C_CONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: The macro AC_TRY_LINK' is obsolete. configure.ac:161: You should run autoupdate. ./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from... lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from... lib/m4sugar/m4sh.m4:699: AS_IF is expanded from... ./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from... ./lib/autoconf/general.m4:2270: AC_CACHE_CHECK is expanded from... build/libtool.m4:561: _LT_AC_LOCK is expanded from... build/libtool.m4:1184: AC_LIBTOOL_SYS_HARD_LINK_LOCKS is expanded from... build/libtool.m4:2727: _LT_AC_LANG_C_CONFIG is expanded from... build/libtool.m4:2726: AC_LIBTOOL_LANG_C_CONFIG is expanded from... build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from... build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from... build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from... configure.ac:161: the top level configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me:${as_lineno-$LINENO}: WARNING: \$CC' does not support `-c -o', so `make -j' may be unsafe
build/libtool.m4:1184: AC_LIBTOOL_SYS_HARD_LINK_LOCKS is expanded from...
build/libtool.m4:2727: _LT_AC_LANG_C_CONFIG is expanded from...
build/libtool.m4:2726: AC_LIBTOOL_LANG_C_CONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me: WARNING: `$CC' does not support `-c -o', so `make -j' may be unsafe
build/libtool.m4:1184: AC_LIBTOOL_SYS_HARD_LINK_LOCKS is expanded from...
build/libtool.m4:2727: _LT_AC_LANG_C_CONFIG is expanded from...
build/libtool.m4:2726: AC_LIBTOOL_LANG_C_CONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me:${as_lineno-$LINENO}: WARNING: output file `$ofile' does not exist
build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me: WARNING: output file `$ofile' does not exist
build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me:${as_lineno-$LINENO}: WARNING: output file `$ofile' does not look like a libtool script
build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me: WARNING: output file `$ofile' does not look like a libtool script
build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me:${as_lineno-$LINENO}: WARNING: using `LTCC=$LTCC', extracted from `$ofile'
build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me: WARNING: using `LTCC=$LTCC', extracted from `$ofile'
build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: back quotes and double quotes must not be escaped in: tag name "$tagname" already exists
build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: The macro AC_LANG_CPLUSPLUS' is obsolete. configure.ac:161: You should run autoupdate. ./lib/autoconf/c.m4:262: AC_LANG_CPLUSPLUS is expanded from... build/libtool.m4:2809: _LT_AC_LANG_CXX_CONFIG is expanded from... build/libtool.m4:2808: AC_LIBTOOL_LANG_CXX_CONFIG is expanded from... build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from... build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from... build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from... build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from... configure.ac:161: the top level configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me:${as_lineno-$LINENO}: WARNING: \$CC' does not support `-c -o', so `make -j' may be unsafe
build/libtool.m4:1184: AC_LIBTOOL_SYS_HARD_LINK_LOCKS is expanded from...
build/libtool.m4:2809: _LT_AC_LANG_CXX_CONFIG is expanded from...
build/libtool.m4:2808: AC_LIBTOOL_LANG_CXX_CONFIG is expanded from...
build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: back quotes and double quotes must not be escaped in: $as_me: WARNING: `$CC' does not support `-c -o', so `make -j' may be unsafe
build/libtool.m4:1184: AC_LIBTOOL_SYS_HARD_LINK_LOCKS is expanded from...
build/libtool.m4:2809: _LT_AC_LANG_CXX_CONFIG is expanded from...
build/libtool.m4:2808: AC_LIBTOOL_LANG_CXX_CONFIG is expanded from...
build/libtool.m4:1917: _LT_AC_TAGCONFIG is expanded from...
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level

Go/regworkerid/regworkerid/reghelper.go 无法连接哨兵模式的redis

在连接哨兵模式的redis时
func newRedisClient() redis.UniversalClient {
client := redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: strings.Split(_RedisConnString, ","),
Password: _RedisPassword,
DB: _RedisDB,
MasterName: _RedisMasterName,
//PoolSize: 1000,
//ReadTimeout: time.Millisecond * time.Duration(100),
//WriteTimeout: time.Millisecond * time.Duration(100),
//IdleTimeout: time.Second * time.Duration(60),
})
return client
}
应该要使用SentinelPassword与SentinelUsername

单核跑极限是怎么限制的,我只能跑10w/s

step := 200000
fmt.Println("start")
t := utils.LocalMilliscond()
for i := 0; i < step; i++ {
idgen.NextId()
}
fmt.Printf("check total cost %d ms\n", utils.LocalMilliscond()-t)
check total cost 2013 ms

当step设置成100000的时候,耗时是22ms,但是设置200000的时候,耗时就需要2013ms

自动注册WorkerId疑问?

按照您提供的自动注册思路,我自己在项目中实现了自动注册WorkerId,数值范围为[1,65535],当应用程序启动时会根据此范围产生一个随机数,写入到redis(采用了lua脚本来写入保证原子性),如果已存在会一直尝试创建新的随机数继续写入直到写入成功,程序关闭清除相关key,如果新启动的应用程序随机到了以前生成的随机数值,那么这个时候会不会产生已经生成过的雪花id呢?感觉我这个疑问很滑稽.. 只要时间没有回拨,应该不会重复吧.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.