Tencent / TencentKona-8

Tencent Kona is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-term support(LTS) with quarterly updates. Tencent Kona serves as the default JDK internally at Tencent Cloud for cloud computing and other Java applications.
Other
938 stars 146 forks source link

Transplant jmh test Skynet.java from Loom #119

Closed youyou0805 closed 1 year ago

youyou0805 commented 1 year ago

Main changes

1.Create a standalone Maven project to meet the needs of JMH 2.To make it compatible with KonaJDK8, replace the keyword var with the corresponding type when declaring variables.

Detailed diff output

diff --git a/Skynet.java b/Skynet.java
index a9255dd..b64ef58 100644
--- a/Skynet.java
+++ b/Skynet.java
@@ -20,7 +20,8 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
-package org.openjdk.bench.loom;
+package com.example;

 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.BenchmarkMode;
@@ -46,7 +47,7 @@ import java.util.concurrent.TimeUnit;
 @SuppressWarnings("preview")
 public class Skynet {

-    @Param({"1000000"})
+    /*
+    * The original default value of 1,000,000 for this parameter would cause excessive computational
+    * overhead and memory usage during training, resulting in a program that cannot run successfully.
+    * To maintain stability and ensure successful execution, we set a smaller default value of 100,000 instead.
+    */
+    @Param({"100000"}) 
     public int num;

     static class Channel<T> {
@@ -89,9 +90,9 @@ public class Skynet {

     static void skynet(Channel<Long> result, int num, int size, int div) {
         if (size == 1) {
             result.send((long) num);
         } else {
-            var chan = new Channel<Long>();
+            Channel<Long> chan = new Channel<>();
             for (int i = 0; i < div; i++) {
                 int subNum = num + i * (size / div);
                 Thread.startVirtualThread(() -> skynet(chan, subNum, size / div, div));
@@ -106,7 +107,7 @@ public class Skynet {

     @Benchmark
     public long skynet() {
-        var chan = new Channel<Long>();
+        Channel<Long> chan = new Channel<>();
         Thread.startVirtualThread(() -> skynet(chan, 0, num, 10));
         return chan.receive();
     }
tencent-adm commented 1 year ago

CLA assistant check
All committers have signed the CLA.

miao-zheng commented 1 year ago
  1. 在comment里列出来,这个文件和loom的原始文件的git diff结果;
  2. 上次讨论过,num是100万的时候,可能会出现out of memory的问题,后续进展如何?
youyou0805 commented 1 year ago
  1. 在comment里列出来,这个文件和loom的原始文件的git diff结果;
  2. 上次讨论过,num是100万的时候,可能会出现out of memory的问题,后续进展如何?
  1. git diff结果已列出
  2. 之后我尝试了在不同的设备上运行程序,但是问题仍然无法得到解决,所以测试时不得不降低Param值。正如老师您上次开会时所说的那样,loom不会有这样的问题,num可以达到100万。
miao-zheng commented 1 year ago

可以把这个num改小一点

youyou0805 commented 1 year ago

可以把这个num改小一点

好的

miao-zheng commented 1 year ago

文件目录改为demo/fiber/loom/Skynet