- 浏览: 425449 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
Glogo:
楼主您好,我在试验您的代码的时候发现新开的三个子线程并没有一直 ...
java 高并发 ReentrantLock -- 可重入的锁 -
univasity:
最近发觉也被限速了,投诉一下就好一会~~ 看来明天又要和电信M ...
ADSL上网速度慢 都是帐号限速惹的祸 -
liuyuanhui0301:
java 高并发 ReentrantLock -- 可重入的锁 -
dang_java:
呵.很好的说明文档.
JXTA技术与应用发展 -
helloqidi:
谢谢,学习了
SQL中exists和in的区别
Erlang memory architecture vs Java memory architecture
- 博客分类:
- JVM/内存模型/调优/排错
I read a really, really interesting article on memory management strategies for the Erlang VM. It was written as a thesis by Jesper Wilhelmsson: http://www.it.uu.se/research/publications/lic/2005-001/ I thought it might be nice to discuss the differences between Erlang's memory setup and Sun's Java VM.
As a real short introduction for those who have never heard of Erlang; it is a functional language that uses asynchronous message passing as its basis for concurrency. The message passing uses copy semantics, making distribution over more than one Erlang VM, running on more than one machine essentially transparent to the programmer.
Erlang and Java are similar in the sense that both use a virtual machine to abstract the hardware into a portable layer. Both languages employ machine independent byte code. Both run-time systems rely on garbage collection to free the programmer of doing memory management.
Threading overhead in Erlang is very low. I believe that the memory requirements for a thread in Erlang is about 512 bytes. In Java threads typically need about 512 kilobytes, about 1000 times more. For a programmer, the upshot is that creating threads to do some work asynchronously is not something you have to sit down and think about. Typical Erlang systems have thousands or tens of thousands of threads. There is no futzing with threadpools and executors like we do in Java.
From what little I have dabbled with it, I found Erlang to be a pleasant compromise between a functional language, and a language that allows you to write real-world applications. (I know I'll get flak for this) Robust distributed error handling is a pleasant surprise and writing a network server of any kind is actually easy. The state-machine approach to web servers makes rolling back on errors completely natural.
But this post is not about the programming model of Erlang. It is about the way the Erlang VM deals with memory.
The current Java virtual machine uses what an Erlang programmer would call a shared heap topology. There is one big heap that is used by all threads. Most memory is allocated on that heap. In addition to the heap, the JVM uses some specialised data areas like the code cache and the permanent generation. These too are shared between all threads.
By contrast, Erlang uses a private heap topology. Each thread has its own tiny heap that contains all data the thread uses and the thread's stack as well. All data for a thread is on that local heap. It is reserved when the thread is created. When the thread dies, the entire heap is simply returned to the pool of free memory.
Aside from the private heaps, all threads share access to a so-called binary heap and a message heap. These are specialised heaps. The binary heap is for allocating large chunks of arbitrary data that are likely to be shared between threads. This is where for example file input or network buffers live.
The message heap is a heap for data that is used in messages. Messages too are shared between processes. Messages are passed between threads by copying a pointer over from the sending thread to the receiving thread. The data for the message is stored on the message heap.
I was impressed by the Erlang memory model. It just strikes me as a lot more scalable than Java's single heap model. The language semantics and the memory model match beautifully.
For instance; the simple fact that heaps are private to a thread relieves the threads of all forms of lock checking on their own data. Add to that the fact that there are no destructive writes and suddenly there is no need for lock checking for shared data either.
The latest version of the Erlang VM take this yet another step further by having more than one scheduler. Once scheduler per physical processor to be precise. This eliminates another entire class of locks to check. Only when a scheduler is bored it needs to go out, gather a lock and get some processes off of another scheduler.
In Java, we have a lot to learn still. That said, we have a few nice things in Java that I miss working with large Erlang systems.
The Erlang VM will reallocate and grow heaps when thread accumulate a lot of data. However, the reallocation algorithm causes heap sizes to grow rapidly. Under high load, we have seen Erlang VM's eat up 16GB of RAM in a matter of minutes. Each release has to be carefully load tested to see if its memory requirements are still sane.
There are no mechanisms in the Erlang VM to curb the growth of the memory. The VM will happily allocate so much memory that the system shoots into swap, or that the virtual memory is exhausted. These may cause the machine to become unresponsive even to KVM console access. In the past we have had to power cycle machines to get access to them again.
The queue-based programming model that makes Erlang so much fun to write code for, is also it Achilles heel in production. Every queue in Erlang is unbounded. The VM will not throw exceptions or limit the number of messages in a queue. Sometimes a process stops processing due to a bug, or a process fails to keep up with the flow of messages being sent to it. In that case, Erlang will simply allow the queue for that process to grow until either the VM is killed or the machine locks up, whichever comes first.
This means that when you run large Erlang VM's in a production environment you need to have OS-level checks that will kill the process if memory use skyrockets. Remote hands for the machine, or remote access cards is a must-have for machines that run large Erlang VM's.
In summary, for every day performance I believe the private heap memory model to be a very powerful tool in Erlang's box. It cuts whole classes of locking mechanisms out of the run-time system and that means it will scale better than Java will for the same purpose. Java's hard limits on memory will save your bacon when your system is being flooded or DDoSed.
Kees Jan
PS. There is a command line switch for Erlang's VM to switch it from using the private heap topology to using the share heap topology.
PPS. I like Erlang and Java. They are hard to compare because the have so little in common for a developer. In general, I would use Java for most systems, though. Tool support is better and the number of libraries available is staggering. I would opt for Erlang in the case where I have a stream oriented messaging system. That's when the Erlang programming model really shines.
<!-- / message -->
发表评论
-
JVM 深入笔记
2012-04-12 20:36 986JVM 深入笔记(1)内存区域是如何划分的? 一个超短的前言 ... -
JVM启动参数
2011-06-10 16:27 959java [jvmargs] class [arguments ... -
JVM指令集 和 一个异常例子
2011-05-19 16:14 1015指令码 助记符 说明 0x00 nop ... -
The Top Java Memory Problems – Part 1
2011-05-18 11:01 897转载:http://blog.dynatrace.com/20 ... -
BTrace使用简介
2011-04-19 13:51 775该文转载自:http://rdc.taobao.com/tea ... -
大方法的执行性能与调优过程小记
2011-04-18 16:20 799该文章转载自:http://rdc.taobao.com/te ... -
十个最好的Java性能故障排除工具
2011-04-18 16:02 920推荐十个最好的Java性能 ... -
两个OOM Cases排查过程的分享
2011-04-18 15:39 924分享一下两个OOM Cases的查找过程,一个应用是Nativ ... -
Monitoring Java garbage collection with jstat
2011-04-18 15:28 855The original article is at : ht ... -
理解Heap Profling名词-Shallow和Retained Sizes
2011-04-18 14:58 971所有包含Heap Profling功能的工具(MAT, You ... -
Java深度历险(四)——Java垃圾回收机制与引用类型
2011-04-01 08:18 977Java语言的一个重要特性 ... -
Thread Dump 和Java应用诊断
2011-03-30 08:08 1127Thread Dump 和Java应用诊断 ... -
Memory Analysis Part 1 – Obtaining a Java Heapdump
2011-03-14 16:06 1117For troubleshooting Java memory ... -
Java Memory Leaks et al. (2. Act)
2011-03-14 15:37 921The first act of this blog-seri ... -
The Java Memory Architecture (1. Act)
2011-03-14 15:15 1409One of the biggest strength of ... -
Permanent generation
2011-03-14 14:53 1270版权声明:转载时请以 ... -
JVM内存模型以及垃圾回收
2011-03-13 09:38 966内存由 Perm 和 Heap 组成. 其中 Heap ... -
Java虚拟机垃圾回收机制
2011-03-13 09:31 821一、相关概念 基本 ... -
JVM结构
2011-03-10 14:43 886类文件格式 JVM使用一 ... -
OOM与JVM(转)
2009-03-24 15:49 954OOM与JVM(转) 2008年08月08日 星期五 15: ...
相关推荐
标题中的“Erlang-or-java.rar_erlang”表明这是一个关于Erlang和Java之间通信的示例项目。Erlang是一种面向并发、分布式、容错的编程语言,常用于构建高可用性和高并发性的系统,而Java则是一种广泛应用的通用编程...
`Erlang`和`Java`都是在各自领域有着独特优势的语言。`Erlang`以其强大的并发处理能力和容错性著称,而`Java`则有丰富的库支持和广泛的企业级应用。将两者结合,可以充分利用它们的优势。本文将详细探讨如何在`...
【Erlang与Java交互实现聊天程序】 在IT领域,Erlang和Java都是重要的编程语言,各有其独特的优点和应用场景。本项目“erlang-java聊天”是一个初级水平的示例,展示了如何利用这两种语言进行交互,实现一个简单的...
6. **项目学习与实践**:通过研究Erlang_Architecture_Behaviours-master中的源码,开发者可以学习如何在Erlang中实现这些架构,理解如何使用Erlang的特性来构建高可用、高性能的系统。此外,这个项目也可以作为模板...
本文将深入探讨Java、PHP、Python和Erlang这四种语言在处理千万级内存数据时的性能差异。 首先,让我们从Erlang开始。Erlang是一种并发性极强的函数式编程语言,特别适合构建分布式、容错系统。在提供的文件"erlang...
Erlang核心开发者Lukas Larsson在2014年3月份Erlang Factory上的一个演讲详细介绍了Erlang内存体系的原理以及调优案例 根据siyao zheng博客上听写的资源进行的翻译,大致只翻译了80%但核心部分已经完整,希望对大家...
本系统是基于erlang开发的后台,java swing开发的前端的qq聊天系统,希望能给初学erlang的人带来一点小小的帮助,具体操作步骤见redme.txt文件 功能如下: 功能: 1.用户登录功能,账号和密码从服务端的mysql数据库...
**Erlang编程:Introducing Erlang** Erlang是一种函数式编程语言,由爱立信在1986年开发,主要用于构建高可用性、容错性和并发性的分布式系统。"Introducing Erlang"是Simon St. Laurent撰写的一本入门级教程,...
- **BEAM虚拟机**:Erlang的运行时系统,全称是BIFs (Built-In Functions)、Erlang、Assembler and Memory管理器。 - **OTP行为**:如Supervisor(监督者)、GenServer(通用服务器)、GenEvent(事件处理器)等,...
本项目提供了一个使用Erlang编写的聊天室服务器端代码以及Java编写的客户端代码,这为我们深入理解Erlang的并发特性和Java与Erlang的交互提供了实践案例。 一、Erlang聊天室服务器端 1. 并发处理:Erlang的轻量级...
标题中的"C#版ErlangOtp跨平台通信框架(Java版的转译)"指的是一个用C#语言实现的框架,其目标是提供与Erlang OTP系统进行跨平台通信的能力。Erlang OTP(开放电信平台)是Erlang编程语言的一个核心组件,它包含了一...
本项目“基于Erlang的文件存储”就是这样一个尝试,它利用Erlang强大的并发处理能力和分布式特性,为服务端提供稳定的基础架构,而客户端则通过Java的Swing组件提供用户友好的交互界面。以下是对该项目中涉及的技术...
6,安装失败,你骂我好了,并把你的ubunt版本、是否是在虚拟机和其下的虚拟机软件名称和版本与再其下的os名称和版本、硬件(cpu、memory、Mainboard、disk)等信息email给我,我帮你找能用的版本。 软件相关信息: ...
5. **Jinterface**:Jinterface是Erlang和Java之间的互操作库,它允许Erlang进程与Java虚拟机(JVM)中的对象进行通信。这对于既有Java基础又想利用Erlang优势的开发者来说,是一个强大的工具。 6. **Eclipse插件...
### Erlang中的Module级别热部署 #### 一、引言 Erlang 是一种专为构建高并发、容错性强的分布式系统而设计的编程语言。它的独特之处在于支持轻量级进程(也称为协程)和热部署能力。本文将深入探讨Erlang 中的 ...
8. **Erlang与其他技术的集成**:Erlang可以与其他语言如Java、Python等集成,用于构建混合系统。例如,使用Erlang的Ranch和Cowboy库可以构建高性能的Web服务器和API。 9. **实时性与并发性**:Erlang的实时性使其...
erlang安装包
Erlang/OTP 26.2.1,Erlang,OTP,26.2.1
Erlang是一种高级编程语言,特别适用于并发、分布式和实时系统。它由Ericsson公司开发,主要用于构建高可用性、容错性和可扩展性的软实时系统。Erlang的25.0版本是该语言的一个更新,针对Windows操作系统进行了优化...
这个“erlang资源”包含两本PDF书籍——《Erlang并发编程》和《Erlang入门手册》,它们是深入理解和学习Erlang语言的关键资料。 《Erlang并发编程》这本书可能涵盖了以下知识点: 1. **并发模型**:Erlang的并发...