Pokazywanie postów oznaczonych etykietą ruby. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą ruby. Pokaż wszystkie posty

środa, 24 sierpnia 2016

Extract method refactor and passing &block

Today I've tried to refactor code by extracting some part to a method. Spuriously it didn't work.

Problem was with passing block to a method. when you do that you pass block to method not the results.
In order to fix it we need to pass a block to find_each method by using &Proc.new as an extra argument. According to this article it is a fastest method.

czwartek, 25 września 2014

Track memory leaks in rails application.

So this day has come - your production server gets out of memory and you didn't notice millions of requests. After quick investigation you see that your ruby processes are just too fat(300MB? 500MB? 900MB?). You may wonder that some of the requests causes memory leaks.

If you're using passenger the quick workaround (just to minimize effects for now) could be killing worker after it grows too much: PassengerMaxRequests

Still we don't know what caused that. You might try to search for long requests and assume that they the one but long response doesn't need to mean memory leak.
You can easily count the number of objects created during the request.



If you are using ruby 2.1 you can gather more detailed information: http://stackoverflow.com/questions/20956401/how-do-i-track-down-a-memory-leak-in-my-ruby-code