Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hwholiday/gid
Golang 分布式ID生成系统,高性能、高可用、易扩展的id生成服务
https://github.com/hwholiday/gid
distributed golang id
Last synced: about 2 months ago
JSON representation
Golang 分布式ID生成系统,高性能、高可用、易扩展的id生成服务
- Host: GitHub
- URL: https://github.com/hwholiday/gid
- Owner: hwholiday
- License: apache-2.0
- Created: 2020-06-09T10:18:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-02T09:19:10.000Z (almost 4 years ago)
- Last Synced: 2024-10-12T04:07:58.536Z (2 months ago)
- Topics: distributed, golang, id
- Language: Go
- Homepage:
- Size: 92.8 KB
- Stars: 62
- Watchers: 6
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-hacking-lists - hwholiday/gid - Golang 分布式ID生成系统,高性能、高可用、易扩展的id生成服务 (Go)
README
# 简介
# [推荐使用V2版本](https://github.com/hwholiday/gid/tree/gidV2)gid 是使用golang开发的生成分布式Id系统,基于数据库号段算法实现
###### HTTP,GRPC 对外服务
### 性能
- id 从内存生成,如果(step)步长设置的足够大,qps可达到千万+
### 可用性
- id 分配依赖mysql ,当mysql不可用的,如果内存上还有的可以继续分配
### 特性
1. 全局唯一的int64型id
2. 分配ID只访问内存
3. 可无限横向扩展
4. 依赖mysql恢复服务迅速
......
### 安装
- 初始化 mysql```base
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);
```
- 编译运行项目
```base
git clone https://github.com/hwholiday/gid.git
cd gid/cmd
go build -o gidsrv
./gidsrv -conf ./gid.toml
```
#### 压测
```base
BenchmarkService_GetId-4 2046296 583 ns/op
```
#### 健康检查
- curl http://127.0.0.1:8080/ping#### 获取ID
- test6 获取该 tag 类型的 id
- curl http://127.0.0.1:8080/id/test6#### 获取雪花算法生成的ID
- curl http://127.0.0.1:8080/rand/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
```base
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生成系统](https://tech.meituan.com/2017/04/21/mt-leaf.html)