[Tutor] Using jon.fcgi to speed up subsequent invocations

Lloyd Kvam pythontutor at venix.com
Fri Aug 15 16:48:40 EDT 2003


You need the apache fast-cgi module (You are using apache??)
### Section 2: 'Main' server configuration
#
<IfModule mod_fastcgi.c>

         # URIs that begin with /fcgi-bin/, are found in /var/www/fcgi-bin/
         Alias /fcgi-bin/ /var/www/fcgi-bin/

         # Anything in here is handled as a "dynamic" server if not defined as "static" or "external"
         <Directory /var/www/fcgi-bin/>
             SetHandler fastcgi-script
             Options +ExecCGI
         </Directory>

</IfModule>
I think this is fairly self explanatory.

I found Jon helpful in getting the regular cgi module to work.  My code (based
on his advice) looks like:

# somecgi.py
import cgi as stdcgi
import jon.cgi as joncgi

class Handler(joncgi.Handler):
	def process(self, req):
		fields = stdcgi.FieldStorage(fp=req.stdin, environ=req.environ)
###################

There is a jonpy mailing list, but it gets a lot of spam.  The pyweb list
focuses on the more elaborate python web frameworks.

Hope this helps.  (Let me know if I left out critical info.)

Jonathan Hayward http://JonathansCorner.com wrote:

> I have a search script that spends 90+% of its time in initialization. 
> One initialisation gets everything ready for multiple searches, so it 
> should speed up with fast cgi. I converted, or tried to convert it, to 
> jon.fcgi to use Fast CGI.
> 
> As is, I can't tell a performance difference. If I load the larger 
> dataset, a search takes ~20 seconds with or without fcgi. Do I need to 
> tell Apache something different to use it as a fast CGI script (what's 
> the URL to the relevant HOWTO)? Here are relevant snippets of my script:
> 
> import jon.cgi as cgi
> import jon.fcgi as fcgi
> 
> class Handler(cgi.Handler):
>   def process(self, request):
>       multitasking.get_thread_specific_storage()["handler"] = 
> request.params
>       request.set_header("Content-Type", "text/html")
>       request.write(get_output())
> 
> if __name__ == "__main__":
>   init() # This is the really slow invocation that should only be needed 
> once.
>   fcgi.Server({fcgi.FCGI_RESPONDER: Handler}, 0, None, fcgi.Request, 
> 0).run()
> 
> Thanks,
> 

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582




More information about the Tutor mailing list