Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory Leaks in my Ruby on Rails Application

My application calls bunch of API's which returns lots of data which are manipulated inside my controller to give various insights (passed onto my view).

The problem is that I have been having memory leaks in my application for which I currently need to restart my application after few number of requests.

Also, I have been caching all of my api calls to improve the performance of my application. Most of my data is stored in form of hashes when returned by the api and this data is manipulated (sort of duplicated using groupby).

I'm using Ruby 1.9 and Rails 3.2. I need to know how can I remove this memory leak from my application.

like image 600
amair Avatar asked Nov 30 '22 16:11

amair


2 Answers

You should confirm, that you indeed have a memory leak and not a memory bloat. You can read about ruby GC here

GC.stat[:heap_live_slot] - this one represents the objects which are not cleared after last GC. If this number steadily increases request by request, then you can be sure, that you have a memory leak.

like image 85
Magnuss Avatar answered Dec 05 '22 02:12

Magnuss


First you can check a list of Ruby gems that have memory leaks first.

Refer (https://github.com/ASoftCo/leaky-gems)

like image 41
JohnPaul Avatar answered Dec 05 '22 03:12

JohnPaul