JNI与JNA性能 [英] JNI vs. JNA performance

查看:847
本文介绍了JNI与JNA性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用GPU(OpenCL)的大量加密/解密数据的原生 c / asm 一个特定的方法,它只是工作完美,没有问题。 JEE 正在开发项目的一部分(Web和发行版),我们只需要调用本机应用程序/库。

We have a native c/asm application utilizing GPU(OpenCL) for a big encrypt/decrypt data with a specific method, and it just works perfect, no problem. A part of the project (web and distribution) is been developing by JEE, and we just need to call native application/library.

我们试图使用 Process 类将它调用为一个独立的外部过程。问题是我们不能控制应用程序(事件,处理程序,线程等等)。我们还试图将C代码切换到Java代码,但性能死亡。除了运行本地代码作为进程,我正在考虑JNA和JNI,但有一些问题。

We have tried to call it as a separated-external process using Process class. The problem is that we cannot control the application(event, handlers, threads, etc...). We also tried to just switch the C code into Java code, but the performance died. Except running the native code as process, I'm thinking about JNA and JNI, but there are some questions.

问题: >

Questions:


  1. 对于更好(更快)的读/写解决方案,可以通过直接(非托管)内存来交换数据[Java(

  2. 是否可以通过本地代码来管理和处理进程,并访问GPU(共享),可以使用JNI和JNA中的字节缓冲区(例如ByteBuffer#allocateDirect()内存通过Java代码(OpenCL lib)?

  3. 性能如何? JNA是否比JNI快?

  1. For better(faster) read/write solution, is it possible to exchange data by direct(unmanaged) memory [Java(ByteBuffer#allocateDirect())] in both JNI and JNA?
  2. Is it possible to manage and handle process by native code, and access the GPU(shared) memory through Java code(OpenCL lib)?
  3. What about performance? Is JNA faster than JNI?

我们在Redhat Linux6 x64上有两个AMD W7000群集设备。

We have two AMD W7000 clustered device on Redhat Linux6 x64.

推荐答案

JNA比JNI慢得多,但更容易。如果性能不是问题,请使用JNA。

JNA is much slower than JNI, but much easier. If performance is not an issue use JNA.

使用直接缓冲区的优点是最关键的操作不使用JNI或JNA,因此更快。他们使用内在的意思,当它们变成单一的机器代码指令。

Using direct buffers have the advantage that the most critical operations don't use JNI or JNA and are thus faster. They use intrinsic when means they get turned into single machine code instructions.

如果Java代码明显比C慢,很可能代码没有被充分优化。通常GPU应该做所有的工作,所以如果Java有点慢,这不应该有太大的区别。

If Java code is significantly slower than C it is likely the code hasn't been optimised enough. Generally the GPU should be doing all the work so if Java is a bit slower this shouldn't make much difference.

例如。如果你花费99%的时间在GPU和Java花费两倍的总时间将是99 + 2%或慢1%。

e.g. if you spend 99% of the time in the GPU and Java takes twice as long the total will be 99+2% or 1% slower.

这篇关于JNI与JNA性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆