hi,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my project involves lot of&nbsp; I/O&nbsp; over the network.. one part of my project involves a server(http) which is listening on the port for many client . this sever fetches an image from the web and&nbsp; and send it to clients ....&nbsp; and many clients will request the server concurrently .. to implement concurrent serving to clients i used threaded http server <br>
like this <br><br>class HTTPServer(SocketServer.ThreadingMixIn,BaseHTTPServer.HTTPServer):<br>&nbsp;&nbsp;&nbsp;&nbsp; pass<br><br>class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def do_GET(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;received connection from: &quot;,self.client_address<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image=image_retreive()&nbsp;&nbsp; #where image retreive is a function that retrieves image from the web and works fine <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.send_response(200)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.send_header(&quot;Content-type&quot;,format)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.send_header(&quot;Content-Length&quot;,len(image_data))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.end_headers()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.request.sendall(image_data)<br><br>httpd = HTTPServer((&#39;&#39;,port_number), RequestHandler)<br>httpd.serve_forever()<br>
<br><br>this code worked fine but this performance was very bad ... it workes fine if the clients requested for small n medium size images as the server sends the response immediately and also workes fine if one client is requesting a large image (obviously server takes time to send response&nbsp; as&nbsp; it takes time to fetch the image from the web ) and other clients concurrently request for small and medium images&nbsp; these&nbsp; clients will&nbsp; be served immediately even if the other client is waiting but problem crops up when 2 clients concurrently request for an large image .. while these&nbsp; two clients are waiting for the response fromthe server . The server doesn&#39;t accept any other client request ... i can see this as i am printing the&nbsp; address of the client that connects with server &nbsp; in the 1st line of get method&nbsp;  of the request handler if two clients concurrently request for an large image and only two clients address gets printed&nbsp; that means only 2 clients receives connection to the server&nbsp; even if&nbsp; other clients&nbsp; are requesting&nbsp; the server at the same time and other servers are served only after the&nbsp; those 2 server releases the connection or get the response . that means server servers only 2 clients at a time .this is very undesirable as even if 3rd client is requesting for very small image and 2 clients are waiting for large image .. 3rd client won&#39;t receive the response until those 2 clients are&nbsp; served . to make thing worst my server should serve 10 to 15 clients concurrently &nbsp;  <br>
<br>to solve this i did some searching and found about cherrypy and twisted also implemented my server in cherrypy <br>like this<br><br>from cherrypy import wsgiserver<br>def image_httpserver_app(environ, start_response):<br>
&nbsp;&nbsp;&nbsp; print &gt;&gt;sys.stdout,&quot;received connection from: (%s : %s ) \nthe image url is: %s &quot; % (environ[&quot;REMOTE_ADDR&quot;],environ[&quot;REMOTE_PORT&quot;],environ[&quot;QUERY_STRING&quot;])<br>&nbsp;&nbsp;&nbsp; status = &#39;200 OK&#39;<br>
&nbsp;&nbsp;&nbsp; response_headers = [(&#39;Content-type&#39;,format)]<br>&nbsp;&nbsp;&nbsp;&nbsp;  image=image_retreive()&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; response_headers = [(&quot;Content-Length&quot;,`len(image_data)`)]<br>&nbsp;&nbsp;&nbsp;&nbsp; start_response(status, response_headers)<br>&nbsp;&nbsp;&nbsp;&nbsp; return [image_data]<br>
<br>mappings=[(&#39;/&#39;, image_httpserver_app)]<br>wsgi_apps = mappings <br>server = wsgiserver.CherryPyWSGIServer((&#39;localhost&#39;, 8888), wsgi_apps,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; server_name=&#39;localhost&#39;,numthreads=20)<br>
&nbsp;<br>if __name__ == &#39;__main__&#39;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; server.start()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; except KeyboardInterrupt:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; server.stop()<br><br>this didn&#39;t solve the problem at all .. same thing is happening only 2 clients is served at a time ..even if no of threads is assigned&nbsp; to 20 .. <br>
i have did lot of searching and reading .. and hoping to find a solution ..can anyone make it easier for me<br>i have heard of twisted deffered object .. will it solved the problem ? if not pls suggest me alternative..<br>
<br>