注册

Erlang R15的内存delayed dealloc特性对消息密集型程序的影响

在新的NUMA体系结构下,每个CPU都有自己的本地内存,如果要访问其他CPU的内存,那算remote了,要走CPU之间的QPI通道,通常这样速度会有40%的下降。
那么对于多线程的程序来讲,这个硬件的变化对软件也有很大的影响。在多线程程序里面,通常一个线程会为一个对象分配内存,然后把这个对象传递到不同的线程去使用,最后由其他线程释放内存。而这二个线程可能在不同的CPU上运行,这个场景很普遍,比如说Erlang的消息机制。如果谁创建谁释放对象,提高内存倒腾的效率,那么对于消息密集型程序会有很多帮助。

R15的最大的运行期优化见: 这里
这个特性也就是之前声称的delayed dealloc特性
对照下OTP团队之前的规划:


屏幕快照 2015-04-20 下午6.45.36.png



目前规划里面的1,2,3,4在R15里面都已经实现了。

Optimize memory allocation

A number of memory allocation optimizations have been implemented. Most
optimizations reduce contention caused by synchronization between
threads during allocation and deallocation of memory. Most notably:
* Synchronization of memory management in scheduler specific allocator
instances has been rewritten to use lock-free synchronization.
* Synchronization of memory management in scheduler specific
pre-allocators has been rewritten to use lock-free synchronization.
* The ‘mseg_alloc’ memory segment allocator now use scheduler specific
instances instead of one instance. Apart from reducing contention
this also ensures that memory allocators always create memory
segments on the local NUMA node on a NUMA **.

我们来尝鲜演示下,首先设计个消息密集型的程序:

抱歉由于刚才的POST**案例设计不合理,重新设计过,敬请期待。。。

已邀请:

要回复问题请先登录注册