Rails: How to load a thread on startup - ruby-on-rails

I am working with a UDP server in rails and I have the server called from my config/initializers folder.
If I run the code thread_a=Thread.new{UDPserver()} then the the code works fine however the code eventually switches off, I presume once my rails script stops running.
If I write
thread_a=Thread.new{UDPserver()}
thread_a.join
then my whole web program doesn't work and I presume this is because my program is waiting till the threads finish (which they don't) until it loads up the rest of the program.
What am I to do?
Notes:
The reason I am running a thread is because I need my program to be constantly waiting for UDP messages and then to react. Also, I need my standard we program to be up at the same time.
ruby 1.9.3p194
Rails 3.2.12

Related

passenger / website under heavy load

running passenger v 5.0.11 on ubuntu, behind nginx, with ruby 2.1.3p242
The app is doing a concurrent call (generate a pdf file via whthlktopdf, opening the app one some url and saving it to a file) when a specific model is updated
not saying this is a good pattern, thing is the call get stuck and the passenger process reaches its passenger_max_request_queue_size
hence I'm wondering if there would be a way to kill stuck processes automatically when this kind of thing occurs ?
There is a builtin feature for that: https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_max_request_time

Ruby On Rails Development Log

I'm using ROR on a Ubuntu server.
I remember the first time I start ROR use rails s,
I can see all logs, server status in the window
Now I start it as background function.
When I need to check the log, I need to open WinSCP, find development log the huge file and open it.
The time for downloading the file takes minutes.
Actually I dun need to see all log, I need only view last say 10-20 lines.
How can I do that?View last 10-20 development log without influence the ROR server.
This should work (assuming that you're already in your Rails project's main directory):
tail -f -n=20 log/development.log
Also, this command is outputting new lines continuously as they appear in log (because of modifier -f).

Rails server running in command prompt causing conhost.exe to crash

I have a Rails application that requires a bunch of environment stuff to get set up, and right now the easiest way for me to do it is to run a batch file to configure the environment and then launch the server from the command prompt. (Perhaps one day I will bite the bullet and transcribe all of the various environment variables into the project config, but I'd rather not...)
But when I do this, I occasionally manage to crash conhost.exe! It does not seem like I should be able to do this. Stranger still, it seems to happen most often if I access certain records in the application. I can't imagine it could crash if there were too much console output???
I am also having mscvrt-ruby.dll crashes, although I may have resolved those by doing some gem finagling. The conhost issue may or may not be related, I'm not sure. But if I launch the server from within RadRails, I don't seem to get these issues (the app doesn't completely work because of the missing environment stuff, but it seems much more stable).
Technicals: Windows 7, Rails 2.3.5, Ruby 1.93, Mongrel 1.2.0pre, uh, not sure what else...
Thoughts?

Loading ruby takes ages

I'm frequently starting up rails console or rails server or using other command line ruby apps. The bootstrap takes several seconds, which becomes tedious after a while.
Is there any way I can either run a compiled version, or keep it loaded using something like spork, so running 'heroku logs' runs instantly, rather than taking 10 seconds to start up?
Run a compiled version of what?
Rails server and rails console take long time to load because they have to load up Ruby on Rails plus whatever your environment requires. If you want to keep instances running then just open up a terminal window, load your console and server, and never close them.
Have you thought of trying vagrant? it will keep your instance running to you want them to stop.

rails console doesn't load

Today, for no reason, my rails(2.1.0) application is very slow or even not responding.
It happens intermittently.
So sometimes it works but again it doesn't work.
When it doesn't work, I can't even load 'script/console production'.
I want to know where it's stuck.
How do I load console step-by-step so that I can know which part causes the problem?
Thanks.
Sam
You could be running out of memory on your server and so the machine can't respond to you. If you are running mongrel then get monit onto it to limit the memory it can use and restart where necessary.
If you are using Passenger, try limiting the amount of instances, and if you have already done that look up a script that kills passenger instances when too big via a cron job.
If it's not a memory issue then I'd probably need more information.
If you are able, try temporarily removing all plugins/gems and see if the app will boot. One of those is likely the problem.
The script/console file contains this.
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
You can find the commands/console file here for Rails 2.1.
I recommend loading up irb and trying to load your app from there.
require 'config/boot'
If that works, then try stepping through the rest of the mentioned commands/console script to find out which part is the problem.
If the boot file won't load, take a look at that config/boot.rb file to see if you can determine which part isn't working. Good luck!
When all else fails, you should be able to use strace to debug what the script/application is actually doing. Note that this should only be one of the last resorts as it produces extremely verbose information (and also mostly limited to I/O actions).
Try using 'strace script/console production' for example

Resources