masesgroup / KNet

KNet is a comprehensive .NET suite for Apache Kafka™ providing all features: Producer, Consumer, Admin, Streams, Connect, backends (ZooKeeper and Kafka).
https://knet.masesgroup.com/
Apache License 2.0
32 stars 6 forks source link

Many KNet operations can, or cannot, be impacted during JNI operations because data can, or cannot, be the copy of the data available in the JVM. #434

Closed masesdevelopers closed 1 month ago

masesdevelopers commented 4 months ago
          Many KNet operations can, or cannot, be impacted during JNI operations because data can, or cannot, be the copy of the data available in the JVM. 

As stated in https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html JVM can decide to copy, or pin, data depending on its internal implementation.

The data transfer used in KNet is based on JNI and the results of some benchmarks seems impacted from the following hypothesis:

Current benchmarks are based on byte array to reduce exogenous interference (like the implementation of the serializers) and in general KNet specific implementation (KNetConsumer, KNetProducer, KNet Streams SDK, etc) uses byte array.

Maybe a better data exchange can be obtained reducing the number of array copies done during execution. An issue will be opened to investigate on this possible evolution, meanwhile this issue is reopened.

Originally posted by @masesdevelopers in https://github.com/masesgroup/KNet/issues/53#issuecomment-1979330526

masesdevelopers commented 4 months ago

A possibility to reduce the memory copy at CLR-JVM boundary comes from the use of ByteBuffer and especially, if it is supported, from the allocateDirect method. allocateDirect creates a memory area generally used from off-heap operations. However to verify this opportunity an enhancement shall be done on JNet because ByteBuffer is managed in that project and shall be found a way to access the memory allocated from the JVM directly from the CLR.