requests hanging

If my Rails server has been sitting idle for a while, it does not respond to new requests.

What is the best way to troubleshoot something like that.

I am using Rails 3.0.7 in development.

Is there anything in development.log when you submit the request (or already there indicating a problem before the request)? What about in the server terminal window?

Colin

I see nothing any where.

I see nothing any where.

To clarify, on your server terminal window, you see no output when you try to access a page? And of course the page does not load, I assume. It is probably not this if you are seeing nothing at all on the terminal, but sometimes if I forget to remove a debugger line and still am running the server in --debugger mode then of course it hangs.

Otherwise, other obvious quations: have you restarted the server? As well, restarted your computer?

I have restarted the server but not the computer. I am doing something abnormal. Off of a request I start some external program as sub processes. It takes about one second to start those sub processes. How long are we allowed to delay the sending of a respond? Is there a better way do this in Rails way? This problem is intermittent.

Please don't top post, it makes it difficult to follow the thread. Insert your replies at appropriate points in previous message. Thanks

I have restarted the server but not the computer. I am doing something abnormal. Off of a request I start some external program as sub processes. It takes about one second to start those sub processes. How long are we allowed to delay the sending of a respond? Is there a better way do this in Rails way? This problem is intermittent.

Where are you starting the sub processes? You said there was nothing in the server or application development.log when you do the submit so it is not getting as far as a rails action.

Colin

I have restarted the server but not the computer. I am doing something abnormal. Off of a request I start some external program as sub processes. It takes about one second to start those sub processes.

Maybe you could post your code. One thing you might want to look at is if you can start it using another thread – especially if you have something which is apparently volatile. I call terminal commands all the time from my code, so itself should not be a problem. One way to do this could be delayed_job but you can probably do it much more simply using a new thread. See: http://www.ruby-doc.org/core/classes/Thread.html

I have restarted the server but not the computer. I am doing something abnormal. Off of a request I start some external program as sub processes. It takes about one second to start those sub processes.

Maybe you could post your code. One thing you might want to look at is if you can start it using another thread – especially if you have something which is apparently volatile. I call terminal commands all the time from my code, so itself should not be a problem. One way to do this could be delayed_job but you can probably do it much more simply using a new thread. See: http://www.ruby-doc.org/core/classes/Thread.html

this looks pretty good as an intro to threading, if it turns out that this is the correct route to go: http://rubylearning.com/satishtalim/ruby_threads.html

I guess though if your process is important you will have to add some handling in the case of failure if it were to happen.

Please don’t top post, it makes it difficult to follow the thread. Sure!

Insert your replies at appropriate points in previous message. Thanks

I have restarted the server but not the computer. I am doing something

abnormal. Off of a request I start some external program as sub processes.

It takes about one second to start those sub processes. How long are we

allowed to delay the sending of a respond? Is there a better way do this in

Rails way? This problem is intermittent.

Where are you starting the sub processes? You said there was nothing

in the server or application development.log when you do the submit so

it is not getting as far as a rails action.

I meant to say that I started the subprocesses in the previous request.

Here is my code:

class PortalMonitor

include Mongoid::Document

field :count, :type => Integer

field :url, :type => String

field :user, :type => String

field :password, :type => String

field :run, :type => Boolean

validates_presence_of :count, :url, :user, :password

validates_uniqueness_of :url

#embeds_many :emails

embeds_many :vidyo_desktops

after_create :desktop_start

before_destroy :desktop_stop

before_update :desktop_stop, :desktop_start, :if => :changed?

def desktop_stop

t1 = Time.now

Rails.logger.debug “######### Stop VidyoDesktops size = #{vidyo_desktops.size} Dir = #{Dir.getwd} #########”

for vd in vidyo_desktops

Rails.logger.debug “######## #{vd.vd_pid} ######”

begin

Process.kill ‘TERM’, vd.vd_pid

rescue Errno::ESRCH

end

end

vidyo_desktops.delete_all

Rails.logger.debug “############# TIME SPENT STOP #{Time.now - t1} ##################”

end

def desktop_start

Rails.logger.debug “######### desktop_start ###########”

return if run == false

t1 = Time.now

count.times do |n|

n += 1

cmd = ‘lib/vidyo/VidyoDesktop’

eid = user + n.to_s

root = ‘lib/vidyo’

args = " --eid #{eid} --port #{51300+n} " +

“–video #{root}/ofer_wvga.vidyo --audio #{root}/ogm.wav”

cmd = cmd.to_s + args

pid, vd_stdin, vd_stdout, vd_stderr = Open4::popen4(cmd)

#eval(“#{cmd}&”)

#pid = $?.pid

=begin

Thread.new do

while (( line = vd_stderr.gets ))

puts “errrrrrrrrrr #{line}”

end

end

Thread.new do

while (( line = vd_stdout.gets ))

puts “ottttttttttt #{line}”

end

end

=end

Rails.logger.debug “######### Start VidyoDesktops #{pid} cmd = #{cmd} #########”

vidyo_desktops.create!(:vd_pid => pid, :pm_pid => 0, :pm_error => “Hello There!”)

Process.detach(pid)

#p vidyo_desktops

end

Rails.logger.debug “############# TIME SPENT START #{Time.now - t1} ##################”

end

end

I have restarted the server but not the computer. I am doing something abnormal. Off of a request I start some external program as sub processes. It takes about one second to start those sub processes.

Maybe you could post your code. One thing you might want to look at is if you can start it using another thread –

I avoided using Threads since I wanted my operations to be atomic.

I suggest that you first disable the starting of the sub processes to see whether the issues disappears.

Colin

I have restarted the server but not the computer. I am doing something abnormal. Off of a request I start some external program as sub processes. It takes about one second to start those sub processes.

Maybe you could post your code. One thing you might want to look at is if you can start it using another thread –

I avoided using Threads since I wanted my operations to be atomic.

So what does the ‘desktop’ app or code do? It is it something that your users depend on, and if so for what? What is the process? Of course first do what Colin asked and see if bypassing this process gets you back working so you at least know where to focus.

I have restarted the server but not the computer. I am doing something abnormal. Off of a request I start some external program as sub processes. It takes about one second to start those sub processes.

Maybe you could post your code. One thing you might want to look at is if you can start it using another thread –

I avoided using Threads since I wanted my operations to be atomic.

So what does the ‘desktop’ app or code do? It is it something that your users depend on, and if so for what? What is the process? Of course first do what Colin asked and see if bypassing this process gets you back working so you at least know where to focus.

I tried it with the subprocess and it does not hang. Keep in mind that hanging does not happen all the time.

The desktop app is a video conferencing desktop client on Linux. I think I would have to do Threads. I will let you know if it makes it better.

? ...

I tried it with the subprocess and it does not hang.

Do you mean *without*?

Colin

? …

I tried it with the subprocess and it does not hang.

Do you mean without? Sorry! Yes I meant without.

I think I have found a good solution for my background tasks.

http://kr.github.com/beanstalkd/

http://railscasts.com/episodes/243-beanstalkd-and-stalker

It’s exactly what I need, and it seems to be a simple and popular solution.

I think I have found a good solution for my background tasks.

http://kr.github.com/beanstalkd/

http://railscasts.com/episodes/243-beanstalkd-and-stalker

It’s exactly what I need, and it seems to be a simple and popular solution.

Thanks for sharing… I had not seen this and good to know about

I think I have found a good solution for my background tasks.

http://kr.github.com/beanstalkd/

http://railscasts.com/episodes/243-beanstalkd-and-stalker

It’s exactly what I need, and it seems to be a simple and popular solution.

Thanks for sharing… I had not seen this and good to know about

Sure! And thanks to Railscasts new and improved website that lists subject categories .