• Stars
    star
    6,340
  • Rank 6,136 (Top 0.2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

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

Repository Details

Distributed ID Generate Service

Leaf

There are no two identical leaves in the world.

​ — Leibnitz

中文文档 | English Document

Introduction

Leaf refers to some common ID generation schemes in the industry, including redis, UUID, snowflake, etc. Each of the above approaches has its own problems, so we decided to implement a set of distributed ID generation services to meet the requirements. At present, Leaf covers Meituan review company's internal finance, catering, takeaway, hotel travel, cat's eye movie and many other business lines. On the basis of 4C8G VM, through the company RPC method, QPS pressure test results are nearly 5w/s, TP999 1ms.

You can use it to encapsulate a distributed unique id distribution center in a service-oriented SOA architecture as the id distribution provider for all applications

Quick Start

Leaf Server

Leaf provides an HTTP service based on spring boot to get the id

run Leaf Server

build
git clone [email protected]:Meituan-Dianping/Leaf.git
cd leaf
mvn clean install -DskipTests
cd leaf-server
run
maven
mvn spring-boot:run

or

shell command
sh deploy/run.sh
test
#segment
curl http://localhost:8080/api/segment/get/leaf-segment-test
#snowflake
curl http://localhost:8080/api/snowflake/get/test

Configuration

Leaf provides two ways to generate ids (segment mode and snowflake mode), which you can turn on at the same time or specify one way to turn on (both are off by default).

Leaf Server configuration is in the leaf-server/src/main/resources/leaf.properties

configuration meaning default
leaf.name leaf service name
leaf.segment.enable whether segment mode is enabled false
leaf.jdbc.url mysql url
leaf.jdbc.username mysql username
leaf.jdbc.password mysql password
leaf.snowflake.enable whether snowflake mode is enabled false
leaf.snowflake.zk.address zk address under snowflake mode
leaf.snowflake.port service registration port under snowflake mode

Segment mode

In order to use segment mode, you need to create DB table first, and configure leaf.jdbc.url, leaf.jdbc.username, leaf.jdbc.password

If you do not want use it, just configure leaf.segment.enable=false to disable it.

CREATE DATABASE leaf
CREATE TABLE `leaf_alloc` (
  `biz_tag` varchar(128)  NOT NULL DEFAULT '', -- your biz unique name
  `max_id` bigint(20) NOT NULL DEFAULT '1',
  `step` int(11) NOT NULL,
  `description` varchar(256)  DEFAULT NULL,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`biz_tag`)
) ENGINE=InnoDB;

insert into leaf_alloc(biz_tag, max_id, step, description) values('leaf-segment-test', 1, 2000, 'Test leaf Segment Mode Get Id')

Snowflake mode

The algorithm is taken from twitter's open-source snowflake algorithm.

If you do not want to use it, just configure leaf.snowflake.enable=false to disable it.

Configure the zookeeper address

leaf.snowflake.zk.address=${address}
leaf.snowflake.enable=true
leaf.snowflake.port=${port}

configure leaf.snowflake.zk.address in the leaf.properties, and configure the leaf service listen port leaf.snowflake.port.

monitor page

segment mode: http://localhost:8080/cache

Leaf Core

Of course, in order to pursue higher performance, you need to deploy the Leaf service through RPC Server, which only needs to introduce the leaf-core package and encapsulate the API that generates the ID into the specified RPC framework.

Attention

Note that leaf's current IP acquisition logic in the case of snowflake mode takes the first network card IP directly (especially for services that change IP) to avoid wasting the workId

More Repositories

1

mpvue

基于 Vue.js 的小程序开发框架,从底层支持 Vue.js 语法和构建工具体系。
JavaScript
20,415
star
2

walle

Android Signature V2 Scheme签名下的新一代渠道包打包神器
Java
6,735
star
3

Logan

Logan is a lightweight case logging system based on mobile platform.
C
5,652
star
4

SQLAdvisor

输入SQL,输出索引优化建议
C
5,490
star
5

Robust

Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.
Java
4,399
star
6

Zebra

美团点评集团统一使用的MySQL数据库访问层的中间件。主要提供对业务开发透明、读写分库、分库分表能力,并提供了端到端SQL监控的集成方案。
Java
2,730
star
7

DBProxy

C
2,226
star
8

beeshell

React Native 组件库
TypeScript
1,796
star
9

lyrebird

移动应用插件化测试工作台
Python
1,139
star
10

MyFlash

flashback mysql data to any point
C
1,102
star
11

Shield

A declarative, efficient, and flexible Native framework for building user interfaces.
Java
938
star
12

octo-rpc

OCTO-RPC 是支持Java和C++的企业级通信框架,在RPC服务之上扩展了丰富的服务治理功能,为美团各业务线提供高效、统一的通信服务。
Java
638
star
13

koa-restql

Build real RESTful APIs without writing one line of code.
JavaScript
447
star
14

octo-ns

OCTO-NS是美团OCTO服务治理体系服务注册发现功能的套件, 包括SDK(Java/C++)、本地服务治理代理(SgAgent), 服务缓存(NSC), 云端健康检查(Scanner)等基础组件,目前已经在全公司大规模使用
C++
326
star
15

asap

ASAP: A Chinese Review Dataset Towards Aspect Category Sentiment Analysis and Rating Prediction
312
star
16

vision-ui

视觉UI分析工具
Python
201
star
17

octo-portal

OCTO-Portal 是OCTO服务治理体系的管理端,为服务权重修改,性能数据分析等服务治理功能提供人性化的一站式管理平台
JavaScript
172
star
18

lyrebird-android

本程序是一个Lyrebird的插件,用于支持获取Android设备信息。
Python
121
star
19

lyrebird-ios

本程序是Lyrebird插件,您可以在插件中快速查看已连接iOS设备的详细设备信息,截取屏幕快照,以及查看已连接设备的应用信息。
Python
68
star
20

vision-ml

A R-CNN machine learning model for handling Pop-up window in mobile Apps.
Python
66
star
21

cat-go

Go
50
star
22

lyrebird-tracking

Tracking 是基于Lyrebird的插件,提供服务请求的数据分析及验证的功能
Python
24
star
23

lyrebird-api-coverage

API-Coverage是基于Lyrebird的插件,为客户端提供API维度测试覆盖评估方法。
Python
23
star
24

mos-mss

mtyun MSS(Meituan Storage Service) sdk for Node.js
JavaScript
19
star
25

lyrebird-java-client

lyrebird-java-client 是Lyrebird的一个 Java SDK,通过调用Lyrebird本身提供的API实现在Java项目中控制 Lyrebird Services
Java
15
star
26

lyrebird-bugit

lyrebird-bugit是Lyrebird的一个插件,目前应用于提交Bug场景
Vue
14
star
27

cat-python

Python
6
star
28

cat-node-js

CMake
5
star
29

cat-c-client

C
1
star
30

groupmeal-java-sdk

Java
1
star