GithubHelp home page GithubHelp logo

hwholiday / gid Goto Github PK

View Code? Open in Web Editor NEW
62.0 6.0 14.0 95 KB

Golang 分布式ID生成系统,高性能、高可用、易扩展的id生成服务

License: Apache License 2.0

Go 99.85% Shell 0.15%
id distributed golang

gid's Introduction

简介

gid 是使用golang开发的生成分布式Id系统,基于数据库号段算法实现

HTTP,GRPC 对外服务

性能

  • id 从内存生成,如果(step)步长设置的足够大,qps可达到千万+

可用性

  • id 分配依赖mysql ,当mysql不可用的,如果内存上还有的可以继续分配

特性

  1. 全局唯一的int64型id
  2. 分配ID只访问内存
  3. 可无限横向扩展
  4. 依赖mysql恢复服务迅速
    ......

安装

  • 初始化 mysql
create database gid;
use gid;
create table segments
(
    biz_tag     varchar(128) not null,
    max_id      bigint       null,
    step        int          null,
    remark      varchar(200) null,
    create_time bigint       null,
    update_time bigint       null,
    constraint segments_pk
        primary key (biz_tag)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;

INSERT INTO segments(`biz_tag`, `max_id`, `step`, `remark`, `create_time`, `update_time`)
VALUES ('test', 0, 100000, 'test', 1591706686, 1591706686);
  • 编译运行项目
    git clone https://github.com/hwholiday/gid.git
    cd gid/cmd
    go build -o gidsrv
   ./gidsrv -conf ./gid.toml

压测

BenchmarkService_GetId-4         2046296               583 ns/op 

健康检查

获取ID

获取雪花算法生成的ID

创建 tag

  • biz_tag tag 名称
  • max_id 从这里开始派发ID
  • step 步长
  • remark 备注
  • {"biz_tag":"test6","max_id":0,"step":10,"remark":"test6 tag"}
  • curl -H "Content-Type:application/json" -X POST --data '{"biz_tag":"test6","max_id":0,"step":10,"remark":"test6 tag"}' http://127.0.0.1:8080/tag

重点SQL

Begin
UPDATE table SET max_id=max_id+step WHERE biz_tag=xxx
SELECT tag, max_id, step FROM table WHERE biz_tag=xxx
Commit

文献

美团点评分布式ID生成系统

gid's People

Contributors

hwholiday 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gid's Issues

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.