REASY opened a new issue, #2924:
URL: https://github.com/apache/fory/issues/2924

   ### Feature Request
   
   When Fory is used in a tight loop from multiple threads the throughput 
suffers due to high contention:
   - 
[Pool::get](https://github.com/apache/fory/blob/f57b12d7a407997373ff2d18ff56da5f741d70b1/rust/fory-core/src/resolver/context.rs#L447)
   - 
[Pool::set](https://github.com/apache/fory/blob/f57b12d7a407997373ff2d18ff56da5f741d70b1/rust/fory-core/src/resolver/context.rs#L453)
   
   The result of `cargo bench`
   ```
       Finished `bench` profile [optimized + debuginfo] target(s) in 0.19s
        Running benches/fory_contention.rs 
(target/release/deps/fory_contention-670f6a7f1f8e19ac)
   Gnuplot not found, using plotters backend
   ForyMlUseridV360Contention/single_thread_200k_serializations
                           time:   [9.2554 ms 9.2758 ms 9.2943 ms]
   Found 4 outliers among 100 measurements (4.00%)
     1 (1.00%) low severe
     3 (3.00%) low mild
   Benchmarking 
ForyMlUseridV360Contention/shared_serializer_8_threads_200k_serializations: 
Warming up for 3.0000 s
   Warning: Unable to complete 100 samples in 5.0s. You may wish to increase 
target time to 13.3s, or reduce sample count to 30.
   ForyMlUseridV360Contention/shared_serializer_8_threads_200k_serializations
                           time:   [131.53 ms 133.14 ms 134.74 ms]
   Found 1 outliers among 100 measurements (1.00%)
     1 (1.00%) low mild
   ```
   
   ## Code 
   ```rust
   fn bench_fory_ml_userid_v360_contention(group: &mut Criterion) {
       const SERIALIZATION_COUNT: usize = 200_000;
       const THREAD_COUNT: usize = 8;
   
       let mut bench = group.benchmark_group("ForyMlUseridV360Contention");
   
       // Single-thread benchmark
       let single_thread_fory = create_fory_ml();
       let single_thread_value = sample_ml_userid_v360();
       bench.bench_function("single_thread_200k_serializations", |b| {
           b.iter(|| {
               for _ in 0..SERIALIZATION_COUNT {
                   let bytes = single_thread_fory
                       .serialize(black_box(&single_thread_value))
                       .expect("serialize ForyMlUseridV360Value with Fory");
                   black_box(bytes);
               }
           });
       });
   
       // Shared serializer across multiple threads
       let shared_fory = Arc::new(create_fory_ml());
       let shared_value = Arc::new(sample_ml_userid_v360());
       bench.bench_function("shared_serializer_8_threads_200k_serializations", 
|b| {
           b.iter(|| {
               thread::scope(|scope| {
                   for _ in 0..THREAD_COUNT {
                       let fory = Arc::clone(&shared_fory);
                       let value = Arc::clone(&shared_value);
                       scope.spawn(move || {
                           for _ in 0..(SERIALIZATION_COUNT / THREAD_COUNT) {
                               let bytes = fory
                                   .serialize(value.as_ref())
                                   .expect("serialize ForyMlUseridV360Value 
with Fory");
                               black_box(bytes);
                           }
                       });
                   }
               });
           });
       });
   
       bench.finish();
   }
   ```
   
   References:
   - 
[fory_contention.rs](https://gist.github.com/REASY/736b165cfd93918aa6c746dcdcfffa02)
   
   
   
   ### Is your feature request related to a problem? Please describe
   
   _No response_
   
   ### Describe the solution you'd like
   
   _No response_
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
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