Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tracing a Memory-leak in a Long Running Eventmachine Application

Tracing a Memory-leak in a Long Running Eventmachine Application

# Tracing a Memory-leak in a Long Running Eventmachine Application
author
: P.S.V.R

allotted-time
: 30m

theme
: debian

# gist

* What's Eventmachine and How was it used in HuantengSmart
* Memory-leak Symptom
* Diagnosis
* Treatment

# What's Eventmachine

* event-processing library, provides event-driven I/O using the Reactor pattern (反应堆模式)
* single-threaded, scalability limited by _calling request handlers synchronously_ & _demultiplexer_
* not to be confused with Actor model, ex. erlang/celluloid
* not to be confused with Proactor pattern, ex. Boost.Asio

# What's Eventmachine (cont.)

![](reactor_blocking.png){:relative_height='80' reflect_ratio='0.5'}

# nonblocking handler sample (by Longyi)

http = EventMachine::HttpRequest.new(@@url).put :body => @@post_params[@@request_count%2]
http.callback { received http.response if http.response }
{: lang="ruby"}

# blocking handler sample

uri = URI(@@url)
res = Net::HTTP.get_response(uri)
received res
{: lang="ruby"}

# How was EM used in HuantengSmart

* Connecting all TelePort routers
* Hosting a HTTP server for internal Rails to send requests
* Hosting a WebSocket server for mobile apps
* Hosting (yet another) WebSocket server for web pages

# Memory-leak Symptom

| Uptime | Observed Memory Footprint |
|---------|--------|
| Startup | 73M |
| 34min | 84M |
| 1h | 92M |
| 1h44m | 106M |
| 3h10m | 130M |
| 30h | 3.47G |

# Memory-leak...

Minqi Pan

March 14, 2014
Tweet

More Decks by Minqi Pan

Other Decks in Programming

Transcript

  1. ������������������������ ������������ ���������������������������������� ������������������������������������� ���������������������������������������� ���������������������������������������� ����������������������������������������� �������������������� ����������������������������������������� ���������������������������

    ������������������������������������� ���������������������� ����������������������������������������� ���������������������������������� ��������������������������� ����������������������������������� ���������������������������������������
  2. ������������������������� ������������ ����������������������������������������� �������������������������������������� ����������������������������������������� ��������������������������������������� ����������������������������������� �������������������� �������������������������������� �������������������������������������

    ������������������������������������ ����������������������������������������� ���������������������������������� ���������������������� ��������������������������� ����������������������������������� ����������������������������
  3. ������������������������� ������������ ����������������������������������������� �������������������������������������� ����������������������������������� ����������������������������������������� ��������������������������������������� �������������������������������������� ������ ��������������������������������������

    ������ ������������������������������������� ������ ���������������������������������������� ������������������������������������� ����������������������������������������� ������������������������������������