All Projects → izern → sequence

izern / sequence

Licence: Apache-2.0 license
高效GUID产生算法(sequence),基于Snowflake实现64位自增ID算法.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to sequence

MiniDao
An powerful enhanced toolkit of SpringJdbc for simplify development
Stars: ✭ 200 (+471.43%)
Mutual labels:  hibernate
vscode-commands
Run commands from Tree View / Status Bar / Quick Pick.
Stars: ✭ 45 (+28.57%)
Mutual labels:  sequence
spring-data-jpa-mongodb-expressions
Use the MongoDB query language to query your relational database, typically from frontend.
Stars: ✭ 86 (+145.71%)
Mutual labels:  hibernate
react-sequence-animator
A React library for sequence animations
Stars: ✭ 23 (-34.29%)
Mutual labels:  sequence
jeecg
JEECG是一款基于代码生成器的J2EE快速开发平台,开源界“小普元”超越传统商业企业级开发平台。引领新的开发模式(Online Coding模式(自定义表单) - > 代码生成器模式 - > 手工MERGE智能开发), 可以帮助解决Java项目90%的重复工作,让开发更多关注业务逻辑。既能快速提高开发效率,帮助公司节省人力成本,同时又不失灵活性。具备:表单配置能力(无需编码)、移动配置能力、工作流配置能力、报表配置能力(支持移动端)、插件开发能力(可插拔)
Stars: ✭ 2,090 (+5871.43%)
Mutual labels:  hibernate
bio
A lightweight and high-performance bioinformatics package in Golang
Stars: ✭ 80 (+128.57%)
Mutual labels:  sequence
Quickperf
QuickPerf is a testing library for Java to quickly evaluate and improve some performance-related properties
Stars: ✭ 231 (+560%)
Mutual labels:  hibernate
springmvc
spring mvc study
Stars: ✭ 87 (+148.57%)
Mutual labels:  hibernate
E-commerce-
Spring + Hibernate
Stars: ✭ 32 (-8.57%)
Mutual labels:  hibernate
SKAT
Sequence kernel association test (SKAT)
Stars: ✭ 24 (-31.43%)
Mutual labels:  sequence
genome updater
Bash script to download/update snapshots of files from NCBI genomes repository (refseq/genbank) with track of changes and without redundancy
Stars: ✭ 93 (+165.71%)
Mutual labels:  sequence
phoenix-hibernate-dialect
An Apache Phoenix Hibernate dialect
Stars: ✭ 20 (-42.86%)
Mutual labels:  hibernate
paxoid
Paxos based masterless ID/Sequence generator.
Stars: ✭ 20 (-42.86%)
Mutual labels:  sequence
doc
QuickPerf documentation: https://github.com/quick-perf/doc/wiki/QuickPerf
Stars: ✭ 22 (-37.14%)
Mutual labels:  hibernate
random-jpa
Create random test data for JPA/Hibernate entities.
Stars: ✭ 23 (-34.29%)
Mutual labels:  hibernate
Spring Framework Petclinic
A Spring Framework application based on JSP, Spring MVC, Spring Data JPA, Hibernate and JDBC
Stars: ✭ 251 (+617.14%)
Mutual labels:  hibernate
Library-Spring
The library web application where you can borrow books. It's Spring MVC and Hibernate project.
Stars: ✭ 73 (+108.57%)
Mutual labels:  hibernate
Diber-backend
Delivery Service - Spring Boot / Spring Data Jpa / Hibernate / PostgreSQL / OAuth2 Application
Stars: ✭ 22 (-37.14%)
Mutual labels:  hibernate
springboot-rest-api-angularjs-https
REST API https with Spring Boot and Angular JS. Use MySQL, Hibernate and Spring Security.
Stars: ✭ 38 (+8.57%)
Mutual labels:  hibernate
langx-java
Java tools, helper, common utilities. A replacement of guava, apache-commons, hutool
Stars: ✭ 50 (+42.86%)
Mutual labels:  idgenerator

分布式高效唯一ID生成器(sequence)

基于开源项目sequence

简介

高效GUID产生算法(sequence),基于Snowflake实现64位自增ID算法。

Twitter-Snowflake算法产生的背景相当简单,为了满足Twitter每秒上万条消息的请求,每条消息都必须分配一条唯一的id,这些id还需要一些大致的顺序(方便客户端排序),并且在分布式系统中不同机器产生的id必须不同。

性能测试数据:

性能测试结果

Snowflake算法核心

把时间戳,工作机器id,序列号组合在一起。

Snowflake算法核心

除了最高位bit标记为不可用以外,其余三组bit占位均可浮动,看具体的业务需求而定。默认情况下41bit的时间戳可以支持该算法使用到2082年,10bit的工作机器id可以支持1023台机器,序列号支持1毫秒产生4095个自增序列id。下文会具体分析。

Snowflake – 时间戳

这里时间戳的细度是毫秒级,具体代码如下,建议使用64位linux系统机器,因为有vdso,gettimeofday()在用户态就可以完成操作,减少了进入内核态的损耗。

Snowflake – 工作机器id

严格意义上来说这个bit段的使用可以是进程级,机器级的话你可以使用MAC地址来唯一标示工作机器,工作进程级可以使用IP+Path来区分工作进程。如果工作机器比较少,可以使用配置文件来设置这个id是一个不错的选择,如果机器过多配置文件的维护是一个灾难性的事情。

Snowflake – 序列号

序列号就是一系列的自增id(多线程建议使用atomic),为了处理在同一毫秒内需要给多条消息分配id,若同一毫秒把序列号用完了,则“等待至下一毫秒”。

获取

<dependency>
	<groupId>cn.izern</groupId>
	<artifactId>sequence</artifactId>
	<version>${version}</version>
</dependency>

使用

import cn.izern.sequence.Sequence;

Sequence sequence = new Sequence();
sequence.nextId();

线程安全,生成唯一序列ID

hibernate/jpa 使用Sequence作为ID生成方式

private Long id;
	
// other 

@Id
@GeneratedValue(generator = "idGenerator")
@GenericGenerator(name = "idGenerator", strategy = "cn.izern.hibernate.id.IDSequenceGenerator")
public Long getId() {
	return id;
}

public void setId(Long id) {
	this.id = id;
}
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].