Meituan-Dianping / Leaf

Licence: apache-2.0
Distributed ID Generate Service

Programming Languages

java
68154 projects - #9 most used programming language
FreeMarker
481 projects

Projects that are alternatives of or similar to Leaf

Leaf
A game server framework in Go (golang)
Stars: ✭ 4,250 (-16.34%)
Mutual labels:  leaf
geoip
🌚 🌍 🌝 GeoIP 规则文件加强版,同时支持定制 V2Ray dat 格式路由规则文件 geoip.dat 和 MaxMind mmdb 格式文件 Country.mmdb。Enhanced edition of GeoIP files for V2Ray, Xray-core, Trojan-Go, Clash and Leaf, with replaced CN IPv4 CIDR available from ipip.net, appended CIDR lists and more.
Stars: ✭ 524 (-89.69%)
Mutual labels:  leaf
nissan-connect-php
Use the Nissan Connect (was Carwings) API using a simple PHP class.
Stars: ✭ 29 (-99.43%)
Mutual labels:  leaf
leafMVC
MVC "Framework" created from Leaf PHP Framework
Stars: ✭ 25 (-99.51%)
Mutual labels:  leaf
carwings
Go package and CLI tool for the Nissan Leaf Carwings API
Stars: ✭ 23 (-99.55%)
Mutual labels:  leaf
Butterfly
分布式ID生成器框架:超高性能的发号器框架。通过引入多种新的方案,彻底解决雪花算法的时间回拨等问题,并将雪花算法原生QPS提高最少十几~二十倍
Stars: ✭ 111 (-97.81%)
Mutual labels:  leaf
typecho-theme-leaf
一款简洁又大气的typecho主题。演示站点
Stars: ✭ 62 (-98.78%)
Mutual labels:  leaf
PHP-Frameworks-Bench
Popular PHP Frameworks Benchmark.
Stars: ✭ 28 (-99.45%)
Mutual labels:  leaf
Vapecord-ACNL-Plugin
Animal Crossing NL Vapecord Public Plugin WIP
Stars: ✭ 72 (-98.58%)
Mutual labels:  leaf
Doramon
个人工具汇总:一致性哈希工具,Bitmap工具,布隆过滤器参数生成器,Yaml和properties互转工具,一键式生成整个前后端工具,单机高性能幂等工具,zookeeper客户端工具,分布式全局id生成器,时间转换工具,Http封装工具
Stars: ✭ 53 (-98.96%)
Mutual labels:  distributed-id-generator
xcode-leaf-color-schemer
https://ashokgelal.com/2017/01/19/leaf_color_schemer_xcode/?ref=github
Stars: ✭ 26 (-99.49%)
Mutual labels:  leaf

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].