A high available global sequence generator for distributed system.
Cantor is a global sequence generator service, which is distributed, stateless and high available.
Cantor generates unique, relatively orderly and inverse decodable 64-bit integer IDs.
This project provides a easy way to use it in your docker environment. In fact, you can only use a few commands to start up all the components the service depends on and the tools, such like monitors and load testing.
This project contains several components:
Protocol of ID
1 bit | 2 bit | 2 bit | 7 bit | 3 bit | 28 bit | 21 bit |
---|---|---|---|---|---|---|
Sign bit as 0, never used | Protocol version, supporting 4 versions most | Generation sources descriptor, 4 in most | Custom spaces, 128 spaces most | Cantor service instance number, supporting 4 instances online most | Timestamp, which can be used in 8 years from 2018-01-01 00:00:00 | Sequence, about 13k ids generated per seconds |
In short, Cantor service guarantees that all unique IDs are generated based on its logic clock and a persistent sequence consuming state. When persistence service is down, Cantor service can downgrade to generate ID in local.
All components are dockerized and we can starts up all the components by docker-compose
.
Deployment demonstration:
$ cd $PROJECT_ROOT
$ mvn clean install -N && cd http && mvn clean install && cd ../service && mvn clean package
$ cd $PROJECT_ROOT
$ docker-compose build
$ docker stack deploy -c docker-compose.yml cantor
Service RESTful API:
API | HTTP Method | Parameters | Request example | Return |
---|---|---|---|---|
/id |
GET | cate: Custom category, range: How many IDs do you want return in a batch | http://localhost:8080/id?cate=0&range=100 |
{"start": "18446744073709551616", "range":"100"} |
/info |
GET | id: The ID to decode | http://127.0.0.1:8080/info?id=36313111556915201 |
{"sequence": 1,"descriptor": 1,"category": 2,"timestamp": 21664133} |
A Java SDK to improve the productivity of interacting with Cantor service.
Monitoring by jmxtrans & influxdb & grafana
http://localhost:3000
grafana.json
in grafanaUses apache-jmeter as performance test client. Jmeter version: apache-jmeter-4.0
.
Script
Start Jmeter
docker exec -it <CONTAINER> /jmeter/apache-jmeter-4.0/bin/jmeter -n -t <Script>
Jmeter result
docker exec -it <CONTAINER> sort r.csv | uniq -c | awk '{print $1}'|sort|uniq -c