Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser causes memory leak problem #20

Open
mquan opened this issue Feb 16, 2012 · 12 comments
Open

Parser causes memory leak problem #20

mquan opened this issue Feb 16, 2012 · 12 comments

Comments

@mquan
Copy link

mquan commented Feb 16, 2012

I have a rails app that dynamically compiles less to css based on user inputs and have noticed significant memory leakage that crashes the app after running for about 30 minutes. Using the oink gem, I was able to pinpoint the cause, which is the parse method that creates the Less::Tree. The memory leak occurs even before calling to_css

It seems like something isn't deallocated properly and I just wonder if there's any hook for me to manually destroy everything created by the parse method.

Thanks

@cowboyd
Copy link
Owner

cowboyd commented Feb 16, 2012

Do you have code reloading turned on?

@mquan
Copy link
Author

mquan commented Feb 16, 2012

I don't know what that feature is, so I assume no. I just use it the way the doc instructs:

parser = Less::Parser.new
tree = parser.parse("/* my less code */") #this here causes leakage
css = tree.to_css

@cowboyd
Copy link
Owner

cowboyd commented Feb 17, 2012

There are a couple things that it could be

Remember that you have a completely separate virtual machine living inside your ruby process. By default, the V8 interpreter will not even start garbage collecting javascript objects until it has allocated something like 256MB of memory. This can be magnified if those js objects reference ruby objects.

Do you see your usage grow or does it plateau after a certain point?

On Feb 16, 2012, at 1:44 PM, Quan Nguyen wrote:

I don't know what that feature is, so I assume no. I just use it the way the doc instructs:

parser = Less::Parser.new
tree = parser.parse("/* my less code */") #this here causes leakage
css = tree.to_css


Reply to this email directly or view it on GitHub:
#20 (comment)

@mquan
Copy link
Author

mquan commented Feb 17, 2012

Without the parse method, the oink log reach constant memory usage very quickly. When it's used, the memory usage keeps rising at very predictable rate. The leakage is about 300k per call on fairly large LESS code.

@cowboyd
Copy link
Owner

cowboyd commented Feb 17, 2012

On Feb 16, 2012, at 9:02 PM, Quan Nguyen wrote:

Without the parse method, the oink log reach constant memory usage very quickly. When it's used, the memory usage keeps rising at very predictable rate. The leakage is about 300k per call on fairly large LESS code.

What is the highest bound you've seen it reach?

@mquan
Copy link
Author

mquan commented Feb 17, 2012

I deployed my app on a heroku dyno, which has 522Mb. The app has about 250Mb when started and memory is maxed out very quickly. I have to restart the app every 30mins or so.

@mbuckbee
Copy link

mbuckbee commented Dec 6, 2012

Just curious if there is an update or any further suggestions to this, I'm observing the same behavior that @mquan reported with respect to memory growth.

@mquan
Copy link
Author

mquan commented Dec 6, 2012

@mbuckbee I ditched this and just compile less client side, not sure if this fits your problem

@mbuckbee
Copy link

mbuckbee commented Dec 6, 2012

@mquan it is an approach I'm considering. Also, I assume that this was for Lavish (which I added as item number 212 over here: http://www.bootstraphero.com/the-big-badass-list-of-twitter-bootstrap-resources)

@nodrog
Copy link

nodrog commented Apr 18, 2013

I get this memory leak also, and there seems to be no limit to the amount it gobbles up, i have 16GB and took it all in about 4 hours of working on the less files in my rails app.

After restarting rails it drops the memory its using fine, and all is nice and fast again.

If i can give anyone any useful information please let me know what would help.

I am sure a bunch of people are experiencing this and not realising what it is.

Many thanks

@cowboyd
Copy link
Owner

cowboyd commented Apr 19, 2013

You have a couple of options 1) make sure you are using the latest version of therubyracer (currently 0.11.4) 2) set V8 resource constraints before using parsing your less files

@nodrog
Copy link

nodrog commented Apr 19, 2013

thanks cowboyd

I have updated to the latest rubyracer and added the following as a initialiser in rails

constraints = V8::C::ResourceConstraints.new
constraints.set_max_young_space_size 64 * 1024 * 1024 # 64M
constraints.set_max_old_space_size 64 * 1024 * 1024 # 64M
constraints.set_max_executable_size 16 * 1024 * 1024 # 16M
V8::C::SetResourceConstraints(constraints)

the issue is still there, if i update a less file and refresh the browser (development env) then i get a bump in memory on the rails process of about 90mb per refresh.

As i am updating css in less and refreshing often this is a major issue very quickly.

Any help much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants