Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Mar 5, 2024 · 1 comment · Fixed by #452
Assignees
Labels
enhancement New feature or request java Pull requests that update Java code KNet KNet related issue .NET Pull requests that update .net code

Comments

@masesdevelopers
Copy link
Contributor

          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:

  • JVM makes a copy of the data before send it to JNI and replace back the object data when JNI returns: so there are multiple copies of data during data exchange;
  • JVM Garbage Collector: some JNI methods can impact the GC operations since, depending on JVM implementation, the GC can pin or copy array of primitive types.

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 #53 (comment)

@masesdevelopers masesdevelopers self-assigned this Mar 5, 2024
@masesdevelopers masesdevelopers added enhancement New feature or request KNet KNet related issue java Pull requests that update Java code .NET Pull requests that update .net code labels Mar 5, 2024
@masesdevelopers
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request java Pull requests that update Java code KNet KNet related issue .NET Pull requests that update .net code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant