j9kkk opened a new issue, #1630:
URL: https://github.com/apache/incubator-fury/issues/1630

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/incubator-fury/issues) and found no similar 
issues.
   
   
   ### Version
   
   os:windows 10
   java: 1.8.0_271
   fury:
   <groupId>org.apache.fury</groupId>
   <artifactId>fury-core</artifactId>
   <version>0.5.0</version>
   
   ### Component(s)
   
   Java
   
   ### Minimal reproduce step
   
   
   `package com.example.test;
   
   import lombok.extern.slf4j.Slf4j;
   import org.apache.fury.BaseFury;
   import org.apache.fury.Fury;
   import org.apache.fury.ThreadSafeFury;
   import org.apache.fury.config.Language;
   import org.junit.Test;
   
   @Slf4j
   public class TestFury {
       final int COUNT = 100000000;
   
       private void benchmark(BaseFury fury) {
           long start = System.nanoTime();
           for (int i = 0; i < COUNT; i++) {
               User user = new User("John", "Doe", 30);
               byte[] serialize = fury.serialize(user);
               Object deserialize = fury.deserialize(serialize);
           }
           long end = System.nanoTime();
           long elapsed = end - start;
           log.info("Elapsed time: {} ns, tps= {} /s", elapsed, 
String.format("%.2f", COUNT / (elapsed / 1e9)));
       }
   
       @Test
       public void testFury() {
           Fury fury = Fury.builder().withLanguage(Language.JAVA)
                   // Allow to deserialize objects unknown types, more flexible
                   // but may be insecure if the classes contains malicious 
code.
                   .requireClassRegistration(true)
                   .build();
           // Registering types can reduce class name serialization overhead, 
but not mandatory.
           // If class registration enabled, all custom types must be 
registered.
           fury.register(TestFury.class);
           fury.register(User.class);
   
           benchmark(fury);
       }
   
       @Test
       public void testMultiFury() throws InterruptedException {
           ThreadSafeFury fury = Fury.builder().withLanguage(Language.JAVA)
                   // Allow to deserialize objects unknown types, more flexible
                   // but may be insecure if the classes contains malicious 
code.
                   .requireClassRegistration(true)
                   .buildThreadSafeFury();
           fury.register(TestFury.class);
           fury.register(User.class);
   
           int threads = Runtime.getRuntime().availableProcessors();
           for (int i = 0; i < threads; i++) {
               new Thread(() -> {
                   benchmark(fury);
               }).start();
           }
   
           Thread.currentThread().join();
       }
   
   }`
   
   
   `package com.example.test;
   
   class User {
       private String firstName;
       private String lastName;
       private int age;
   
       public User(String john, String doe, int i) {
           this.firstName = john;
           this.lastName = doe;
           this.age = i;
       }
   }`
   
   ### What did you expect to see?
   
   单线程与多线程序列化反序列化性能一致
   
   ### What did you see instead?
   
   `2024-05-14 12:38:58 INFO  Fury:144 [main] - Created new fury 
org.apache.fury.Fury@624ea235
   2024-05-14 12:38:58 INFO  Fury:144 [Thread-3] - Created new fury 
org.apache.fury.Fury@4ff7ff2e
   2024-05-14 12:38:58 INFO  Fury:144 [Thread-2] - Created new fury 
org.apache.fury.Fury@60bfb620
   2024-05-14 12:38:58 INFO  Fury:144 [Thread-6] - Created new fury 
org.apache.fury.Fury@7ff887
   2024-05-14 12:38:58 INFO  Fury:144 [Thread-4] - Created new fury 
org.apache.fury.Fury@44de8d4a
   2024-05-14 12:38:58 INFO  Fury:144 [Thread-5] - Created new fury 
org.apache.fury.Fury@159886f2
   2024-05-14 12:38:58 INFO  Fury:144 [Thread-7] - Created new fury 
org.apache.fury.Fury@1d5fc898
   2024-05-14 12:38:58 INFO  Fury:144 [Thread-1] - Created new fury 
org.apache.fury.Fury@47540be1
   2024-05-14 12:38:58 INFO  Fury:144 [Thread-8] - Created new fury 
org.apache.fury.Fury@69b38d00
   24/05/14 12:39:28.896 [INFO ] 23 com.example.test.TestFury[23] - Elapsed 
time: 29918667800 ns, tps= 3342394.81 /s 
   24/05/14 12:39:30.318 [INFO ] 23 com.example.test.TestFury[23] - Elapsed 
time: 31341023100 ns, tps= 3190706.30 /s 
   24/05/14 12:39:33.827 [INFO ] 23 com.example.test.TestFury[23] - Elapsed 
time: 34851435100 ns, tps= 2869322.30 /s 
   24/05/14 12:39:34.476 [INFO ] 23 com.example.test.TestFury[23] - Elapsed 
time: 35503676500 ns, tps= 2816609.71 /s 
   24/05/14 12:39:35.605 [INFO ] 23 com.example.test.TestFury[23] - Elapsed 
time: 36628779700 ns, tps= 2730093.68 /s 
   24/05/14 12:39:36.613 [INFO ] 23 com.example.test.TestFury[23] - Elapsed 
time: 37636506500 ns, tps= 2656994.75 /s 
   24/05/14 12:39:36.622 [INFO ] 23 com.example.test.TestFury[23] - Elapsed 
time: 37644876100 ns, tps= 2656404.01 /s 
   24/05/14 12:39:36.769 [INFO ] 23 com.example.test.TestFury[23] - Elapsed 
time: 37792022400 ns, tps= 2646061.09 /s 
   
   
   2024-05-14 12:38:36 INFO  Fury:144 [main] - Created new fury 
org.apache.fury.Fury@29626d54
   2024-05-14 12:38:36 INFO  CompileUnit:55 [main] - Generate code for 
com.example.test.UserFuryCodec_1_414493378_1516500233 took 71 ms.
   2024-05-14 12:38:36 INFO  JaninoUtils:121 [main] - Compile 
[UserFuryCodec_1_414493378_1516500233] take 265 ms
   24/05/14 12:38:58.959 [INFO ] 23 com.example.test.TestFury[23] - Elapsed 
time: 22694408600 ns, tps= 4406371.71 /s 
   `
   
   问题
   1. 多线程tps约为单线程tps一半
   2. 多线程之间tps结果差异较大
   
   
   ### Anything Else?
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [ ] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to