A distributed id infrastructure service based on the Snowflake
402
一个基于雪花改进型分布式id基础服务

请求路径:GET http://{url}:{port}/web/uuid/get
入参说明:
| 字段 | 字段名 | 说明 |
|---|---|---|
| url | 对外暴露的ip或者域名 | 本地启动一般为127.0.0.1或者localhost |
| port | 对外暴露的端口信息 | |
| /web/uuid/get | 获取唯一id的请求路径 |
{
"code":"0",
"msg":"1",
"data":15969077833633829
}
反参说明:
| 字段 | 字段名 | 类型 | 意义 |
|---|---|---|---|
| code | 标识码 | string | 0表示反参正常 |
| msg | 运行节点的workId | string | 这个id是由那个工作容器节点产生 |
| data | 全局唯一的id(长整型) | integer 64 | 全局唯一的id |
java -jar app.jar
备注:使用jdk21
测试:直接在浏览器请求 http://127.0.0.1:8080/web/uuid/get
docker.io镜像
# jvm模式运行
docker run -it -d -p 8080:8080 activeclub/uid-service:v1.0.0-jvm-2023-11-12
# native模式运行
docker run -it -d -p 8080:8080 activeclub/uid-service:v1.0.0-native-2023-11-12
阿里云mirror镜像:
# jvm模式运行
docker run -it -d -p 8080:8080 registry.cn-shanghai.aliyuncs.com/activeclub/uid-service:v1.0.0-jvm-2023-11-12
# native模式运行
docker run -it -d -p 8080:8080 registry.cn-shanghai.aliyuncs.com/activeclub/uid-service:v1.0.0-native-2023-11-12
测试:直接在浏览器请求 http://127.0.0.1:8080/web/uuid/get
Stateful.yaml部署
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: uid-service
spec:
serviceName: uid-service
replicas: 3
selector:
matchLabels:
app: uid-service
template:
metadata:
labels:
app: uid-service
spec:
containers:
- name: uidserver
imagePullPolicy: IfNotPresent
image: activeclub/uid-service:v1.0.0-native-2023-11-12
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: uid-service
spec:
selector:
app: uid-service
ports:
- name: uid-port
port: 8080
targetPort: 8080
protocol: TCP
备注:
1,修改replicas,可以调整节点个数
2,设置健康检查,确保服务的可用性与自愈性

| 类别 | JVM | Native |
|---|---|---|
| 启动耗时(s) | 2.549 | 0.090 |
| 资源包压缩后大小(MB) | 269.68 | 55.38 |
| 资源包大小(MB) | 601.62 | 160.72 |
| 前1s,并发性能(QPS) | 8441.0 | 11577.4 |
| 运行30s后,并发性能(QPS) | 15692.1 | 15240.0 |
测试请求并发线程数:16
资源包压缩后大小(MB):

资源包大小(MB):

时间回溯
自增性
Content type
Image
Digest
sha256:273bbada3…
Size
269.7 MB
Last updated
over 2 years ago
docker pull activeclub/uid-service