`
cookoo
  • 浏览: 646386 次
  • 性别: Icon_minigender_1
  • 来自: Shanghai
社区版块
存档分类
最新评论

[fwd]Why I Chose Erlang

    博客分类:
  • FP
阅读更多
Why I chose erlang (very, very long story)

http://www.erlang.org/ml-archive/erlang-questions/200302/msg00013.html

I've been following the discussions about OTP the past few days and found
the comments by various participants particularly enlightening. It's
always nice to observe a lively discussion -- so much can be learned. I
thought I'd throw in my opinions as to why I am using erlang. I hope they
are useful to someone, especially the Ericsson Product Manager.

My background is rather varied having started with Basic, assembler and
RPG, before moving on to APL, Prolog, Pascal, Forth, Smalltalk-80, Modula-2
(on the Lilith), then those halcyon days of Symbolics LISP with Flavors &
Z-macs (an editor without meta-, hyper-, and super- seems so limited),
Expert Systems and other AI techniques, a rude introduction to C on Sun
(why is this new concept of memory allocation necessary?), followed by C++,
OODBs, CLOS with MOP (MOP being the main reason why OO was so interesting
in the first place -- why, oh why, was it eliminated in future OO
languages, just to allow mere mortals with no passion for programming to
have access to the Gospel?), Perl, Javascript, Java, Python, Ruby (now that
is a fine OO language for small problems) and now erlang.

I am first and foremost a language dilettante, but when I find one that is
useful I work with it to discover what is different about it and in what
situations it might apply. I have written small things (compared neural
net implementations in Pascal, spreadsheet macros and APL, a mini-SECD
machine in assembler on TRS-80) to large things (traditional
business/banking/manufacturing inventory/accounting/personnel systems,
aerospace message-based OODB applications, a Perl program that
automatically loaded a structured database from English text free-formatted
OCRed resumes) to Internet things (webserver / gameserver, meta-search
tools, html generators, data extraction systems). Unfortunately, a job
often dictates the language and the problem so my useful efforts have been
limited.

My observations about languages:

1) Spend a little time evaluating and toss quickly those that you don't like
2) Toy problems are designed to make a language look good or to point out
its strongest features
3) Fiddling with your own toy problems highlights issues of a language
relevant to your use of it
4) Until you implement a real problem you can't understand the language
5) Until you hit the limits of applicability you aren't proficient in a
language
6) A language will subliminimally and fundamentally alter your perception
of a problem
7) Don't believe the hype
8) The proper or improper design of data structures can make a problem
range from trivial to unsolvable; ease of expressing and redesigning data
structures is essential to solving real problems

#6 is most apparent if you compare any combination of a functional
language, imperative language, constraint-base language, rule-based
language, OO language, dataflow lnaguage, pattern-based language or any
other paradigm to the same problem. Another easy way to see #6 is to
discover the right language for a problem, solve it elegantly and then try
to talk to a C, C++, or Java programmer about the problem.

I have always been partial to recursive languages, functional languages,
and pattern-based languages (I even played around a little with REFAL on
that last note). A combination of these attributes are more natural and
readable to my sensibilities. Others may have their own conceptual and
readability biases.

As an aside: I hate statically typed languages, and so-called OO languages
where the data have no type, but the containers you put them in have type
and forces same on its data. I never understood the usefulness of a
language that dictates if you take your laptop to the library it magically
becomes a book and has no notion that it was ever anything else.


What attracted me to erlang:

I have been building a webserver / gameserver for the last 4 years on and
off in my spare time (see www.5x5.net) out of general curiosity to
understand all aspects of eCommerce from the technology underlying the
gamesite, to the marketing, advertising, and business implications of an
Internet only company, but also because I saw that the mega-media companies
were taking over the Internet and service providers and I wanted to have my
own capability that couldn't be usurped by the software vendor or service
provider. At the time I thought Java was mature enough to support what I
wanted to do, but it did have a couple limitations, including the fact that
each simultaneous player had to have a separate thread (no support for
non-blocking threads). I thought this would be challenging and teach me a
little about threaded programming, but without the headaches of a C or C++
approach.

After about 30K lines of Java in both applets and Tomcat servlets I was
nearly ready to launch the website. I had built all the user account
management, registration, demographics, automated email, MySQL web-based
management tools (so I could manage the site from work or from home), and
the gameserver (designed to deliver HTML pages, applets and ads all from
the same IP address and port to tunnel through firewalls and deliver ads
directly to the applet), and started an Alpha test. After 3-4 days the
thread that reports when people enter and leave game rooms stopped
responding. It didn't crash but it didn't do any more work. All other
threads worked fine with ads, webpages and HTML still being
delivered. Somehow it starved.   After 4 weeks or so, Tomcat stopped
running servlets intermittently. The logfiles had a message that the JVM
could no longer spawn new threads (is that Java, Linux or Tomcat with the
problem?).

I had built some kickstart scripts and cronjobs that would attempt to
restore freezes, etc. (oooh, this sounds too much like Microsoft and IBM's
"self-healing" software), but it all seemed so hokey and unnecessary -- and
still didn't solve the problem of giving me a remotely administerable
non-stop server. Whenever the server came down all users in the gamerooms
would freeze or get booted from their applets. There was no redundancy,
distributed processing or fault tolerance. The latter was my mistake in
the message protocol because it was possible to lose one message and not
know the state of the game or be able to rejoin and reproduce without
leaving the table and disrupting it for everyone else. I learned quite a
bit, including Visual Age Java, but only enough to believe that while Java
could solve the problem, it was the wrong language -- I felt I had hit its
limits for this application. In desperation I abandoned the project and
started browsing the web listlessly for several months.

The main issues with Java boiled down to:

1) Threads are much easier than C, but still a royal pain
2) There are no useful tools for administering a server that I built
3) The OO straight-jacket is a major hindrance to web-based computing
4) There is no fault tolerance or distributed computing, the VM is heavy
and flaky
5) The use of Java applets put a heavy constraint on the server in
delivering content
6) Performance was always a concern, especially handling thousands of threads
7) Embedded capabilities were just being developed and not stable or
performing well

When I came across erlang it was obvious that #3 was solved straight
away. The biggest pain was in message passing. Messages had to be
received as a generic Msg type, a jump table based on the first byte was
used to get a msg handler, which in turn parsed, converted and cast the
message as the right object type (hopefully). Fighting the static type
checking of the compiler every step of the way, I successfully created
type-less objects and a functional callback implementation that resulted in
a remote object (which of course had no knowledge or state corresponding to
the originating object's environment space). All this immediately
disappears and becomes natural with a functional approach, the first
solution that you would attempt rather than the last futile try.

Threading seemed to be completely a non-issue in erlang, with the added
benefit that every user could be a separate process in addition to the game
table itself, leading to an automatic distributed, fault-tolerant approach
of losing only one game room rather than the entire server in a failure
situation (and even the possibility that a game room fails but the game may
continue on a new instance of a game room). I could freely add servers to
allow more players without any more effort than the load-balancing
aspect. The lighter VM solved #4, and the lightweight processes solved #6
beyond my wildest dreams (probably even beyond my ability to design a
meaningful UI for 50,000 game tables per server).

#5 was now not as great a concern because the load-balancing reduces the
strain created by the Java applets. The trick is just faking them into
believing everything is coming from the same server, or transparently
relocating the user before delivering the applet.

I have been reading the docs, fiddling around and have started
reimplementing the server. I am getting 5-10 times code reduction with an
incredible increase in code clarity. HTML and the pattern-based functional
style are the perfect marriage. This brings back the happy days of LISP,
but I find the code much more readable and the language concepts more
succinct for this problem set than LISP was. The beauty of erlang is that
it is small, clear and succinct and therefore implements problems clearly
and efficiently.

I've spent the last 4 months or so following the email list and reading
docs. The learning curve for the full system is steeper than most every
language I've pursued except the most interesting/useful ones:
Smalltalk-80, Common LISP Object System with the Meta Object Protocol, and
Java. Java may prove to be the largest and least useful of the set, its
usefulness mainly is in improving on the C++ experiment. (Ada has to be
the absolutely least useful steep learning curve language because it was
designed by committee and not to solve any particular problem). The
learning curve on the language itself is practically nil if you've ever
used a functional language before, and if you haven't erlang promises the
greatest hope that you ever will.

OTP. The raging debate about this was the most informative thing I've read
over the last few months, aside from those postings that corrected all my
misperceptions of erlang the language. I decided to invest the time in
erlang rather than skip over it like I did Mozart OZ, precisely because OTP
was present. I have never seen anything like it, and it solved exactly the
problem that I did not want to waste my time on -- developing another Java
/ Linux application set for managing the server. That task would have been
bigger than the gameserver itself that had taken me way too long already.

I believe OTP provides me:

1) Embedded turnkey system using SASL, reboot and all that
2) Non-stop server using supervision trees
3) Failover and takeover for seamless, continuous gameplay during server
maintenance
4) Distributed debugging and logging that can be turned on and off at will
5) A complicated build, but with the result of hotcode version upgrade
6) Mnesia distributed database, with in memory and on disk capabilities
7) Pre-built behaviours that match my problem set

Maybe I'm mistaken in evaluating based on the documents, and I'll find out
that I'm not capable of making OTP work, but it has more promise than
anything I've seen. OTP solves problems that I've not seen examples of
having been solved before. I'm learning and the best way to learn is to
take a real problem, push the limits and see where things break. In 6
months I should know. When I'm done with all this, I expect to be able to
have gained knowledge enough that when someone asks me "Can A or B be
done?" I can reply based on first-hand experience and have the confidence
that if I say yes, I would be capable of delivering what was asked. In 5
years I may have to roll my own OTP; maybe I'll be deep in the source code
6 months from now figuring out how to roll my own. If I was still stuck
with Java, I would be spending my time at the beach instead.

Besides all that, erlang has got me excited about programming again. I'm
trying to figure out how to sneak a prototype into my job to convert them
as well. Right now, my day job is programming stock trading systems for
mutual fund administrators using a homebrew rule-based dataflow language
that no one seems to want any more (the language was developed there long
before I arrived). Guess what, the problem requires non-stop, distributed,
fault-tolerant, constraint-based, functional capabilites, with in memory
DB, distributed logging, failover and realtime interactive monitoring,
querying and progress reporting. Sounds like a job for erlang and OTP
(Online Trading Platform). As a programmer, I really could care less what
it is called, does it solve my problem in a way that I enjoy coding and
maintaining?

P.S. The Telephony of OTP did really put me off and delayed my looking
into the capability until my problem made it apparent this was really
useful. From a marketing standpoint a name is needed, as well as a
separation between the language and the platform. More would download and
play with the language. Only those with a real need will download the
platform.


Sorry for the loss of bandwidth. Had to drop in my 20,000 drachmas worth.

jay

分享到:
评论
1 楼 cookoo 2006-11-13  
Absolutely interesting and "Until you hit the limits of applicability you aren't proficient in a language" is very true. I'm looking forward to his success story in near future.

Another, I've seen people describing that using static typing is like a fight several times and earily today Robbin and I debated together in a post showing facts that enterprise software development is far from being dominated by static languages. Of course, static langauges are useful for accessing legacy codes/libraries, system-level programming or simply for raw speeds. I'm still a right-tools-for-the-job believer.

相关推荐

    插件 ISearch

    使用方法: 1、打开QQ安装目录的Bin文件夹(就是QQFun的IPShow组件所在的目录),然后建立一个“IPlugins”的文件夹(如果已有无需建立),将插件DLL及配置文件等放进去即可。 2、登陆QQ客户端后,打开一个群聊天...

    fwd:FWD-Web应用程序的便捷环境

    烟花网注意- fwd是死的,万岁 FWD项目已中止,转而使用我们的新解决方案 。 FWD为开发团队利用Docker容器进行本地开发提供了很多帮助。 kool现在以更大的功能和灵活性继续执行相同的任务,它的目标是使个人和团队...

    Fwd_ 计算机英语词汇Fwd_ 计算机英语词汇

    Fwd_ 计算机英语词汇Fwd_ 计算机英语词汇

    dpdk18版本下l2fwd自定义修改目的mac地址

    然后放入l2fwd文件夹中。 编译如下: # export RTE_SDK=/root/dpdk # export RTE_TARGET=build # make CC main.o LD l2fwd INSTALL-APP l2fwd INSTALL-MAP l2fwd.map 适配dpdk-17.11.1,命令通过新增-d指定...

    dpdk17版本下的l2fwd支持目的mac地址手动修改

    LD l2fwd INSTALL-APP l2fwd INSTALL-MAP l2fwd.map 适配dpdk-17.11.1,命令通过新增-d指定端口的dmac。 ./build/l2fwd -c 3 -n 2 -- -p 3 -d 11:11:11:11:11:11 -d 22:22:22:22:22:22 Port0的dmac为: 11:11:...

    FWD V101文件.zip_FWD UD_K60头文件

    "FWD V101文件.zip_FWD UD_K60头文件"这个标题暗示了这是一个与FWD(可能是某个软件框架或库)的版本V101相关的压缩包,其中包含了UD(用户定义)部分针对K60微控制器的头文件。在嵌入式系统开发中,头文件通常包含...

    fwd.zip_NOISE_fwd

    "fwd.zip_NOISE_fwd" 提供的功能文件是专门用于生成图像噪声的工具。这个功能可能对研究图像噪声特性、测试去噪算法或理解噪声对图像质量影响的研究人员非常有用。 噪声通常指的是图像中不期望存在的随机变化,可以...

    DPDKL2fwd代码走读报告(代码流程分析).pdf

    DPDKL2fwd代码走读报告(代码流程分析) DPDK(Data Plane Development Kit)是一种高性能的网络数据包处理平台,能够在通用x86服务器上实现高速网络数据包转发。该平台通过使用hugepage、uio、zero copy、cpu ...

    fwd_solve.doc

    《fwd_solve.doc》文档涉及了多个IT领域的知识点,主要集中在MATLAB编程、EIDORS库的使用、有限元方法(FEM)以及图像处理软件Avizo的运用。下面将逐一详细解析这些内容。 首先,`fwd_solve`是MATLAB中的一个函数,...

    Fwd: Extension-crx插件

    Fwd:文本,Fwd:链接,Fwd:图像,Fwd:捕获-保存您访问Fwd:Wiki的任何网站中的数据。 Google Meet出勤报告(具有自动允许/无依赖性),您可以将Meets组织到组中-添加| 编辑 删除以HTML文件格式下载报告或推送至...

    fwd.zip_Centroid

    在这个场景中,"fwd.zip_Centroid" 提供的资料可能是一个关于如何计算和应用对象点集的质心(Centroid)的教学或实例。 首先,让我们深入理解什么是质心。质心是几何对象所有点的平均位置,可以视为物体在均匀密度...

    海康威视DS-2CD8264FWD-EI 升级包

    软件版本 V4.0.1build 120508 DSP 版本 V4.0 build 120508

    爱普生Epson TX820FWD 清零软件

    爱普生Epson TX820FWD是一款多功能一体机,集打印、扫描、复印和传真功能于一身,常被家庭和小型办公室用户所使用。然而,随着时间的推移,打印机内部的计数器可能会逐渐积累,导致打印质量下降或者出现错误提示。...

    dpdk 开发实例,l2fwd 端口转发实例

    dpdk 开发实例,l2fwd 端口转发实例,数据平面开发套件(DPDK [1] ,Data Plane Development Kit)是由6WIND,Intel等多家公司开发,主要基于Linux系统运行,用于快速数据包处理的函数库与驱动集合,可以极大提高数据...

    海康IPC 网络摄像机DS-CD4026FWD SDK及DEMO

    海康威视(Hikvision)的IPC(网络摄像机)是安防监控领域的热门产品,其DS-CD4026FWD型号是一款备受青睐的网络摄像机。该产品不仅在市面上广泛应用,还为开发者提供了丰富的资源,以满足不同层次的二次开发需求,...

    websocket_FWD.rar

    此外,为了提高性能和可扩展性,可能还需要考虑多线程或异步I/O模型,使得服务端可以同时处理多个客户端连接。 总结来说,"websocket_FWD.rar"中的C++ WebSocket服务端项目是一个不依赖第三方库的自实现,它涵盖了...

    Fwd.zip_zip

    【标题】"Fwd.zip_zip" 提到的文件是一个压缩包,它采用了 ZIP 文件格式,这是最常用的文件压缩格式之一。ZIP 格式允许用户将多个文件或文件夹打包成一个单一的文件,便于存储、传输和管理。"Fwd" 可能暗示这是一个...

    FWD FWD FWD-crx插件

    将社交媒体分享到正确的环境中。 当此扩展名侦听来自Facebook上经常共享的网站的链接时,该链接的标题将以FWD:FWD:FWD:为前缀。 支持语言:English

    dpdk l2fwd 示例代码改造支持arp 响应,支持ping 包

    dpdk l2fwd 示例代码改造支持arp 响应,支持ping 包

    TIME FWD-PAUSE-REVERSE.zip

    4. **软件工程**:如果是项目管理或软件开发的文档,可能会涵盖版本控制、持续集成/持续部署(CI/CD)流程中如何处理时间线上的任务,以及如何在团队协作中有效地暂停和恢复工作。 5. **操作系统和脚本编程**:时间...

Global site tag (gtag.js) - Google Analytics