| @@ -12,7 +12,7 @@ namespace Yitter.OrgSystem.TestA | |||||
| class Program | class Program | ||||
| { | { | ||||
| // 测试参数(默认配置下,最佳性能是10W/s) | // 测试参数(默认配置下,最佳性能是10W/s) | ||||
| static int genIdCount = 2;//5000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为20000或适当增加SeqBitLength) | |||||
| static int genIdCount = 500000;//5000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为2000或适当增加SeqBitLength) | |||||
| static short method = 1; // 1-漂移算法,2-传统算法 | static short method = 1; // 1-漂移算法,2-传统算法 | ||||
| @@ -27,6 +27,9 @@ namespace Yitter.OrgSystem.TestA | |||||
| static void Main(string[] args) | static void Main(string[] args) | ||||
| { | { | ||||
| RunSingle(); | |||||
| return; | |||||
| Console.WriteLine("Hello World! C#"); | Console.WriteLine("Hello World! C#"); | ||||
| var options = new IdGeneratorOptions() | var options = new IdGeneratorOptions() | ||||
| @@ -130,16 +133,42 @@ namespace Yitter.OrgSystem.TestA | |||||
| private static void RunSingle() | private static void RunSingle() | ||||
| { | { | ||||
| DateTime start = DateTime.Now; | |||||
| for (int i = 0; i < genIdCount; i++) | |||||
| var options = new IdGeneratorOptions() | |||||
| { | { | ||||
| var id = IdGen.NewLong(); | |||||
| } | |||||
| Method = 1, | |||||
| WorkerId = 1, | |||||
| //WorkerIdBitLength = 6, | |||||
| SeqBitLength = 6, | |||||
| //DataCenterIdBitLength = 0, | |||||
| //TopOverCostCount = 2000, | |||||
| DateTime end = DateTime.Now; | |||||
| Console.WriteLine($"++++++++++++++++++++++++++++++++++++++++, total: {(end - start).TotalMilliseconds} ms"); | |||||
| Interlocked.Increment(ref Program.Count); | |||||
| //TimestampType = 1, | |||||
| // MinSeqNumber = 1, | |||||
| // MaxSeqNumber = 200, | |||||
| // BaseTime = DateTime.Now.AddYears(-10), | |||||
| }; | |||||
| //IdGen = new DefaultIdGenerator(options); | |||||
| YitIdHelper.SetIdGenerator(options); | |||||
| while (true) | |||||
| { | |||||
| DateTime start = DateTime.Now; | |||||
| for (int i = 0; i < genIdCount; i++) | |||||
| { | |||||
| //var id = IdGen.NewLong(); | |||||
| var id = YitIdHelper.NextId(); | |||||
| } | |||||
| DateTime end = DateTime.Now; | |||||
| Console.WriteLine($"++++++++++++++++++++++++++++++++++++++++, total: {(end - start).TotalMilliseconds} ms"); | |||||
| Thread.Sleep(1000); | |||||
| } | |||||
| //Interlocked.Increment(ref Program.Count); | |||||
| } | } | ||||
| private static void Go(IdGeneratorOptions options) | private static void Go(IdGeneratorOptions options) | ||||
| @@ -13,51 +13,62 @@ | |||||
| #include "idgen/IdGenerator.h" | #include "idgen/IdGenerator.h" | ||||
| #include "YitIdHelper.h" | #include "YitIdHelper.h" | ||||
| const int GenIdCount = 50000; | |||||
| const int GenIdCount = 500000; | |||||
| const bool multiThread = false; | const bool multiThread = false; | ||||
| const int threadCount = 50; | const int threadCount = 50; | ||||
| const int method = 1; | const int method = 1; | ||||
| void RunMultiThread() { | |||||
| //int64_t start = GetCurrentMicroTime(); | |||||
| for (int i = 0; i < GenIdCount / threadCount; i++) { | |||||
| void RunMultiThread() | |||||
| { | |||||
| // int64_t start = GetCurrentMicroTime(); | |||||
| 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(); | ||||
| //printf("%s,total:%d μs\n", method == 1 ? "1" : "2", (end - start)); | |||||
| // printf("%s,total:%d μs\n", method == 1 ? "1" : "2", (end - start)); | |||||
| } | } | ||||
| void RunSingle() { | |||||
| 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("%s, total: %d us\n", method == 1 ? "1" : "2", (end - start)); | printf("%s, total: %d us\n", method == 1 ? "1" : "2", (end - start)); | ||||
| } | } | ||||
| int main() { | |||||
| int main() | |||||
| { | |||||
| IdGeneratorOptions options = BuildIdGenOptions(1); | IdGeneratorOptions options = BuildIdGenOptions(1); | ||||
| options.Method = method; | options.Method = method; | ||||
| options.WorkerId = 1; | options.WorkerId = 1; | ||||
| options.SeqBitLength = 6; | |||||
| options.SeqBitLength = 10; | |||||
| // options.TopOverCostCount = 2000; | |||||
| SetIdGenerator(options); | SetIdGenerator(options); | ||||
| pthread_t tid[threadCount]; | pthread_t tid[threadCount]; | ||||
| while (1) { | |||||
| if (multiThread) { | |||||
| for (int i = 0; i < threadCount; i++) { | |||||
| if (pthread_create(&tid[i], NULL, (void *) RunMultiThread, NULL) != 0) { | |||||
| while (1) | |||||
| { | |||||
| if (multiThread) | |||||
| { | |||||
| for (int i = 0; i < threadCount; i++) | |||||
| { | |||||
| if (pthread_create(&tid[i], NULL, (void *)RunMultiThread, NULL) != 0) | |||||
| { | |||||
| printf("thread creation failed\n"); | printf("thread creation failed\n"); | ||||
| exit(1); | exit(1); | ||||
| } | } | ||||
| } | } | ||||
| } else { | |||||
| } | |||||
| else | |||||
| { | |||||
| RunSingle(); | RunSingle(); | ||||
| } | } | ||||
| @@ -24,22 +24,24 @@ func main() { | |||||
| // 自定义参数 | // 自定义参数 | ||||
| var options = idgen.NewIdGeneratorOptions(1) | var options = idgen.NewIdGeneratorOptions(1) | ||||
| options.WorkerIdBitLength = 6 | options.WorkerIdBitLength = 6 | ||||
| options.SeqBitLength = 6 | |||||
| options.SeqBitLength = 10 | |||||
| options.BaseTime = time.Date(2020, 2, 20, 2, 20, 2, 20, time.UTC).UnixNano() / 1e6 | options.BaseTime = time.Date(2020, 2, 20, 2, 20, 2, 20, time.UTC).UnixNano() / 1e6 | ||||
| idgen.SetIdGenerator(options) | idgen.SetIdGenerator(options) | ||||
| var genCount = 50000 | |||||
| for { | |||||
| var begin = time.Now().UnixNano() / 1e3 | |||||
| for i := 0; i < genCount; i++ { | |||||
| // 生成ID | |||||
| id := idgen.NextId() | |||||
| fmt.Println(id) | |||||
| var genCount = 500000 | |||||
| for j := 0; j < 100000; j++ { | |||||
| for { | |||||
| var begin = time.Now().UnixNano() / 1e6 | |||||
| for i := 0; i < genCount; i++ { | |||||
| // 生成ID | |||||
| idgen.NextId() | |||||
| // fmt.Println(id) | |||||
| } | |||||
| var end = time.Now().UnixNano() / 1e6 | |||||
| fmt.Println("耗时:", (end - begin), "ms") | |||||
| time.Sleep(time.Duration(1000) * time.Millisecond) | |||||
| } | } | ||||
| var end = time.Now().UnixNano() / 1e3 | |||||
| fmt.Println(end - begin) | |||||
| time.Sleep(time.Duration(1000) * time.Millisecond) | |||||
| } | } | ||||
| } else { | } else { | ||||
| // ip := "localhost" | // ip := "localhost" | ||||
| @@ -19,7 +19,9 @@ | |||||
| *.zip | *.zip | ||||
| *.tar.gz | *.tar.gz | ||||
| *.rar | *.rar | ||||
| target/ | |||||
| target | |||||
| .vscode | |||||
| *.code-workspace | |||||
| # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||||
| hs_err_pid* | hs_err_pid* | ||||
| @@ -41,9 +41,9 @@ | |||||
| <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> | ||||
| <maven.compiler.source>1.8</maven.compiler.source> | |||||
| <maven.compiler.target>1.8</maven.compiler.target> | |||||
| <java.version>1.8</java.version> | |||||
| <maven.compiler.source>11</maven.compiler.source> | |||||
| <maven.compiler.target>11</maven.compiler.target> | |||||
| <java.version>11</java.version> | |||||
| </properties> | </properties> | ||||
| <dependencies> | <dependencies> | ||||
| <dependency> | <dependency> | ||||
| @@ -12,7 +12,7 @@ public class StartUp { | |||||
| * [不同CPU可能结果有差异,但相对大小不变] | * [不同CPU可能结果有差异,但相对大小不变] | ||||
| * 默认配置下,最佳性能是5W/s-8W/s | * 默认配置下,最佳性能是5W/s-8W/s | ||||
| */ | */ | ||||
| final static int genIdCount = 50000; | |||||
| final static int genIdCount = 500000; | |||||
| //1-漂移算法,2-传统算法 | //1-漂移算法,2-传统算法 | ||||
| final static short method = 1; | final static short method = 1; | ||||
| @@ -20,11 +20,12 @@ public class StartUp { | |||||
| public static void main(String[] args) { | public static void main(String[] args) { | ||||
| IdGeneratorOptions options = new IdGeneratorOptions(); | IdGeneratorOptions options = new IdGeneratorOptions(); | ||||
| // options.WorkerIdBitLength = 6; | |||||
| // options.SeqBitLength = 6; | |||||
| // options.WorkerIdBitLength = 6; // 默认6 | |||||
| options.SeqBitLength = 10; // 默认6 | |||||
| // options.BaseTime = 1582206693000L; | // options.BaseTime = 1582206693000L; | ||||
| options.Method = method; | options.Method = method; | ||||
| options.WorkerId = 1; | options.WorkerId = 1; | ||||
| options.TopOverCostCount=2000; | |||||
| // 首先测试一下 IdHelper 方法,获取单个Id | // 首先测试一下 IdHelper 方法,获取单个Id | ||||
| YitIdHelper.setIdGenerator(options); | YitIdHelper.setIdGenerator(options); | ||||