java中直接内存访问网卡
一些现代网卡支持直接内存访问以提高性能。我如何利用 Java 的此功能?
JVM 是否自动提供此功能,或者我是否需要在用于与该 NIC 通信的 ByteBuffer 上执行 allocateDirect?
有人有讨论这个的文档吗?
Some modern network cards support Direct Memory Access for improved performance. How can I utilize this feature from Java?
Does the JVM provide this automatically, or do I need to do an allocateDirect on the ByteBuffers that I am using to talk to that NIC?
Does anyone have documentation that discusses this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用网卡的DMA功能是操作系统的任务。 JVM 并不真正关心操作系统如何做到这一点,而只是使用操作系统的功能来与“网络接口”进行通信。
It is the operating systems task to use the DMA feature of the network card. The JVM does not really care how the OS does it, and simply uses the operating system's functions for talking to "network interfaces".
您无法在典型的桌面/服务器 JVM 中的 Java 内部执行此操作,因为这是操作系统区域,需要您接触 C 代码。查看 JNI 或 JNA 以了解如何执行此操作。请注意,如果您没有完全正确地做到这一点,这可能会使您的应用程序变得脆弱。
You cannot do this from inside Java in the typical desktop/server JVMs, as this is operating system area which requires you to reach out into C code. Go have a look on JNI or JNA to see how to do this. Please note that this may make your application brittle if you do not get this exactly right.
是的 - ankon 的答案是正确的。 Java 在沙箱中运行 - 一种虚拟机(因此,JVM 中的“VM”;Sun 实际上构建了一个物理版本 - 它在某处展示)。
Java 从来没有(有意)设计为能够到达沙箱之外,这与 ActiveX 不同,ActiveX 几乎可以在 PC 上的任何地方运行。
想想多年来 ActiveX 通过浏览器所做的所有坏事吧。您不希望 Java 发生这种情况,对吗?
Yeah - ankon's answer is right. Java operates in a sandbox - a virtual machine (hence the, "VM" in JVM; Sun actually built ONE physical version -- it's on display somewhere).
Java was never designed (intentionally) to reach outside the sandbox, unlike ActiveX, which can go just about anywhere on a PC.
Just think of all the bad things ActiveX has done over the years via a browser. You wouldn't want that to happen with Java, would you?
虽然......
您可能能够在Java中实例化一个可以访问硬件的对象(例如那些ActiveX控件之一,或者一些DLL - 您必须编写它们) , 也)。
我看到的问题是吞吐量。对于 100MB 或 1000MB 卡,JVM(请记住,这是在操作系统上运行的虚拟机,因此与硬件相比少了几层)是否有足够的速度来处理负载下的情况?您是否希望 Java 程序在修改 NIC 时保留数据(想想对系统其他部分的影响)?
此时,您可能最好用 C 语言编写解决方案的核心部分。而且,如果您仍然需要 Java 来处理这些数据,请将其放在 Java 可以访问的地方。
Although...
you might be able to instantiate an object in Java that does have access to the hardware (like one of those ActiveX controls, or some DLL, for example - which you'd have to write, too).
The problem I see is the throughput. With 100MB or 1000MB cards, would a JVM (remember, this is a VM running on an OS, so you're a couple of layers removed from the hardware) have the speed to handle what's coming in under load? Would you want a Java program holding up data in your NIC while it tinkered with it (think of the impact to the rest of the system)?
At this point, you're probably better off writing the hard-working guts of your solution in C. And, if you still need Java to play with that data, put it in a place where Java can get to it.
如果您在 Java 中没有获得所需的网络吞吐量,那么您将需要编写一个 C 包装器才能访问它。
您是否对代码进行了基准测试以找出性能问题的真正所在?如果您告诉我们,我们很可能可以帮助您,而无需诉诸 JNI。
If you're not getting the network throughput you need in java, then you're going to need to write a C wrapper in order to access it.
Have you benchmarked your code to find where your performance issues really are? If you let us know that we can likely help you out without resorting to JNI.