CPU utilization optimization? PROBLEM FOUND!
Weiss Blitz
weissblitz@y...
Thu, 05 Apr 2001 00:07:42 -0000
Ok, I think I found the problem...
I developed a Medusa based instant messaging server running on a dual-
processor Compaq Proliant box under Win2000 Server.
I noticed Medusa idled at 1-2%, one connection comes up and the CPU
utilization jumps to 100%!
Found that the asyncore.py select loop was being pegged as soon as
the first connection was made. Also noticed this was so because the
asynchat.writable method was always returning a '1' even when the
ac_out_buffer output buffer was empty. I replaced the 'is' operator
with the '==' and it now seems to work normally.
Following is a copy of the original and the modified version of the
asynchat.writable method:
def writable (self):
"predicate for inclusion in the writable for select()"
# return len(self.ac_out_buffer) or len(self.producer_fifo)
or (not self.connected)
# this is about twice as fast, though not as clear.
return not (
(self.ac_out_buffer is '') and
self.producer_fifo.is_empty() and
self.connected
)
def writable (self):
"predicate for inclusion in the writable for select()"
# return len(self.ac_out_buffer) or len(self.producer_fifo)
or (not self.connected)
# this is about twice as fast, though not as clear.
return not (
(self.ac_out_buffer == '') and
self.producer_fifo.is_empty() and
self.connected
)
Not sure if this is the way it is on the original Medusa
distribution, but at least that's the way mine was until now.
Anyways, thanks to all who have spent time and efforts to make Medusa
and Python even better tools!
Carlos :)