What is the correct way of doing Java IPC through /dev/shm (with the lowest possible latency)(通过/dev/shm执行Java IPC的正确方式是什么(具有尽可能低的延迟))
问题描述
我正在尝试通过/dev/shm编写IPC解决方案。
@SK-logic在这里的评论中给了我一些指示:Chronicle: How to optimize memory-mapped files for low-latency?
我的疑问是:我应该使用MappedByteBuffer还是只使用普通的FileChannel?
通过MappedByteBuffer,我可以使用sun.misc.Unsafe并可以直接访问内存。这很棒,因为Unsafe提供了像getLongVolatile(除了getLong)和putLongVolatile(除了putLong)这样的方法。如果我使用普通的FileChannel,这可能吗?如何避免从FileChannel读取FileChannel从CPU缓存中读取缓存数据?对于/dev/shm中的易失性读写,我是否必须在操作系统中配置某些内容?什么?哪里?如何?:)
/dev/shm执行Java IPC的正确方式是什么?普通文件频道?MappdByteBuffer?
下面我如何通过sun.misc.Unsafe获取指向内存的指针:
try {
this.raf = new RandomAccessFile(file, "rw");
this.fileChannel = raf.getChannel();
this.mappedBuffer = this.fileChannel.map(MapMode.READ_WRITE, 0, size);
} catch (Exception e) {
throw new RuntimeException("Could not mmap file to memory: " + filename + " " + size, e);
}
try {
addressField = Buffer.class.getDeclaredField("address");
addressField.setAccessible(true);
this.pointer = (long) addressField.get(this.mappedBuffer);
} catch(Exception e) {
throw new RuntimeException("Could not get off-heap pointer!", e);
}
推荐答案
历史记录队列使用Unsafe对堆和直接内存进行线程安全内存访问。
与其自己编写所有这些内容,为什么不尝试使用编年史地图或队列来为您完成这些工作呢?
这篇关于通过/dev/shm执行Java IPC的正确方式是什么(具有尽可能低的延迟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过/dev/shm执行Java IPC的正确方式是什么(具有尽可能低的延迟)
基础教程推荐
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
