Sockets/Threads/ThreadingTCPServer and other NASTY things...

Scherer, Bill Bill.Scherer at VerizonWireless.com
Thu May 3 09:35:36 EDT 2001


I'm not sure this is causing your problem, but I thought I'd let you know
of a problem I ran into when creating a threaded http server.

I found that under high load (~ > 10 hits/second), the server would
periodically hang for ten seconds or so.  It turned out to be the
logging.

I 'resolved' it by overriding log_request in my request handler.  The code
I 'overrode' it with was "pass" because I wasn't really interested in
any of the logging at the time.  A possible solution here would be to have
log_request put the log message in a Queue, and have another thread write
the que to the log, but I haven't tried this yet.

I hope that's helpfull,

William K. Scherer
Sr. Member of Applications Staff - Verizon Wireless
Bill.Scherer_at_VerizonWireless.com

On Thu, 3 May 2001 gbgbgb at gmx.de wrote:

> Hi!
> I am writing an Applicationserver for CGI-Scripts using
> ThreadingTCPServer.
> I my BaseHTTPRequestHandler I am handling the call in do_GET/do_POST.
> My problem is that the response I am writing sometimes gets crippled,
> about every five times. (Crippled meens that the data is truncated or
> even no response is getting back)
>
> My send-routine looks like this:
>
>     def dah_writeResponse(self, header, data):
>
> 	data_len = len(data)
>
> 	start_time = time.time()
>
> 	self.wfile.write("%s %s %s\r\n" % (self.protocol_version, "200", ""))
> 	self.wfile.write("%s: %s\r\n" % ("Content-Length", str(data_len)))
> 	self.wfile.write("%s: %s\r\n" % ("Date", self.date_time_string()))
> 	self.wfile.write("%s: %s\r\n" % ("Server", Server_ID))
> 	self.wfile.write("%s: %s\r\n" % ("Connection", "Close"))
> 	self.wfile.write(header + "\r\n\r\n")
>
> 	self.wfile.write(data)
> 	self.wfile.flush()
>
> 	slice = 0
> 	l = len(data)
> 	print "(" + str(l) + " bytes response written in " + str(time.time()
> - start_time) + ")"
> 	sys.stdout.flush()
>
> 	time.sleep(1)
>
> Without the time.sleep(1) call it does not work at all. The most funny
> thing is, that under Internetexplorer it works worse than with
> Netscape.
>
> Is there maybe some "mystical" HTTP-HEADER needed? "keep-alive"? Is
> the flushing bad? What else could be the problem? Has it something to
> do with the Threads?
>
> Has anybody an idea?
> This is driving me mad!!
>
> yours in hope
> Gunter
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list