I'm running a deployed rails webserver, and i'm experiencing memory issues. I get an Errno::ENOMEM error each time i try to invoke sendmail. When i run 'top' on my server, it shows me that 2 ruby1.8 processes are running, each digesting around 40% of memory. Is this caused by a leak in my code, or have I launched two simultaneous ruby processes?
Both processes are run by my deployer account, and following that they are invoked when I push to my production git repository (using pushand). I'm trying to find out if this is natural (ie. server needs to be upgraded) or if I have some kind of fault in my setup. I upgraded my RAM from 256 mb to 512 mb recently, and didn't have this problem before.
The problem is preventing visitors from creating a user, because the application throws an error when they should get an activation email.
Note that I'm running rails 2.1.0 on an ubuntu setup, with apache and passenger.
Ok guys, I guess this was one of the cases where I had to help myself, and I'm actually pretty glad I did. I Didn't use any of the tools I linked to.
I logged in my server via. ssh and ran two commands in two screen windows: top and tail -f /var/www/mysite.com/log/production.log.
I looked in the live log file and noticed a page request that took a long time to load – a page where a user can get his/her images shown, where each user is identified by their name, via. acts_as_taggable_on. It took 6 seconds for this single request.
And it kept popping up. I think I saw it 6 or 7 times, and I decided to investigate it further. It was always the same user id, so I decided to look up the user. It turns out, the user had a blank name, "", and the tagged images is found by
Asset.tagged_with(#user.name, :on => "users")
Now in my app, there are 10s of thousands of assets, and Asset.tagged_with("", :on => "users") would return ALL of them, thus eating up my memory.
Now I've handled the case where a user has a blank name, and has it required for all new users. Even though no one helped, I still feel some gratitude towards stackoverflow, because sometimes its as simple as asking the questions to solve the problem.
Related
I have a weird issue that just started popping up for our customers. The portal they've been using for years has started freezing on some of the pages that the user navigates to. I tried restarting the IIS Server, the site within and the Application Pool under which the site is site is running. No difference.
In Chrome Dev Tools I can see that it is always one of these three calls that take time to complete:
When it happens, one of those three calls will report that the request is not finished, like this:
When eventually the call completes, I can see that the Content Download took 3.8 minutes. Not sure whether it is relevant or not, but it is always 3.8 minutes:
Did anyone else encounter a similar situation? Is there a suggestion on how to figure out what is happening all of a sudden that triggers these type of behaviours?
TIA,
Ed
Edit: The resource that fails to load after 3.8 minutes always generates a net::ERR_CONNECTION_RESET error:
Edit2: Thanks to all of you trying to help. A little update: I was able to isolate to problem to an issue with the server not serving some of the files. either *.css or *.js. The setting is that of two identical servers placed behind a load balancer. Apparently, the load balancer software was recently updated and right after that we started having these issues. I am working closely with the IT department of our client, trying to figure out what is the impact of the newer version that seems to have triggered all this drama.
I am using Rails 4.2 and Ruby 2.2.0. Recently, I have noticed that my app will hang for long periods of time when a certain worker is working. This is an app that has been under development for several years and I have never seen this sort of hanging behavior before (nor am I unfortunately completely aware of what changes I've made since it was last not hanging).
What I mean by "hang" is: No pages will load (no controllers can be reached, and even the default homepage which is basically a static page won't load). None of my logs will update. Standard output is not being written to. The application also has many background worker processes (managed by Resque), which also appear to be hung.
I have looked at top and netstat and various other Unix utilities and I don't see anything alarming there, either.
Finally, I'm not sure if it's worth mentioning but this application is running via Foreman on an EC2 instance.
EDIT: I don't believe that it is query related, because nothing abnormal shows up on top. Also, I'm a little inexperienced with rails, but each job has its own entry in the process table, if that helps.
Does anyone have any experience with Rail development page display erratically slowing down and speeding up (page appears 15-20 seconds after the console says the entire page has been rendered).
My development environment is rails 3.0.17 on Mac (Lion), WEBrick 1.3.1, ruby 1.9.2, with Postgres v11 (app supplied by Heroku) for the development database.
Recently, I've noticed some very long delays loading pages... 15 to 20 seconds at times, and the delay is completely unrelated to the complexity of the page, and a given page might load fast several times, then load slow. It might be pretty bad for several minutes, then go away for an hour.
And whether the page loads slow or fast, the rails log always shows the page has rendered fairly quickly... I'll see something like "Completed 200 OK in 486ms" but then the browser might say "waiting for localhost" for another 15 seconds before displaying the page.
Does not seem to depend on the browser (FF or Safari act the same).
Dos not sem to relate to updating the code base. I cna be testing some UI elements and everything is snappy, then suddenly several pages hang for 15-120 seconds.
Still happens even after I added the gem 'rails-dev-boost' to my Gemfile in development.
I also added to my development machine gem 'http_logger' to log calls to external http requests like S3, but don't see that as a factor (the delays often happen on pages that don't access external APIs).
My layouts have a couple of external .js dependencies such as http://static.twilio.com/libs/twiliojs/1.0/twilio.min.js, but I have added that to the bottom of my layout so I would (resumably) still see the page contents quickly if that were being delayed. (Besides, it is probably cached by my browser).
Of course I have tried rebooting the machine, verified activity monitor seems normal for CPU and memory usage. It does not seem to correlate when timemachine is doing its thing.
MORE INFO: per suggestion in comment from AKG below, I used Firebug's web console and most of the time the stylesheets load in a couple of milliseocnds, but when the slowdown occurs I'm seeing delays of 8-20 seconds for most of the stylesheets... which suggests webrick is failing to serve the pages timely?
It could be that buggy/slow middleware is executing after the render is called, but before the response is sent. I recently ran into this issue with pauses of more than 1 minute in some cases, and the culprit turned out to be the Bullet gem, which is designed to help us detect N+1 queries. I removed the middleware and the issue went away!
I got the same problem a few times. I switched to Mongrel. That automatically resolved the issue. However, I got this with Rails 2.3.8.
After performing load testing against an app hosted on Heroku, I am finding that the most DB intensive request takes 50-200ms depending upon load. It never gets slower, no matter the load. However, seemingly at random, the request will outright timeout (30s or more).
On Heroku, why might a relatively high performing query/request work perfectly 8 times out of 10 and outright timeout 2 times out of 10 as load increases?
If this is starting to seem like a question for Heroku itself, I'm looking to first answer the question of whether "bad code" could somehow cause this issue -- or if it is clearly a problem on their end.
A bit more info:
Multiple Dynos
Cedar Stack
Dedicated Heroku DB (16 connections, 1.7 GB RAM, 1 comp. unit)
Rails 3.0.7
Thanks in advance.
Since you have multiple dynos and a dedicated DB instance and are paying hundreds of dollars a month for their service, you should ask Heroku
Edit: I should have added that when you check your logs, you can look for a line that says "routing" That is the Heroku routing layer that takes HTTP request and sends them to your app. You can add those up to see how much time is being spent outside your app. Unfortunately I don't know how easy it is to get large volumes of those logs for a load test.
I have Rails 3, with webrick, running a sqlite3 database. On my standard linux desktop, doing Word.all (Word is my model), I have no problems, even though there are 10,000 entries in my database. I have scopes to display them 2000 at a time, to make things more tractable.
On my Windows 7 laptop, it's a very different story. I can only get about 400 Words at a time, or I get that "Not enough space" error.
I can open up window's task manager, and the memory barely even blips. On the console, the command returns almost instantly (it clearly has not done anything to several hundred entries before giving up).
What is going on here? My laptop isn't exactly much worse than my desktop, so I don't think i"m actually hitting any RAM limits... Is there some weird Ruby thing going on?
EDIT: It's not just a server issue either, i see the same thing in the rails console, as well... So, webrick might not be an issue...
If it were code, you'd think I"d see it across platforms, not just on my laptop... Even then, how can it be my code if all I'm typing is Word.all (no custom code) and the database is clearly set up right (I don't have issues getting any individual entry, just not too many at a time)
-jenny
webrick is a very simple web application server think to work only for development.
I have no experience of it on windows os , but,anyway, i have many probel with it when test limit situation. you could try the mongrel gem , if the problem persist it's something in your code.