{"id":14973031,"url":"https://github.com/ahoo-wang/cosid","last_synced_at":"2025-05-15T01:04:31.146Z","repository":{"id":37083387,"uuid":"379480417","full_name":"Ahoo-Wang/CosId","owner":"Ahoo-Wang","description":"Universal, flexible, high-performance distributed ID generator.                              | 通用、灵活、高性能的分布式 ID 生成器","archived":false,"fork":false,"pushed_at":"2025-03-25T22:16:36.000Z","size":10694,"stargazers_count":531,"open_issues_count":8,"forks_count":79,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-06T18:12:35.873Z","etag":null,"topics":["clock","clock-synchronization","cloud-native","distributed","generator","gradle","id","id-generator","idgenerator","java","k8s","kubernetes","microservice","redis","sharding","snowflake","spring","spring-boot","spring-cloud","zookeeper"],"latest_commit_sha":null,"homepage":"https://cosid.ahoo.me","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ahoo-Wang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-23T04:40:29.000Z","updated_at":"2025-04-03T09:44:07.000Z","dependencies_parsed_at":"2023-09-21T18:33:40.104Z","dependency_job_id":"7d6541d7-eb73-4a43-b675-b3819a486fb8","html_url":"https://github.com/Ahoo-Wang/CosId","commit_stats":{"total_commits":1060,"total_committers":12,"mean_commits":88.33333333333333,"dds":0.439622641509434,"last_synced_commit":"3694286b3f9c95a4dfcf2367e0d438a68b7b4f54"},"previous_names":[],"tags_count":147,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2FCosId","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2FCosId/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2FCosId/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2FCosId/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ahoo-Wang","download_url":"https://codeload.github.com/Ahoo-Wang/CosId/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248785421,"owners_count":21161283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clock","clock-synchronization","cloud-native","distributed","generator","gradle","id","id-generator","idgenerator","java","k8s","kubernetes","microservice","redis","sharding","snowflake","spring","spring-boot","spring-cloud","zookeeper"],"created_at":"2024-09-24T13:47:59.014Z","updated_at":"2025-05-15T01:04:31.135Z","avatar_url":"https://github.com/Ahoo-Wang.png","language":"Java","readme":"\u003cp align=\"center\" style=\"text-align:center\"\u003e\n  \u003cimg width=\"300\" src=\"./document/docs/.vuepress/public/logo.png\"/\u003e\n\u003c/p\u003e\n\n# [CosId](https://cosid.ahoo.me/) Universal, flexible, high-performance distributed ID generator\n\n[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)\n[![GitHub release](https://img.shields.io/github/release/Ahoo-Wang/CosId.svg)](https://github.com/Ahoo-Wang/CosId/releases)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.ahoo.cosid/cosid-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/me.ahoo.cosid/cosid-core)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/dfd1d6237a1644409548ebfbca300dc1)](https://app.codacy.com/gh/Ahoo-Wang/CosId?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=Ahoo-Wang/CosId\u0026utm_campaign=Badge_Grade_Settings)\n[![codecov](https://codecov.io/gh/Ahoo-Wang/CosId/branch/main/graph/badge.svg?token=L0N51NB7ET)](https://codecov.io/gh/Ahoo-Wang/CosId)\n![Integration Test Status](https://github.com/Ahoo-Wang/CosId/actions/workflows/integration-test.yml/badge.svg)\n[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/Ahoo-Wang/CosId)\n\n\u003e [中文文档](https://cosid.ahoo.me/)\n\n## Introduction\n\n*[CosId](https://github.com/Ahoo-Wang/CosId)* aims to provide a universal, flexible and high-performance distributed ID\ngenerator.\n\n- `CosIdGenerator` : Stand-alone *TPS performance：15,570,085 ops/s* , three times that of `UUID.randomUUID()`,global trend increasing based-time.\n- `SnowflakeId` : Stand-alone *TPS performance：4,096,000 ops/s* [JMH Benchmark](#jmh-benchmark) , It mainly solves two major\n  problems of `SnowflakeId`: machine number allocation problem and clock backwards problem and provide a more friendly\n  and flexible experience.\n- `SegmentId`: Get a segment (`Step`) ID every time to reduce the network IO request frequency of the `IdSegment`\n  distributor and improve performance.\n    - `IdSegmentDistributor`:\n        - `RedisIdSegmentDistributor`: `IdSegment` distributor based on *Redis*.\n        - `JdbcIdSegmentDistributor`: The *Jdbc-based* `IdSegment` distributor supports various relational databases.\n        - `ZookeeperIdSegmentDistributor`: `IdSegment` distributor based on *Zookeeper*.\n        - `MongoIdSegmentDistributor`: `IdSegment` distributor based on *MongoDB*.\n- `SegmentChainId`(**recommend**):`SegmentChainId` (*lock-free*) is an enhancement of `SegmentId`, the design\n  diagram is as follows. `PrefetchWorker` maintains a `safe distance`, so that `SegmentChainId` achieves\n  approximately `AtomicLong` *TPS performance: 127,439,148+ ops/s* [JMH Benchmark](#jmh-benchmark) .\n    - `PrefetchWorker` maintains a safe distance (`safeDistance`), and supports dynamic `safeDistance` expansion and\n      contraction based on hunger status.\n\n## SnowflakeId\n\n\u003cp align=\"center\"\u003e\n     \u003cimg src=\"./document/docs/.vuepress/public/assets/design/Snowflake-identifier.png\" alt=\"Snowflake\"/\u003e\n\u003c/p\u003e\n\n\u003e *SnowflakeId* is a distributed ID algorithm that uses `Long` (64-bit) bit partition to generate ID.\n\u003e The general bit allocation scheme is : `timestamp` (41-bit) + `machineId` (10-bit) + `sequence` (12-bit) = 63-bit。\n\n- 41-bit `timestamp` = (1L\u003c\u003c41)/(1000/3600/24/365) approximately 69 years of timestamp can be stored, that is, the usable\n  absolute time is `EPOCH` + 69 years. Generally, we need to customize `EPOCH` as the product development time. In\n  addition, we can increase the number of allocated bits by compressing other areas， The number of timestamp bits to\n  extend the available time.\n- 10-bit `machineId` = (1L\u003c\u003c10) = 1024 That is, 1024 copies of the same business can be deployed (there is no\n  master-slave copy in the Kubernetes concept, and the definition of Kubernetes is directly used here) instances.\n  Generally, there is no need to use so many, so it will be redefined according to the scale of deployment.\n- 12-bit `sequence` = (1L\u003c\u003c12) * 1000 = 4096000 That is, a single machine can generate about 409W ID per second, and a\n  global same-service cluster can generate `4096000*1024=4194304000=4.19 billion (TPS)`.\n\nIt can be seen from the design of SnowflakeId:\n\n- :thumbsup: The first 41-bit are a `timestamp`,So *SnowflakeId* is local monotonically increasing, and affected by\n  global clock synchronization *SnowflakeId* is global trend increasing.\n- :thumbsup: `SnowflakeId` does not have a strong dependency on any third-party middleware, and its performance is also\n  very high.\n- :thumbsup: The bit allocation scheme can be flexibly configured according to the needs of the business system to\n  achieve the optimal use effect.\n- :thumbsdown: Strong reliance on the local clock, potential clock moved backwards problems will cause ID duplication.\n- :thumbsdown: The `machineId` needs to be set manually. If the `machineId` is manually assigned during actual\n  deployment, it will be very inefficient.\n\n---\n\n*[CosId-SnowflakeId](https://github.com/Ahoo-Wang/CosId/tree/main/cosid-core/src/main/java/me/ahoo/cosid/snowflake)*\n\nIt mainly solves two major problems of `SnowflakeId`: machine number allocation problem and clock backwards problem and\nprovide a more friendly and flexible experience.\n\n### MachineIdDistributor\n\n\u003e Currently [CosId](https://github.com/Ahoo-Wang/CosId) provides the following three `MachineId` distributors.\n\n#### ManualMachineIdDistributor\n\n```yaml\ncosid:\n  snowflake:\n    machine:\n      distributor:\n        type: manual\n        manual:\n          machine-id: 0\n```\n\n\u003e Manually distribute `MachineId`\n\n#### StatefulSetMachineIdDistributor\n\n```yaml\ncosid:\n  snowflake:\n    machine:\n      distributor:\n        type: stateful_set\n```\n\n\u003e Use the stable identification ID provided by the `StatefulSet` of `Kubernetes` as the machine number.\n\n#### RedisMachineIdDistributor\n\n\u003cp align=\"center\"\u003e\n     \u003cimg src=\"./document/docs/.vuepress/public/assets/design/RedisMachineIdDistributor.png\" alt=\"Redis Machine Id Distributor\"/\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n     \u003cimg src=\"./document/docs/.vuepress/public/assets/design/Machine-Id-Safe-Guard.png\" alt=\"Machine Id Safe Guard\"/\u003e\n\u003c/p\u003e\n\n```yaml\ncosid:\n  snowflake:\n    machine:\n      distributor:\n        type: redis\n```\n\n\u003e Use *Redis* as the distribution store for the machine number.\n\n### ClockBackwardsSynchronizer\n\n```yaml\ncosid:\n  snowflake:\n    clock-backwards:\n      spin-threshold: 10\n      broken-threshold: 2000\n```\n\nThe default `DefaultClockBackwardsSynchronizer` clock moved backwards synchronizer uses active wait synchronization\nstrategy, `spinThreshold` (default value 10 milliseconds) is used to set the spin wait threshold, when it is greater\nthan `spinThreshold`, use thread sleep to wait for clock synchronization, if it exceeds` BrokenThreshold` (default value\n2 seconds) will directly throw a `ClockTooManyBackwardsException` exception.\n\n### MachineStateStorage\n\n```java\npublic class MachineState {\n    public static final MachineState NOT_FOUND = of(-1, -1);\n    private final int machineId;\n    private final long lastTimeStamp;\n    \n    public MachineState(int machineId, long lastTimeStamp) {\n        this.machineId = machineId;\n        this.lastTimeStamp = lastTimeStamp;\n    }\n    \n    public int getMachineId() {\n        return machineId;\n    }\n    \n    public long getLastTimeStamp() {\n        return lastTimeStamp;\n    }\n    \n    public static MachineState of(int machineId, long lastStamp) {\n        return new MachineState(machineId, lastStamp);\n    }\n}\n```\n\n```yaml\ncosid:\n  snowflake:\n    machine:\n      state-storage:\n        local:\n          state-location: ./cosid-machine-state/\n```\n\nThe default `LocalMachineStateStorage` local machine state storage uses a local file to store the machine number and the\nmost recent timestamp, which is used as a `MachineState` cache.\n\n### ClockSyncSnowflakeId\n\n```yaml\ncosid:\n  snowflake:\n    share:\n      clock-sync: true\n```\n\nThe default `SnowflakeId` will directly throw a `ClockBackwardsException` when a clock moved backwards occurs, while\nusing the `ClockSyncSnowflakeId` will use the `ClockBackwardsSynchronizer` to actively wait for clock synchronization to\nregenerate the ID, providing a more user-friendly experience.\n\n### SafeJavaScriptSnowflakeId\n\n```java\nSnowflakeId snowflakeId=SafeJavaScriptSnowflakeId.ofMillisecond(1);\n```\n\nThe `Number.MAX_SAFE_INTEGER` of `JavaScript` has only 53-bit. If the 63-bit `SnowflakeId` is directly returned to the\nfront end, the value will overflow. Usually we can convert `SnowflakeId` to String type or customize `SnowflakeId` Bit\nallocation is used to shorten the number of bits of `SnowflakeId` so that `ID` does not overflow when it is provided to\nthe front end.\n\n### SnowflakeFriendlyId (Can parse `SnowflakeId` into a more readable `SnowflakeIdState`)\n\n```yaml\ncosid:\n  snowflake:\n    share:\n      friendly: true\n```\n\n```java\npublic class SnowflakeIdState {\n    \n    private final long id;\n    \n    private final int machineId;\n    \n    private final long sequence;\n    \n    private final LocalDateTime timestamp;\n    /**\n     * {@link #timestamp}-{@link #machineId}-{@link #sequence}\n     */\n    private final String friendlyId;\n}\n```\n\n```java\npublic interface SnowflakeFriendlyId extends SnowflakeId {\n    \n    SnowflakeIdState friendlyId(long id);\n    \n    SnowflakeIdState ofFriendlyId(String friendlyId);\n    \n    default SnowflakeIdState friendlyId() {\n        long id = generate();\n        return friendlyId(id);\n    }\n}\n```\n\n```java\n    SnowflakeFriendlyId snowflakeFriendlyId=new DefaultSnowflakeFriendlyId(snowflakeId);\n    SnowflakeIdState idState=snowflakeFriendlyId.friendlyId();\n    idState.getFriendlyId(); //20210623131730192-1-0\n```\n\n## SegmentId\n\n\u003cp align=\"center\"\u003e\n     \u003cimg src=\"./document/docs/.vuepress/public/assets/design/SegmentId.png\" alt=\"Segment Id\"/\u003e\n\u003c/p\u003e\n\n### RedisIdSegmentDistributor\n\n```yaml\ncosid:\n  segment:\n    enabled: true\n    distributor:\n      type: redis\n```\n\n### JdbcIdSegmentDistributor\n\n\u003e Initialize the `cosid` table\n\n```mysql\ncreate table if not exists cosid\n(\n    name            varchar(100) not null comment '{namespace}.{name}',\n    last_max_id     bigint       not null default 0,\n    last_fetch_time bigint       not null,\n    constraint cosid_pk\n        primary key (name)\n) engine = InnoDB;\n```\n\n```yaml\nspring:\n  datasource:\n    url: jdbc:mysql://localhost:3306/test_db\n    username: root\n    password: root\ncosid:\n  segment:\n    enabled: true\n    distributor:\n      type: jdbc\n      jdbc:\n        enable-auto-init-cosid-table: false\n        enable-auto-init-id-segment: true\n```\n\nAfter enabling `enable-auto-init-id-segment:true`, the application will try to create the `idSegment` record when it\nstarts to avoid manual creation. Similar to the execution of the following initialization sql script, there is no need\nto worry about misoperation, because `name` is the primary key.\n\n```mysql\ninsert into cosid\n    (name, last_max_id, last_fetch_time)\n    value\n    ('namespace.name', 0, unix_timestamp());\n```\n\n### SegmentChainId\n\n![SegmentChainId](./docs/SegmentChainId.png)\n\n```yaml\ncosid:\n  segment:\n    enabled: true\n    mode: chain\n    chain:\n      safe-distance: 5\n      prefetch-worker:\n        core-pool-size: 2\n        prefetch-period: 1s\n    distributor:\n      type: redis\n    share:\n      offset: 0\n      step: 100\n    provider:\n      bizC:\n        offset: 10000\n        step: 100\n      bizD:\n        offset: 10000\n        step: 100\n```\n\n## IdGeneratorProvider\n\n```yaml\ncosid:\n  snowflake:\n    provider:\n      bizA:\n        #      timestamp-bit:\n        sequence-bit: 12\n      bizB:\n        #      timestamp-bit:\n        sequence-bit: 12\n```\n\n```java\nIdGenerator idGenerator=idGeneratorProvider.get(\"bizA\");\n```\n\nIn actual use, we generally do not use the same `IdGenerator` for all business services, but different businesses use\ndifferent `IdGenerator`, then `IdGeneratorProvider` exists to solve this problem, and it is the container\nof `IdGenerator` , You can get the corresponding `IdGenerator` by the business name.\n\n### CosIdPlugin (MyBatis Plugin)\n\n\u003e Kotlin DSL\n\n``` kotlin\n    implementation(\"me.ahoo.cosid:cosid-mybatis:${cosidVersion}\")\n```\n\n```java\n\n@Target({ElementType.FIELD})\n@Documented\n@Retention(RetentionPolicy.RUNTIME)\npublic @interface CosId {\n    String value() default IdGeneratorProvider.SHARE;\n    \n    boolean friendlyId() default false;\n}\n```\n\n```java\npublic class LongIdEntity {\n    \n    @CosId(value = \"safeJs\")\n    private Long id;\n    \n    public Long getId() {\n        return id;\n    }\n    \n    public void setId(Long id) {\n        this.id = id;\n    }\n}\n\npublic class FriendlyIdEntity {\n    \n    @CosId(friendlyId = true)\n    private String id;\n    \n    public String getId() {\n        return id;\n    }\n    \n    public void setId(String id) {\n        this.id = id;\n    }\n}\n```\n\n```java\n\n@Mapper\npublic interface OrderRepository {\n    @Insert(\"insert into t_table (id) value (#{id});\")\n    void insert(LongIdEntity order);\n    \n    @Insert({\n        \"\u003cscript\u003e\",\n        \"insert into t_friendly_table (id)\",\n        \"VALUES\" +\n            \"\u003cforeach item='item' collection='list' open='' separator=',' close=''\u003e\" +\n            \"(#{item.id})\" +\n            \"\u003c/foreach\u003e\",\n        \"\u003c/script\u003e\"})\n    void insertList(List\u003cFriendlyIdEntity\u003e list);\n}\n```\n\n```java\n        LongIdEntity entity=new LongIdEntity();\n    entityRepository.insert(entity);\n    /**\n     * {\n     *   \"id\": 208796080181248\n     * }\n     */\n    return entity;\n```\n\n### ShardingSphere Plugin\n\n\u003e [cosid-shardingsphere](https://github.com/apache/shardingsphere/tree/master/features/sharding/plugin/cosid)\n\n#### CosIdKeyGenerateAlgorithm (Distributed-Id)\n\n```yaml\nspring:\n  shardingsphere:\n    rules:\n      sharding:\n        key-generators:\n          cosid:\n            type: COSID\n            props:\n              id-name: __share__\n```\n\n#### Interval-based time range sharding algorithm\n\n\u003cp align=\"center\"\u003e\n     \u003cimg src=\"./document/docs/.vuepress/public/assets/design/CosIdIntervalShardingAlgorithm.png\" alt=\"CosIdIntervalShardingAlgorithm\"/\u003e\n\u003c/p\u003e\n\n- Ease of use: supports multiple data types (`Long`/`LocalDateTime`/`DATE`/ `String` / `SnowflakeId`),The official\n  implementation is to first convert to a string and then convert to `LocalDateTime`, the conversion success rate is\n  affected by the time formatting characters.\n- Performance: Compared to  `org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm`\n  ,The performance is *1200~4000* times higher.\n\n| **PreciseShardingValue**                                                                                                                                                                  | **RangeShardingValue**                                                                                                                                                                |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ![Throughput Of IntervalShardingAlgorithm - PreciseShardingValue](./document/docs/.vuepress/public/assets/perf/sharding/Throughput-Of-IntervalShardingAlgorithm-PreciseShardingValue.png) | ![Throughput Of IntervalShardingAlgorithm - RangeShardingValue](./document/docs/.vuepress/public/assets/perf/sharding/Throughput-Of-IntervalShardingAlgorithm-RangeShardingValue.png) |\n\n- CosIdIntervalShardingAlgorithm\n    - type: COSID_INTERVAL\n\n```yaml\nspring:\n  shardingsphere:\n    rules:\n      sharding:\n        sharding-algorithms:\n          alg-name:\n            type: COSID_INTERVAL\n            props:\n              logic-name-prefix: logic-name-prefix\n              id-name: cosid-name\n              datetime-lower: 2021-12-08 22:00:00\n              datetime-upper: 2022-12-01 00:00:00\n              sharding-suffix-pattern: yyyyMM\n              datetime-interval-unit: MONTHS\n              datetime-interval-amount: 1\n```\n\n#### CosIdModShardingAlgorithm\n\n\u003cp align=\"center\"\u003e\n     \u003cimg src=\"./document/docs/.vuepress/public/assets/design/CosIdModShardingAlgorithm.png\" alt=\"CosId Mod Sharding Algorithm\"/\u003e\n\u003c/p\u003e\n\n- Performance: Compared to  `org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm`\n  ,The performance is *1200~4000* times higher.And it has higher stability and no serious performance degradation.\n\n| **PreciseShardingValue**                                                                                                                                                        | **RangeShardingValue**                                                                                                                                                      |\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ![Throughput Of ModShardingAlgorithm - PreciseShardingValue](./document/docs/.vuepress/public/assets/perf/sharding/Throughput-Of-ModShardingAlgorithm-PreciseShardingValue.png) | ![Throughput Of ModShardingAlgorithm - RangeShardingValue](./document/docs/.vuepress/public/assets/perf/sharding/Throughput-Of-ModShardingAlgorithm-RangeShardingValue.png) |\n\n```yaml\nspring:\n  shardingsphere:\n    rules:\n      sharding:\n        sharding-algorithms:\n          alg-name:\n            type: COSID_MOD\n            props:\n              mod: 4\n              logic-name-prefix: t_table_\n```\n\n## Examples\n\u003e 项目中根据使用的场景（`jdbc`/`proxy`/`redis-cosid`/`redis`/`shardingsphere`/`zookeeper`等）提供了对应的例子，实践过程中可以参照配置快速接入。\n\n[点击查看Examples](https://github.com/Ahoo-Wang/CosId/tree/main/examples)\n\n## Installation\n\n### Gradle\n\n\u003e Kotlin DSL\n\n``` kotlin\n    val cosidVersion = \"1.14.5\";\n    implementation(\"me.ahoo.cosid:cosid-spring-boot-starter:${cosidVersion}\")\n```\n\n### Maven\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\n\u003cproject xmlns=\"http://maven.apache.org/POM/4.0.0\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\u003e\n\n    \u003cmodelVersion\u003e4.0.0\u003c/modelVersion\u003e\n    \u003cartifactId\u003edemo\u003c/artifactId\u003e\n    \u003cproperties\u003e\n        \u003ccosid.version\u003e1.14.5\u003c/cosid.version\u003e\n    \u003c/properties\u003e\n\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eme.ahoo.cosid\u003c/groupId\u003e\n            \u003cartifactId\u003ecosid-spring-boot-starter\u003c/artifactId\u003e\n            \u003cversion\u003e${cosid.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\n\u003c/project\u003e\n```\n\n### application.yaml\n\n```yaml\nspring:\n  shardingsphere:\n    datasource:\n      names: ds0,ds1\n      ds0:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbcUrl: jdbc:mysql://localhost:3306/cosid_db_0\n        username: root\n        password: root\n      ds1:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbcUrl: jdbc:mysql://localhost:3306/cosid_db_1\n        username: root\n        password: root\n    props:\n      sql-show: true\n    rules:\n      sharding:\n        binding-tables:\n          - t_order,t_order_item\n        tables:\n          cosid:\n            actual-data-nodes: ds0.cosid\n          t_table:\n            actual-data-nodes: ds0.t_table_$-\u003e{0..1}\n            table-strategy:\n              standard:\n                sharding-column: id\n                sharding-algorithm-name: table-inline\n          t_date_log:\n            actual-data-nodes: ds0.t_date_log_202112\n            key-generate-strategy:\n              column: id\n              key-generator-name: snowflake\n            table-strategy:\n              standard:\n                sharding-column: create_time\n                sharding-algorithm-name: data-log-interval\n        sharding-algorithms:\n          table-inline:\n            type: COSID_MOD\n            props:\n              mod: 2\n              logic-name-prefix: t_table_\n          data-log-interval:\n            type: COSID_INTERVAL\n            props:\n              logic-name-prefix: t_date_log_\n              datetime-lower: 2021-12-08 22:00:00\n              datetime-upper: 2022-12-01 00:00:00\n              sharding-suffix-pattern: yyyyMM\n              datetime-interval-unit: MONTHS\n              datetime-interval-amount: 1\n        key-generators:\n          snowflake:\n            type: COSID\n            props:\n              id-name: snowflake\n\n\ncosid:\n  namespace: ${spring.application.name}\n  machine:\n    enabled: true\n    #      stable: true\n    #      machine-bit: 10\n    #      instance-id: ${HOSTNAME}\n    distributor:\n      type: redis\n    #        manual:\n    #          machine-id: 0\n  snowflake:\n    enabled: true\n    #    epoch: 1577203200000\n    clock-backwards:\n      spin-threshold: 10\n      broken-threshold: 2000\n    share:\n      clock-sync: true\n      friendly: true\n    provider:\n      order_item:\n        #        timestamp-bit:\n        sequence-bit: 12\n      snowflake:\n        sequence-bit: 12\n      safeJs:\n        machine-bit: 3\n        sequence-bit: 9\n  segment:\n    enabled: true\n    mode: chain\n    chain:\n      safe-distance: 5\n      prefetch-worker:\n        core-pool-size: 2\n        prefetch-period: 1s\n    distributor:\n      type: redis\n    share:\n      offset: 0\n      step: 100\n    provider:\n      order:\n        offset: 10000\n        step: 100\n      longId:\n        offset: 10000\n        step: 100\n```\n\n## JMH-Benchmark\n\n- The development notebook : MacBook Pro (M1)\n- All benchmark tests are carried out on the development notebook.\n- Deploying Redis on the development notebook.\n\n### SnowflakeId\n\n``` shell\ngradle cosid-core:jmh\n# or\njava -jar cosid-core/build/libs/cosid-core-1.14.5-jmh.jar -bm thrpt -wi 1 -rf json -f 1\n```\n\n```\nBenchmark                                                    Mode  Cnt        Score   Error  Units\nSnowflakeIdBenchmark.millisecondSnowflakeId_friendlyId      thrpt       4020311.665          ops/s\nSnowflakeIdBenchmark.millisecondSnowflakeId_generate        thrpt       4095403.859          ops/s\nSnowflakeIdBenchmark.safeJsMillisecondSnowflakeId_generate  thrpt        511654.048          ops/s\nSnowflakeIdBenchmark.safeJsSecondSnowflakeId_generate       thrpt        539818.563          ops/s\nSnowflakeIdBenchmark.secondSnowflakeId_generate             thrpt       4206843.941          ops/s\n```\n\n### Throughput (ops/s) of SegmentChainId\n\n\u003cp align=\"center\" \u003e\n  \u003cimg src=\"./document/docs/.vuepress/public/assets/perf/Throughput-Of-SegmentChainId.png\" alt=\"Throughput-Of-SegmentChainId\"/\u003e\n\u003c/p\u003e\n\n### Percentile-Sample (*P9999=0.208 us/op*)  of SegmentChainId\n\n\u003e In statistics, a [percentile](https://en.wikipedia.org/wiki/Percentile) (or a centile) is a score below which a given percentage of scores in its frequency distribution falls (exclusive definition) or a score at or below which a given percentage falls (inclusive definition). For example, the 50th percentile (the median) is the score below which (exclusive) or at or below which (inclusive) 50% of the scores in the distribution may be found.\n\n\u003cp align=\"center\" \u003e\n  \u003cimg src=\"./document/docs/.vuepress/public/assets/perf/Percentile-Sample-Of-SegmentChainId.png\" alt=\"Percentile-Sample-Of-SegmentChainId\"/\u003e\n\u003c/p\u003e\n\n### CosId VS MeiTuan Leaf\n\n\u003e CosId (`SegmentChainId`) is 5 times faster than Leaf(`segment`).\n\n\u003cp align=\"center\" \u003e\n  \u003cimg  src=\"./document/docs/.vuepress/public/assets/perf/CosId-VS-Leaf.png\" alt=\"CosId VS MeiTuan Leaf\"/\u003e\n\u003c/p\u003e\n\n## Community Partners and Sponsors\n\n\u003ca href=\"https://www.jetbrains.com/?from=CosId\" target=\"_blank\"\u003e\n    \u003cimg src=\"./docs/jetbrains-logo.png\" title=\"JetBrains\" width=130 /\u003e\n\u003c/a\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoo-wang%2Fcosid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahoo-wang%2Fcosid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoo-wang%2Fcosid/lists"}