A Case Study of Scalability Related "Out of memory" Crash in Erlang
We are building a platform for message switching, in Erlang. Everything looks OK on stability and features. It actually has run more than half year with zero down. We tested its performance on our 2-core CPU machine before, and got about 140 transactions/second, it's good enough.
Then, we got a 8-core CPU machine several weeks ago, and we did same performance testing on it, to see the scalability. Since Erlang is almost perfect on scalability, you can image the result, yes, about 700 transactions/second now, scaled almost linear. Until it crashed with "out of memory" when million hits processed.
It left a very big "erl_crash.dump" file there, I had to dig the issue. My first guess was, were some remote requests (access db, access remote web service etc) timeout but the process itself was not timeout yet, and cause more and more processes kept in VM?
A quick grep "=proc:" erl_crash.dump showed that the total number of processes was about 980, which was reasonable for our case.
So, which process ate so many memory? A quick grep "Stack+head" erl_crash.dump showed that there was indeed a process with 285082125 size of Stack+head there.
Following this clue, I caught this process:
=proc:<0.4.0>
State: Garbing
Name: error_logger
Spawned as: proc_lib:init_p/5
Last scheduled in for: io_lib_format:pad_char/2
Spawned by: <0.1.0>
Started: Sun Apr 1 01:21:50 2012
Message queue length: 2086029
Number of heap fragments: 1234053
Heap fragment data: 281266956
Link list: [<0.27.0>, <0.0.0>, {from,<0.42.0>,#Ref<0.0.0.88>}]
Reductions: 72745575
Stack+heap: 285082125
OldHeap: 47828850
Heap unused: 121777661
OldHeap unused: 47828850
Program counter: 0x0764c66c (io_lib_format:pad_char/2 + 4)
CP: 0x0764c1b4 (io_lib_format:collect_cseq/2 + 124)
This process was error_logger, which is from OTP/Erlang standard lib: error_logger, writing received messages to log file or tty. The typical usage is:
error_logger:info_msg("~p:~p " ++ Format, [?MODULE, ?LINE] ++ Data))
Which will format Data to a String according to the Format string, and write it to tty or log file.
The above case showed the message queue length of process "error_logger" had reached 1234053, and the Stack+heap was 285082125, about 272M size.
So the cause may be, that the message queue could not be processed in time, the messages were crowded in error_logger's process and finally caused "out of memory". The bottle-neck was that when error_logger tried to format the message to String, Erlang VM was weak on processing them, which seemed to need a lot of CPU cycles.
In my previous blog, I talked about Erlang is bad on massive text processing. Erlang processes String/Text via List, which is obvious bottle-neck in Erlang now, with Erlang is getting much and much popular and more and more Erlang applications are written.
But, why this did not happen on our 2-core CPU machine? It's an interesting scalability related problem:
"error_logger" module will registered one and only one process to receive and handle all log messages. But Erlang VM's scheduler can not distribute ONE process to use multiple CPUs' computing ability. In our 2-core machine, the whole ability is about 140 transactions/second, the one process of "error_logger" just happened to have the power to handle corresponding log messages in time. Under 8-core CPUs machine, our platform scales to handle 700 transactions/second, but there is still only one process of "error_logger", which can not use 8-core CPUs' ability at all, and finally fail on it.
Erlang treats every process fairly (although you can change the priority manually), we can do a simple/quick evaluation:
1. 2-Core machine, keeping hits at 140 trans/second:
The number of simultaneous processes will be about 200, each process shares the CPU cycles: 1/200 * 2 Core = 1%
2. 8-Core machine, keeping hits at 700 trans/second:
The number of simultaneous processes will be about 980, each process shares the CPU cycles: 1/980 * 8 Core = 0.82%
So, the CPU cycles shared by error_logger process actually not increases.
BTW, I think error_logger should cut its message queue when can not process them in time (disk IO may also be slower than receiving messages).

rss
Comments
Next time you have an erl_crash.dump file you might want to take a look at crashdump_viewer in the standard distribution. It parses the dump file and lets you examine all the processes (including message queue and process heap contents) from a handy web interface.
Geoff,
Thanks. But I got erl_crash.dump is not an Erlang crash dump
Thanks for posting this, it was very informative and helped me very much.
Cassandra http://creditcard-ok.blogspot.com/
You can still find lots of individuals http://www.oaksunglassesale.com/oakley-juliet-c-11.html cannot personal one couple of the actual sneaker as well as be reluctant to get one match regarding themselves. Inside virtually people's brain
There is clearly any lot of money to know about this specific membuat blog. Post consider you produced certain nice points within features also.
Following examine a couple of template blogger with the weblog posts in your web site now, as well as I really just like ones manner of posting. My partner and i added it to help this bookmark web site listing as well as will likely be checking again quickly. Pls try this web page while properly as well as allow me to understand what you believe.
Post discovered your own blog site on the internet lowongan kerja in addition to verify a number of of one's earlier threads. Continue to keep up that very good run. Post just additional up your own Feed to my WINDOWS LIVE MESSENGER News Readership. In search of forward to reading more from you later on! …
Our online store offers you discounted Designer louis vuitton replica wallet at present. You could find them in desirable quality and price. If you don't mind high class louis vuitton uk, have a good time here.These is the first time your visit our louis vuit Louis vuitton online shop ,welcome.
http://www.louisvuittonukk.org.uk
any louis vuitton outlet New backpack features usa a function grownup overall look. Varied piece allows that it is captivated me within the approve and also further than your body.It’s induced by way of severe hardworking liver diseases, and also the most familiar factors behind constant louis vuitton bags outlet hard working liver disorder usually are excessive drinking and also liver disease Chemical.Ladies have an ardent love for the Louis Vuitton handbags outlet because Louis Vuitton enjoys a worldwide reputation of high quality and fashionable designs.
http://www.louisvuittonoutletbagsc.com
coach outlet store online marketed properly all greater compared to earth and earn cozy praise from customers. They are made from the finest leather and fabric.coach outlet store have Coach handbags,Coach Shoulder Bags,Coach Briefcases and so on,these bags are so perfectly reproduced,you won't even be able to tell the difference!Coach Outlet Online Store would dynamically change your overall styles right away. The amazing knack about the unique coach handbag is that it would never disappoint your individual styles at all. Rather, it would instantly change your ultimate fashions in a remarkable manner.
http://www.coachoutletstoreonlineeo.com
No one can deny the shopping at the coach factory outlet is satisfactory. For the low prices and good quality.Over the years, coach factory online has added a multitude of new handbag shapes, styles and materials to their collection. However, the highest care is taken that every Coach handbags is both aesthetically beautiful and functional.Many fashionable women match with practical Coach Purses which will make the street shopping become relaxed,and make every person can enjoy more diversiform combination in coach factory outlet online. http://www.ccoachfactoryoutlet.com
Don't feel upset, there will be a great conversion to this kind of situation because there are a large number of louis vuitton sale now!louis vuitton outlet,welcome to buy urban louis vuitton on our online shop.discount price is our special offer, durability and high quality is our promise.louis vuitton Outlets offer famous classic brand for LV,Channel, with perfect service.So become to the VIP soon.They offer more new styles,like LV purses,LV wallets etc. And are tested by product quality monitoring center .
http://www.louisvuittonoutletsaleo.com
Turn your attention to such discount coach sneakers for women from coach outlet online, you will find something unique and special of such authentic coach for sale at coach factory outlet store online.coach outlet store sells goods that are constructed to meet the highest standards of quality and functionality.You can trust it 100 percent.coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers.
http://www.coachoutletonlinesl.com
http://www.airmaxniketn.com
christian louboutin outlet christian louboutin uk
louis vuitton uk louis vuitton bags uk
mulberry outlet uk mulberry sale
I really enjoyed this site. This is such a Great resource that you are providing and you give it away for free. It gives in depth information. Thanks for this valuable information. http://www.nuvodev.com/
You can see the erl_crash.dump file at crushdump_viewer. Thanks for this informative turotial. lawdepot law depot
I am sure you hade a lot of fun writing this article! best skirts
Hello, friends! Welcome to http://www.nicerjerseys.net . We offer the nicer jerseys, caps and so on. We have updated a lot of jerseys such as: NFL, MLB, NBA, women jerseys and youth jerseys. If you pay by Western Union , you’ll get 10% discount. We can give you the best discount. If you have any question please ask me or email me. Thanks a lot for looking around and ordering.
"Magic" 23 headphones by well-known hip-hop godfather, http://www.monsteroutletsaleclub.com/goods-11199-discount-cheap-monster-beats-by-dr-dre-solo-hd-headphones-black.html Monster Beats By Dr. Dre Solo HD Headphones Black Grammy winner Dr.Dre and Monster (Monster), developed a landmark headphones Monster Beats, the biggest feature of the headset is a strong bass, surging dynamic and extreme detail. The birth of monster of the headset, http://www.monsteroutletsaleclub.com/goods-11196-discount-cheap-monster-beats-by-dr-dre-solo-hd-headphones-red.html Monster Beats By Dr. Dre Solo HD Headphones Red set off a storm, sports and arts and culture in the United States, monster from the Exocet Phelps to Kobe Bryant, from the USA basketball dream team to all kinds of music MV, http://www.monsteroutletsaleclub.com/goods-11193-discount-cheap-monster-beats-by-dr-dre-solo-hd-headphones-black.html Monster Beats By Dr. Dre Solo HD Headphones Black can be seen in its presence. http://www.monsteroutletsaleclub.com