• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    Go
  • Created about 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Golang+Mysql实现的分布式ID发号器

go-id-alloc

Golang+Mysql实现的分布式ID生成服务

特性

  • 高性能:分配ID只访问内存
  • 分布式:横向扩展,理论无上限
  • 高可靠:Mysql持久化,故障恢复快
  • 唯一性:生成64位整形,整体递增,永不重复
  • 易用性:可自定义ID起始位置,对外HTTP服务
  • 可运维性:提供健康检查接口,通过负载均衡自动摘除故障节点

编译项目

  • 进入$GOPATH目录(至少包含src子目录),下载源码
go get -u github.com/owenliang/go-id-alloc
  • 安装mysql依赖
go get -u github.com/go-sql-driver/mysql
  • 进入目录
$GOPATH/src/github.com/owenliang/go-id-alloc
  • 编译项目
go build

初始化数据库

create database id_alloc_db;

use id_alloc_db;

CREATE TABLE `segments` (
 `biz_tag` varchar(32) NOT NULL,
 `max_id` bigint NOT NULL,
 `step` bigint NOT NULL,
 `description` varchar(1024) DEFAULT '' NOT NULL,
 `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 PRIMARY KEY (`biz_tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO segments(`biz_tag`, `max_id`, `step`, `description`) VALUES('test', 0, 100000, "test业务ID池");

启动程序

./go-id-alloc -config ./alloc.json

请求分配ID

http://localhost:8880/alloc?biz_tag=test

{"errno":0,"msg":"success","id":201}

健康检查

http://localhost:8880/health?biz_tag=test

{"errno":0,"msg":"success","left":2}

原理

核心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

设计参考

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

More Repositories

1

go-push

千万级go弹幕推送服务器
Go
1,025
star
2

php7-extension-explore

全网唯一PHP7扩展开发教程
C
425
star
3

qwen-vllm

通义千问VLLM推理部署DEMO
Python
417
star
4

k8s-client-go

K8S client-go用法大全
Go
381
star
5

php-fpm-code-analysis

php-fpm源码分析
178
star
6

go-websocket

演示一下golang的websocket
Go
176
star
7

go-raft

Go复现的Raft内存KV数据库(参考MIT 6.824)
Go
148
star
8

mit-6.824

MIT6.824作业 - 基于Raft的分布式KV存储
Go
132
star
9

pytorch-diffusion

pytorch复现stable diffusion
Python
112
star
10

agent

qwen ai agent
Python
102
star
11

bigpipe

以Kafka为存储介质,提供异步Http RPC的中间件
Go
90
star
12

Web-API-The-Good-Parts

《Web API的设计与开发》--知识点整理
87
star
13

rag-retrieval

RAG向量召回示例
Python
81
star
14

crontab

Go
78
star
15

task_schedule

(C++)基于图数据结构与拓扑序列的任务调度demo
C++
65
star
16

pytorch-transformer

pytorch复现transformer
Python
59
star
17

mnist-clip

a super easy clip model with mnist dataset for study
Python
59
star
18

aippt

generate ppt with llm
Python
57
star
19

qwen-sft

通义千问 SFT试验
Jupyter Notebook
51
star
20

redis-lua

使用Redis+lua实现秒杀业务的DEMO
PHP
47
star
21

myf-go

封装的go mvc企业级框架
Go
44
star
22

k8s-jumpserver

开源K8S跳板机(web console)
CSS
43
star
23

mnist-dits

Diffusion Transformers (DiTs) trained on MNIST dataset
Python
42
star
24

kafka

使用Pykafka的正确姿势
Python
32
star
25

chatgpt

simple decoder-only GTP model in pytorch
Python
28
star
26

simple_kit

C实现的服务端开发框架
C
28
star
27

side-by-side-diff

利用python的difflib,实现HTML的双视图diff
Python
26
star
28

react

JavaScript
25
star
29

pullToRefresh

javascript-pull-to-refresh
JavaScript
24
star
30

dht

一个DHT爬虫
Go
24
star
31

bpe-tokenizer

LLM Tokenizer with BPE algorithm
Python
24
star
32

another-pytorch

实现一个PyTorch框架
Python
23
star
33

introduction-to-machine-learning-with-python

学习笔记与代码(markdown格式)
23
star
34

composer-private-repository

composer私有仓库建设
23
star
35

FlappyBirdTensorflow

强化学习玩flappy bird
Python
21
star
36

mnist-onnx-runtime

MoE model with onnx runtime
Python
20
star
37

blockchain

Go
16
star
38

qwen-dpo

通义千问的DPO训练
Jupyter Notebook
16
star
39

mnist-vit

vision transformer on mnist dataset
Python
15
star
40

go-advanced

go的一些高级技巧
Go
14
star
41

vanna-chatbi

vanna.ai demo
Jupyter Notebook
14
star
42

elasticsearch-dsl-usage

使用elasticsearch-dsl库来更结构化的生成ES请求
PHP
13
star
43

NeuralNetwork

用python手写神经网络模型
Python
11
star
44

go-crontab

GO实现类似quartz的超轻量分布式crontab(已弃坑)
Go
11
star
45

go-orig-dst

golang获取原始目标IP
Go
11
star
46

nacos-forward-proxy

nacos http rpc反向代理
Go
11
star
47

zkclient

zookeeper sdk wrapper written in c++
C++
10
star
48

ItemCF-php

simple itemCF algorithm in php
PHP
9
star
49

js-toc

js实现table of content目录导航
HTML
9
star
50

go-share-reflect

关于go反射的分享
Go
9
star
51

flume-ng-round-robin-channel-selector

flume extension which enables multi channel dispatch
Java
9
star
52

myf-app

myf means 'my framework'
PHP
8
star
53

douban-comments-similarity

豆瓣影评数据集 word2vec+LSH相似评论分析
Python
8
star
54

learnpytorch

Jupyter Notebook
8
star
55

elasticsearch6-practise

elasticsearch 6.0+的一些demo
PHP
7
star
56

prepare

Go
7
star
57

go-queue

Reliable&persistent message queue based on Leveldb&Golang
Go
7
star
58

asyncio-threadpool-demo

fastapi异步IO+threadpool线程池的工作原理
Python
7
star
59

qcon2018

ppt crawler
Python
6
star
60

mysql-bulk-insert

测试mysql合并插入的吞吐
PHP
6
star
61

annotation

基于『JAVA反射+运行时注解』,实现一个URL路由器DEMO
Java
6
star
62

tf2-widedeep

Python
6
star
63

webpack-static-html

利用webpack编译静态多页网站
JavaScript
6
star
64

go-share-sync

分享用-go常用同步原语
Go
6
star
65

qwen-eval

通义千问的ceval打分评测示例
Python
6
star
66

myf-core

myf means 'my framework'
PHP
5
star
67

react-webpack2

SPA with react+react-router-v4+webpack2
JavaScript
5
star
68

kubernetes-deployment-tracer

deployment doctor for kubernetes
Python
5
star
69

TradeMatchEngine

股票交易撮合-原理demo
Jupyter Notebook
5
star
70

zipkin-php-demo

deep dive into zipkin
PHP
5
star
71

The-Pragmatic-Programmers

程序员思维修炼 -- 读书总结
5
star
72

modern-cpp

现代cplusplus的小探索哦~
C++
4
star
73

pyspark-demo

Shell
4
star
74

webpy-demo

从源码中来,到应用中去,靠谱的webpy用法
HTML
4
star
75

machine-learning

sklearn,spark ml,pmml的基础示例
Python
4
star
76

counting-stars-tx

LLM大海捞针
Jupyter Notebook
4
star
77

scrapy

my crawler
Python
3
star
78

pi-switch

树莓派GPIO开关
Python
3
star
79

tensorflow2-end-to-end

example for tensorflow2.0 production usage
Jupyter Notebook
3
star
80

tag-input

how to implment a tag input with html
HTML
3
star
81

go-structure-tag

Go
3
star
82

docker-multi-stage

基于docker的multi stage实现编译与运行容器分离
Dockerfile
3
star
83

go-etcd

调研etcd SDK用法
Go
3
star
84

boston-dataset

波士顿房价回归
Jupyter Notebook
3
star
85

search

Java
3
star
86

tf-graph-explore

tensorflow原理
Jupyter Notebook
2
star
87

numpy_pandas

Python
2
star
88

language-speed

C
2
star
89

go-middlewares

Go
2
star
90

pi-temp

树莓派智能温控风扇
Python
2
star
91

tf2-onspark

Python
2
star
92

jenkins_tools

jenkins打包基础镜像
2
star
93

zipkin-ui-demo

演示如何将zipkin存储的span数据输出到web ui上
JavaScript
2
star
94

bilibili-2020-01-31

python bilibili spider
Python
2
star
95

thanos-prometheus

分布式prometheus配置demo
2
star
96

mickey-sdk

cat catches mickey
PHP
1
star
97

beego-demo

beego调研
Smarty
1
star
98

v2ex-clone

仿了一下v2ex的WAP站首页,主要是学习设计配色
HTML
1
star
99

page-layout

PC端常见的后台布局示例
HTML
1
star
100

go-jsonrpc

一个golang jsonrpc的测试例子
Go
1
star