Deadlock?

I have a multi-threaded http server. Sometimes, it gets into a state
where it stops responding to requests, and if I press Ctrl+C at the
console it takes a long time to respond. The “ruby -rprofile” shows
this at the top:

% cumulative self self total
time seconds seconds calls ms/call ms/call name
62.65 1.04 1.04 30 34.67 853.00 Thread#stop
9.64 1.20 0.16 37 4.32 18.38 Kernel.require
9.04 1.35 0.15 1 150.00 220.00 IO#each
7.23 1.47 0.12 152 0.79 0.92 Kernel.sleep

I never call Thread#stop explicitly in my program so it’s surprising
that Thread#stop takes up so much time… although I do have both
Timeout and Mutex.

Anyone know what to make of this 62.65% time consumption by
Thread#stop? Could it be that somehow my threads are deadlocking each
other?

Hi,

I never call Thread#stop explicitly in my program so it’s surprising
that Thread#stop takes up so much time… although I do have both
Timeout and Mutex.

Mutex uses Thread#stop to wait to be unlocked.

Anyone know what to make of this 62.65% time consumption by
Thread#stop? Could it be that somehow my threads are deadlocking each
other?

Do you define the signal handler?

···

At Sun, 14 Sep 2003 14:59:27 +0900, Philip Mak wrote:


Nobu Nakada

Nobu Nokada wrote:

Mutex uses Thread#stop to wait to be unlocked.

I don’t think I’m doing very much with Mutex, though. I only have
these two things:

@@mutex.synchronize do
	@@num_sending += 1
end

@@mutex.synchronize do
	@@num_sending -= 1
end

Those should be executed fairly quickly, shouldn’t they? Since I’m
just incrementing and decrementing a number.

Anyone know what to make of this 62.65% time consumption by
Thread#stop? Could it be that somehow my threads are deadlocking
each other?

Do you define the signal handler?

The only signal handling code in my program is this, which happens in
the main thread:

["SIGTERM", "SIGINT"].each do |sig|
	trap(sig) { shutdown }
end

Is that what you’re referring to when you say “signal handler”?

Hi,

Those should be executed fairly quickly, shouldn’t they? Since I’m
just incrementing and decrementing a number.

Hmmm, seem so. Do you use just one mutex in the application?

The only signal handling code in my program is this, which happens in
the main thread:

[“SIGTERM”, “SIGINT”].each do |sig|
trap(sig) { shutdown }
end

What’s `shutdown’? Doesn’t anything deadlock in it?

···

At Sun, 21 Sep 2003 03:21:25 +0900, Philip Mak wrote:


Nobu Nakada