1
0
mirror of synced 2025-12-18 11:08:03 +08:00

auto commit

This commit is contained in:
yitter
2021-03-30 01:29:03 +08:00
parent 27b527993e
commit 55a5722d95
23 changed files with 241 additions and 152 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Yitter.IdGenerator; using Yitter.IdGenerator;
namespace Yitter.OrgSystem.TestA namespace Yitter.OrgSystem.TestA
@@ -54,20 +55,23 @@ namespace Yitter.OrgSystem.TestA
while (true) while (true)
{ {
RunSingle(); //RunSingle();
//Go(options); //Go(options);
//CallDll(); CallDll();
Thread.Sleep(1000); // 每隔1秒执行一次Go Thread.Sleep(1000); // 每隔1秒执行一次Go
} }
} }
[DllImport("yitidgenc.dll", CallingConvention = CallingConvention.Cdecl)] //[DllImport("yitidgenc.dll", CallingConvention = CallingConvention.StdCall)]
//public static extern long NextId();
[DllImport("yitidgenc.dll", CallingConvention = CallingConvention.StdCall)]
public static extern long NextId(); public static extern long NextId();
[DllImport("yitidgenc.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("yitidgenc.dll", CallingConvention = CallingConvention.StdCall)]
public static extern void SetWorkerId(uint workerId); public static extern void SetWorkerId(uint workerId);
[DllImport("yitidgenc.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("yitidgenc.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int TestId(); public static extern int TestId();
private static void CallDll() private static void CallDll()
@@ -78,15 +82,27 @@ namespace Yitter.OrgSystem.TestA
int i = 0; int i = 0;
long id = 0; long id = 0;
DateTime start = DateTime.Now; DateTime start = DateTime.Now;
bool useMultiThread = false;
var ids = TestId(); //var ids = TestId();
//SetWorkerId(1); //SetWorkerId(1);
while (i < 50000) while (i < 50000)
{ {
id = NextId();
i++; i++;
if (useMultiThread)
{
Task.Run(() =>
{
id = NextId();
Console.WriteLine("id" + id);
});
}
else
{
id = NextId();
}
} }
DateTime end = DateTime.Now; DateTime end = DateTime.Now;
Console.WriteLine("id:" + id); Console.WriteLine("id:" + id);

View File

@@ -0,0 +1,8 @@
{
"profiles": {
"Yitter.IdGenTest": {
"commandName": "Project",
"nativeDebugging": true
}
}
}

View File

@@ -12,6 +12,10 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Yitter.IdGenerator\Yitter.IdGenerator.csproj" /> <ProjectReference Include="..\Yitter.IdGenerator\Yitter.IdGenerator.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -9,13 +9,13 @@
TAP_DLLEXPORT TAP_DLLEXPORT
extern void SetIdGenerator(IdGeneratorOptions options); extern void TAP_STDCALL SetIdGenerator(IdGeneratorOptions options);
TAP_DLLEXPORT TAP_DLLEXPORT
extern void SetWorkerId(uint32_t workerId); extern void TAP_STDCALL SetWorkerId(uint32_t workerId);
TAP_DLLEXPORT TAP_DLLEXPORT
extern uint64_t NextId(); extern uint64_t TAP_STDCALL NextId();
TAP_DLLEXPORT TAP_DLLEXPORT
extern uint64_t TestId() ; extern uint64_t TAP_STDCALL TestId();

View File

@@ -5,9 +5,11 @@
#ifdef _WIN32 #ifdef _WIN32
#define TAP_CDECL __cdecl #define TAP_CDECL __cdecl
#define TAP_STDCALL __stdcall
#define TAP_DLLEXPORT __declspec(dllexport) #define TAP_DLLEXPORT __declspec(dllexport)
#else #else
#define TAP_CDECL #define TAP_CDECL
#define TAP_STDCALL
#define TAP_DLLEXPORT #define TAP_DLLEXPORT
#endif #endif

View File

@@ -24,7 +24,7 @@ void RunMultiThread() {
//int64_t start = GetCurrentMicroTime(); //int64_t start = GetCurrentMicroTime();
for (int i = 0; i < GenIdCount / threadCount; i++) { for (int i = 0; i < GenIdCount / threadCount; i++) {
int64_t id = NextId(); int64_t id = NextId();
printf("生成ID: %D\n", id); printf("ID: %D\n", id);
} }
int64_t end = GetCurrentMicroTime(); int64_t end = GetCurrentMicroTime();
@@ -35,11 +35,11 @@ void RunSingle() {
int64_t start = GetCurrentMicroTime(); int64_t start = GetCurrentMicroTime();
for (int i = 0; i < GenIdCount; i++) { for (int i = 0; i < GenIdCount; i++) {
int64_t id = NextId(); int64_t id = NextId();
// printf("生成ID: %ld\n", id); // printf("ID: %ld\n", id);
} }
int64_t end = GetCurrentMicroTime(); int64_t end = GetCurrentMicroTime();
printf("%stotal%d μs\n", method == 1 ? "1" : "2", (end - start)); printf("%s, total: %d us\n", method == 1 ? "1" : "2", (end - start));
} }
int main() { int main() {

View File

@@ -1,5 +1,11 @@
# idgenerator # idgenerator
##
Go<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ר<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>https://gitee.com/yitter/idgenerator-go
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Go ר<><EFBFBD><EEB9A4>Ϊ׼<CEAA><D7BC>
## Go<47><6F><EFBFBD><EFBFBD> ## Go<47><6F><EFBFBD><EFBFBD>
1.SDK<44><4B>go1.16 1.SDK<44><4B>go1.16

View File

@@ -1,12 +1,19 @@
package main package main
import ( import (
"C"
"fmt" "fmt"
"time" "time"
"yitidgen/contract" "yitidgen/contract"
"yitidgen/gen" "yitidgen/gen"
) )
//export NextId
func NextId() uint64{
return gen.GetIns().NextId()
}
func main() { func main() {
// 方法一直接采用默认方法生成一个Id // 方法一直接采用默认方法生成一个Id
var yid = gen.YitIdHelper{} var yid = gen.YitIdHelper{}

View File

@@ -5,7 +5,12 @@ JDK 1.8+
## <20><><EFBFBD><EFBFBD> maven <20><> ## <20><><EFBFBD><EFBFBD> maven <20><>
``` ```
<dependency>
<groupId>com.github.yitter</groupId>
<artifactId>yitter-idgenerator</artifactId>
<version>1.0.1</version>
<type>pom</type>
</dependency>
``` ```
## <20><><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE> ## <20><><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>

View File

@@ -4,23 +4,40 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.yitter</groupId> <groupId>com.github.yitter</groupId>
<artifactId>yitter.idgenerator</artifactId> <artifactId>yitter-idgenerator</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.0.0</version> <version>1.0.1</version>
<name>yitter.idgenerator</name> <name>yitter-idgenerator</name>
<description>Shorter ID and faster generation with a new snowflake drift algorithm. The core is to shorten the ID length, but also can have a very high instantaneous concurrent processing capacity (50W/0.1s), and powerful configuration capacity.</description> <description>Shorter ID and faster generation with a new snowflake drift algorithm. The core is to shorten the ID
length, but also can have a very high instantaneous concurrent processing capacity (50W/0.1s), and powerful
configuration capacity.
</description>
<url>https://github.com/yitter/idgenerator</url>
<developers> <developers>
<developer> <developer>
<id>yitter</id> <id>yitter</id>
<name>yitter</name> <name>yitter</name>
<email>yitter@126.com</email> <email>yitter@126.com</email>
<url>https://gitee.com/yitter/idgenerator</url> <url>https://github.com/yitter/idgenerator</url>
</developer> </developer>
</developers> </developers>
<scm>
<connection>scm:git:https://github.com/yitter/idgenerator.git</connection>
<developerConnection>scm:git:https://github.com/yitter/idgenerator.git</developerConnection>
<url>https://github.com/yitter/idgenerator.git</url>
</scm>
<licenses>
<license>
<name>MIT</name>
<url>https://github.com/yitter/IdGenerator/blob/main/LICENSE</url>
</license>
</licenses>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@@ -30,13 +47,63 @@
</properties> </properties>
<build> <build>
<pluginManagement>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>3.8.0</version> <version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration> <configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<fork>true</fork>
<source>${java.version}</source> <source>${java.version}</source>
<target>${java.version}</target> <target>${java.version}</target>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
@@ -47,47 +114,18 @@
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version> <version>3.1.0</version>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins> </plugins>
</pluginManagement>
<resources>
<resource>
<directory>${project.basedir}</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>LICENSE</include>
<include>NOTICE</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<includes>
<include>**</include>
</includes>
</testResource>
</testResources>
</build> </build>
<licenses> <distributionManagement>
<license> <snapshotRepository>
<name>The Apache Software License, Version 2.0</name> <id>ossrh</id>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</license> </snapshotRepository>
</licenses> <repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</project> </project>

View File

@@ -2,7 +2,7 @@
* 版权属于yitter(yitter@126.com) * 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator * 开源地址https://gitee.com/yitter/idgenerator
*/ */
package com.yitter.contract; package com.github.yitter.contract;
public interface IIdGenerator { public interface IIdGenerator {
long newLong() throws IdGeneratorException; long newLong() throws IdGeneratorException;

View File

@@ -2,7 +2,7 @@
* 版权属于yitter(yitter@126.com) * 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator * 开源地址https://gitee.com/yitter/idgenerator
*/ */
package com.yitter.contract; package com.github.yitter.contract;
public interface ISnowWorker { public interface ISnowWorker {
long nextId() throws IdGeneratorException; long nextId() throws IdGeneratorException;

View File

@@ -2,7 +2,7 @@
* 版权属于yitter(yitter@126.com) * 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator * 开源地址https://gitee.com/yitter/idgenerator
*/ */
package com.yitter.contract; package com.github.yitter.contract;
public class IdGeneratorException extends RuntimeException { public class IdGeneratorException extends RuntimeException {

View File

@@ -2,7 +2,7 @@
* 版权属于yitter(yitter@126.com) * 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator * 开源地址https://gitee.com/yitter/idgenerator
*/ */
package com.yitter.contract; package com.github.yitter.contract;
/** /**
* 雪花算法使用的参数 * 雪花算法使用的参数

View File

@@ -2,7 +2,7 @@
* 版权属于yitter(yitter@126.com) * 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator * 开源地址https://gitee.com/yitter/idgenerator
*/ */
package com.yitter.contract; package com.github.yitter.contract;
/** /**
* Id生成时回调参数 * Id生成时回调参数

View File

@@ -2,12 +2,12 @@
* 版权属于yitter(yitter@126.com) * 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator * 开源地址https://gitee.com/yitter/idgenerator
*/ */
package com.yitter.core; package com.github.yitter.core;
import com.yitter.contract.ISnowWorker; import com.github.yitter.contract.ISnowWorker;
import com.yitter.contract.IdGeneratorException; import com.github.yitter.contract.IdGeneratorOptions;
import com.yitter.contract.IdGeneratorOptions; import com.github.yitter.contract.OverCostActionArg;
import com.yitter.contract.OverCostActionArg; import com.github.yitter.contract.IdGeneratorException;
public class SnowWorkerM1 implements ISnowWorker { public class SnowWorkerM1 implements ISnowWorker {

View File

@@ -2,10 +2,10 @@
* 版权属于yitter(yitter@126.com) * 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator * 开源地址https://gitee.com/yitter/idgenerator
*/ */
package com.yitter.core; package com.github.yitter.core;
import com.yitter.contract.IdGeneratorException; import com.github.yitter.contract.IdGeneratorOptions;
import com.yitter.contract.IdGeneratorOptions; import com.github.yitter.contract.IdGeneratorException;
public class SnowWorkerM2 extends SnowWorkerM1 { public class SnowWorkerM2 extends SnowWorkerM1 {

View File

@@ -2,14 +2,14 @@
* 版权属于yitter(yitter@126.com) * 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator * 开源地址https://gitee.com/yitter/idgenerator
*/ */
package com.yitter.idgen; package com.github.yitter.idgen;
import com.yitter.contract.ISnowWorker; import com.github.yitter.contract.IIdGenerator;
import com.yitter.contract.IdGeneratorException; import com.github.yitter.contract.ISnowWorker;
import com.yitter.contract.IdGeneratorOptions; import com.github.yitter.contract.IdGeneratorException;
import com.yitter.contract.IIdGenerator; import com.github.yitter.contract.IdGeneratorOptions;
import com.yitter.core.SnowWorkerM1; import com.github.yitter.core.SnowWorkerM1;
import com.yitter.core.SnowWorkerM2; import com.github.yitter.core.SnowWorkerM2;
public class DefaultIdGenerator implements IIdGenerator { public class DefaultIdGenerator implements IIdGenerator {

View File

@@ -2,11 +2,11 @@
* 版权属于yitter(yitter@126.com) * 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator * 开源地址https://gitee.com/yitter/idgenerator
*/ */
package com.yitter.idgen; package com.github.yitter.idgen;
import com.yitter.contract.IdGeneratorException; import com.github.yitter.contract.IIdGenerator;
import com.yitter.contract.IdGeneratorOptions; import com.github.yitter.contract.IdGeneratorException;
import com.yitter.contract.IIdGenerator; import com.github.yitter.contract.IdGeneratorOptions;
/** /**
* 这是一个调用的例子默认情况下单机集成者可以直接使用 nextId() * 这是一个调用的例子默认情况下单机集成者可以直接使用 nextId()
@@ -22,8 +22,6 @@ public class YitIdHelper {
/** /**
* 设置参数建议程序初始化时执行一次 * 设置参数建议程序初始化时执行一次
*
* @param options
*/ */
public static void setIdGenerator(IdGeneratorOptions options) throws IdGeneratorException { public static void setIdGenerator(IdGeneratorOptions options) throws IdGeneratorException {
idGenInstance = new DefaultIdGenerator(options); idGenInstance = new DefaultIdGenerator(options);

View File

@@ -1,6 +1,6 @@
package com.yitter.test; package com.github.yitter.test;
import com.yitter.contract.IIdGenerator; import com.github.yitter.contract.IIdGenerator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View File

@@ -1,9 +1,9 @@
package com.yitter.test; package com.github.yitter.test;
import com.yitter.contract.IdGeneratorOptions; import com.github.yitter.contract.IIdGenerator;
import com.yitter.contract.IIdGenerator; import com.github.yitter.contract.IdGeneratorOptions;
import com.yitter.idgen.DefaultIdGenerator; import com.github.yitter.idgen.DefaultIdGenerator;
import com.yitter.idgen.YitIdHelper; import com.github.yitter.idgen.YitIdHelper;
public class StartUp { public class StartUp {

View File

@@ -63,6 +63,8 @@ QQ群646049993
6.不依赖任何外部缓存和数据库。(当然 WorkerId 须由外部指定) 6.不依赖任何外部缓存和数据库。(当然 WorkerId 须由外部指定)
7.基础功能,开箱即用,无需配置文件、数据库连接等。
## 性能数据 ## 性能数据
(参数10位自增序列1000次漂移最大值) (参数10位自增序列1000次漂移最大值)

View File

@@ -0,0 +1,3 @@
@echo off
cargo build --release
@pause