Fastcgi and performance

24 views
Skip to first unread message

PF4Pylons

unread,
Jan 26, 2010, 2:39:02 PM1/26/10
to pylons-discuss
Hi all

I was told by a programmer (I am not one :D ) that an application that
runs Pylons via CGI is not going to be performant in a shared hosting
environment and I may not be allowed to use it. As reason for poor
performance the programmer indicated the fact the the server will have
to spawn a new process each time a request comes.

Is that so?


Thank you
PF

Mike Orr

unread,
Jan 26, 2010, 5:04:36 PM1/26/10
to pylons-...@googlegroups.com

That's why people don't use CGI in production. But FastCGI was
designed specifically to overcome this. Pylons has several deployment
options: ProxyPass, mod_wsgi, FastCGI, etc. These are all similar in
performance (maybe not identical, but certainly better than CGI). I
would start with ProxyPass because it's the most straightforward
(just connect Apache to your existing PasteHTTPServer), but it's worth
exploring all of them and seeing which one best meets your needs.

I haven't used FastCGI so I can't answer your specific questions on it.

--
Mike Orr <slugg...@gmail.com>

PF4Pylons

unread,
Jan 26, 2010, 5:40:56 PM1/26/10
to pylons-discuss
Hi Mike

I am using a hosted environment and the hosting company doesn't give
me access to the apache confing files
and as far as I know neither the option to use include client
httpd.conf sections so the proxy solution is
not for me

Thank you for your reply
PF

On Jan 26, 5:04 pm, Mike Orr <sluggos...@gmail.com> wrote:

> Mike Orr <sluggos...@gmail.com>

Alec Lyons

unread,
Jan 26, 2010, 5:51:14 PM1/26/10
to pylons-...@googlegroups.com
Assume your host supports mod_python (so you can upload python files, execute them and have the results returned)? If so, http://wiki.pylonshq.com/display/pylonscookbook/Production+deployment+using+mod_python might help.

My suggestion though would be to look for a hosting partner that support mod_wsgi...I don't know of any though, and i you find one please share!


--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.


Richard Rosenberg

unread,
Jan 26, 2010, 5:51:30 PM1/26/10
to ultimul...@gmail.com, pylons-...@googlegroups.com
I have pylons running behind Apache/FastCGI on a hostmonster.com shared server and it seems to work well and perform just fine. I have yet to move any logic (controllers, templates, etc.) over from my dev server to the shared host, so pylons is serving static stuff at the moment, but it definitely works and performs reasonably well so far.

Say the word and I'll pull some of the config files down from the shared machine and post 'em to the list. Sorry. . .But I got it going a while ago and have not really done much with it yet, so the Apache configuration and other steps have faded from memory. Should be at least similar to what would be required for godaddy.com.

Richard

Jonathan Gardner

unread,
Jan 26, 2010, 5:55:43 PM1/26/10
to pylons-...@googlegroups.com


ProxyPass will get you setup very quickly. However, FastCGI is
actually the preferred method where I work. It ends up being pretty
much like ProxyPass except instead of an HTTP request being sent to
the process, it's a set of CGI parameters. That translates to a bit of
savings due to HTTP being a bit complicated to negotiate.

You can also do things like manage how many FastCGI processes are
running and such which makes management nicer as you need to scale up.

In a shared hosting environment, I am pretty certain they will want
you to use FastCGI. That's because they see which processes are out
there and connected to the web server, versus various web servers that
are targets for proxy requests and otherwise unconnected.

--
Jonathan Gardner
jgar...@jonathangardner.net

PF4Pylons

unread,
Jan 26, 2010, 9:56:21 PM1/26/10
to pylons-discuss

Hi guys

Thanks for your replies.
Godaddy doesn't support mod_wsgi and they support FastCGI only for
Perl and Ruby.
I just opened a ticket a support ticket with them to verify if the
ProxyPass which I understand is the same with Reverse Proxy is allowed
and installed.


What other options do I have? For various reasons I can't change the
provider.
Thank you
PF

Graham Dumpleton

unread,
Jan 26, 2010, 10:48:29 PM1/26/10
to pylons-discuss

On Jan 27, 1:56 pm, PF4Pylons <ultimulunic...@gmail.com> wrote:
> Hi guys
>
> Thanks for your replies.
> Godaddy doesn't support mod_wsgi and they support FastCGI only for
> Perl and Ruby.

There is nothing special that has to be done to FASTCGI setup to
support a particular language. If they already have Python installed
for CGI scripts, you should be able to use it with FASTCGI. The only
dependency is that you may have to install flup into an area in your
own account and use it from there instead of it being installed in
main Python installation. In worst case you could even install your
own Python installation so you can use any version you want instead of
any antiquated version they supply.

That they say they don't support Python either means they just don't
want anyone running Python at all, or they don't understand how
FASTCGI works which leaves the question of why you would want to use
them if their technical knowledge is so limited.

As such, you may want to go find a web host that actually knows about
Python and how to host web applications using Python properly. That
company doesn't seem to be a very good choice.

Graham

PF4Pylons

unread,
Jan 28, 2010, 9:55:27 PM1/28/10
to pylons-discuss
By mistake I replied to the author instead of replying to the group. I
am posting these here so others can read this too

2010/1/27 PF4Pylons <ultimul...@gmail.com>:
> Hi Graham
> According to this http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html
> you are right but can't they limit what you use as a language by
> controlling the extensions of the files that are going to be executed
> as fastcgi?

If they allow generic use of .fcgi as extension for fastcgi scripts
there generally wouldn't be a restriction on what language you can
use. It is actually probably pretty hard to even put in place a
language restriction because FASTCGI is a socket protocol so even if
they had a fastcgi wrapper set up for purposes of user switching and
the extension .pl was mapped in Apache, you could probably still put
Python code in it with appropriate #! line saying it was actually
Python. This is because unlikely that fastcgi wrapper is going to
invoke the specific interpreter but would still just run the script
and let the script determine what interpreter is used.

I would really suggest you just use a web host that properly supports
Python via fastcgi or other mechanism. The most popular among Python
people is WebFaction.

Graham

> Thanks for your reply
> PF
>
>
> On Jan 26, 10:48 pm, Graham Dumpleton <graham.dumple...@gmail.com>
- Show quoted text -

On Jan 26, 10:48 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:

PF4Pylons

unread,
Jan 28, 2010, 9:56:30 PM1/28/10
to pylons-discuss
I just paid the hosting for one year in advance, I can't change that
now, Not till I am sure
it makes sense financially to put more money in my website.

When you say sockets below are you talking about this:

Our CGI service does not support the creation of socket connections.
This includes "sockets module" and "socket connections."

This prevents scripts and applications from creating real-time links
to other servers (such as outgoing mail servers). This restriction is
in place to inhibit spammers and protect bandwidth. Likewise,
streaming media is not supported, nor are other real-time services
like IRC.

This is what they say about their service. I know that the paster
server opens a port specified in the .ini file. Wold that at list be
allowed to comunicate with the appache server? How does it actually
work?

Graham

PF4Pylons

unread,
Jan 28, 2010, 9:57:54 PM1/28/10
to pylons-discuss
010/1/29 PF4Pylons <ultimul...@gmail.com>:
> Hi Graham
>
> According with the documentation http://www.fastcgi.com/docs/faq.html#typical_httpd.conf
> they can configure some specific file extensions only to be executed
> via the fastcgi module.
>
> http://www.fastcgi.com/docs/faq.html#typical_httpd.conf

No, as I understand the configuration in that specific section, that
does not restrict it to a specific language. This is because that
configuration would rely on the #! line in the .fcgi file to know what
interpreter to run.

If you look down further at the PHP example however, that does
restrict the language. This is because for .php it has been configured
to execute a wrapper or helper script instead of the target resource.
That wrapper will then read in the resource file and interpret it
specifically as PHP code, ignoring the #! line.

> As the web hosting company mentioned in their documentation they only
> support perl and ruby for
> fastcgi. They don't mention any extension to be specifically used for
> fastcgi.
>
> In general if, according with the documentation you specify fcgi or
> fpl as extesions these will be executed via
> fastcgi. Does the fastcgi module care for the shebang line you put in
> your file? Can that be restricted only to
> specific script interpreters?

As I said before, it really depends on how the hosting company has
configured it. The default way people usually set up fastcgi however,
ie., that typical configuration, would be such that .fcgi would be
executed per the #! line.

> I am thinking about just pointing the shebang line to Python but
> use .pl extension for my files. Would that work?

Try it. You haven't as far as I remember even pointed at which hosting
company it is or where there documentation is describing their setup,
so I am not going to know. Just try and make sure you have a working
Python fastcgi hello world first by testing it on your own computer
system somehow because any mistake in the code will yield a 500 error
and you may not know whether it is a coding error in your program or
lack of flup, of whether it just isn't honouring the #! line.

Graham

PF4Pylons

unread,
Jan 28, 2010, 10:02:42 PM1/28/10
to pylons-discuss
The provider is Godaddy
Here is all they say about fastcgi in their help section

http://help.godaddy.com/search?q=fastcgi&x=0&y=0

Quite cryptic sometimes.

I will get back to this after I configure the HelloWorld app.
I did mention the provider in the other thread I started here, I had
the impression you replied there too.

I will also update that thread, I have made some progress there but I
run into an other roadblock.

Thanks
PF

On Jan 28, 9:57 pm, PF4Pylons <ultimulunic...@gmail.com> wrote:
> 010/1/29 PF4Pylons <ultimulunic...@gmail.com>:
>
> > Hi Graham
>
> > According with the documentationhttp://www.fastcgi.com/docs/faq.html#typical_httpd.conf

Graham Higgins

unread,
Jan 28, 2010, 11:18:28 PM1/28/10
to pylons-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 29 Jan 2010, at 03:02, PF4Pylons wrote:

> The provider is Godaddy
> Here is all they say about fastcgi in their help section
>
> http://help.godaddy.com/search?q=fastcgi&x=0&y=0
>
> Quite cryptic sometimes.


Looks like you may unfortunately be constrained to CGI:

http://webpy.org/godaddy.com

FWIW:

Two config lines from my apache's default.conf file showing fastcgi i)
port and ii) socket configs:

> FastCgiServer /www/app1/app1.fcgi -port 8081 -processes 1
> FastCgiServer /www/app2/app2.fcgi -idle-timeout 120 -socket /www/
> app2/app2.sock -processes 2


The contents of file /www/app1/app1.fcgi are:

> #!/usr/bin/python
> from paste.deploy import loadapp
> wsgi_app = loadapp('config:/www/app1/production.ini')
> if __name__ == '__main__':
> from flup.server.fcgi import WSGIServer
> WSGIServer(wsgi_app).run()

content of app2.fcgi is more or less identical

Cheers,

(A different) Graham

http://www.linkedin.com/in/ghiggins


-----BEGIN PGP SIGNATURE-----

iEYEARECAAYFAktiYZQACgkQOsmLt1Nhivz4EgCfT2/7fHszpOQQ/8pXDS7ZwhrX
7QAAoJ1iyU6mjew8Zc0YdYpgpVGGmuVyiQCVAgUBS2JhlFnrWVZ7aXD1AQKpEQP/
WMecC2FkIPXCG0eWBXrBVkrUK9PTx0Bm4wbhmisKiHDDCI2SMpvhGyzG6D1F/4br
VcKb5MMtUauj/J6PCCqHYVKwikn71CmNFbUFvCor+6RXRuu7/uoxSYNatp4Si532
mRTLOiq9PaTn0clgrC/D8WYXdqv/pxATazoglPYVoxk=
=SrQR
-----END PGP SIGNATURE-----

Graham Dumpleton

unread,
Jan 28, 2010, 11:28:16 PM1/28/10
to pylons-discuss

On Jan 29, 2:02 pm, PF4Pylons <ultimulunic...@gmail.com> wrote:
> The provider is Godaddy
> Here is all they say about fastcgi in their help section
>
> http://help.godaddy.com/search?q=fastcgi&x=0&y=0
>
> Quite cryptic sometimes.
>
> I will get back to this after I configure the HelloWorld app.
> I did mention the provider in the other thread I started here, I had
> the impression you replied there too.
>
> I will also update that thread, I have made some progress there but I
> run into an other roadblock.


Under their Perl FAQ entry they say:

"""NOTE: This will need to be done in any directory outside of /cgi in
which you want to run .fcgi scripts."""

So, they mention .fcgi files.

It would be quite silly if they were using .fcgi files and the only
thing you can stick in it is Perl. If that were the case they should
have used a specific Perl extension.

As such, it looks a good bet that if you can get flup installed into
your account and can set up sys.path to reference where flup is, it
may work.

Thus, install flup under lib/python in your home directory. Presuming
your home directory is '/home/pf4pylons', then use following in file
called 'hello.fcgi'.

#!/usr/bin/env python

import sys
sys.path.insert(0, '/home/pf4pylons/lib/python')

def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello World!\n']

if __name__ == '__main__':
from flup.server.fcgi import WSGIServer

WSGIServer(myapp).run()

Get that going and then you can work out getting Pylons installed as
well.

Graham

PF4Pylons

unread,
Jan 30, 2010, 12:46:47 PM1/30/10
to pylons-discuss
Hi guys

Here is what I have manged to get working:


=========HelloWorld.fcgi====working, OK====================

#!$HOME/html/Others/PVE/bin/python
import sys
sys.path.insert(0, '$HOME/html/Others/PVE/lib/python2.5')

def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello World!\n']

if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(myapp).run()

======================================================

=========HelloWorld.cgi====working, OK=====================

#!$HOME/Others/PVE/bin/python

import sys
from paste.deploy import loadapp
import wsgiref.handlers

sys.path = ['$HOME/html/Others/HelloWorld'] + sys.path
wsgi_app = loadapp('config:$HOME/html/Others/HelloWorld/
development.ini')
wsgiref.handlers.CGIHandler().run(wsgi_app)
======================================================


=========MyApp.cgi====working, with errors, see
below=====================

#!$HOME/html/Others/PVE/bin/python

import sys
from paste.deploy import loadapp
import wsgiref.handlers
#os.chdir("$HOME/html/Others/Anki/MyAppweb")
sys.path = ['$HOME/html/Others/PVE/lib/'] + sys.path
sys.path = ['$HOME/html/Others/MyApp/MyAppweb'] + sys.path

sys.path.insert(0, "$HOME/html/Others/MyApp/libMyApp")
wsgi_app = loadapp('config:$HOME/html/Others/MyApp/MyAppweb/
production.ini')
wsgiref.handlers.CGIHandler().run(wsgi_app)

======================================================
Sat Jan 30 09:29:06 2010] [error] [client 121.1.1.1] File does not
exist: $HOME/html/css/app.css
[Sat Jan 30 09:29:06 2010] [error] [client 121.1.1.1] File does not
exist: $HOME/html/study/getCSS
[Sat Jan 30 09:29:06 2010] [error] [client 121.1.1.1] File does not
exist: $HOME/html/js/other/jquery-1.2.6.min.js
[Sat Jan 30 09:29:06 2010] [error] [client 121.1.1.1] File does not
exist: $HOME/html/js/other/jquery.hotkeys-0.7.8-packed.js
[Sat Jan 30 09:29:06 2010] [error] [client 121.1.1.1] File does not
exist: $HOME/html/js/other/MochiKit/MochiKit.js
[Sat Jan 30 09:29:06 2010] [error] [client 121.1.1.1] File does not
exist: $HOME/html/js/other/MochiKit/MochiKit.js
[Sat Jan 30 09:29:07 2010] [error] [client 121.1.1.1] File does not
exist: $HOME/html/activity.gif


These files are all rooted in the public folder of the application.
How can I fix this please?

However the my application is slow, so is the HelloWorld aplication
athough this one has no errors in the log.
I believe this is because of the cgi approach.

==============Myapp.fcgi ==Lightning fast===BUT WITH ERRORS see
below=====

#!/home/content/c/r/i/cristip/html/Others/PVE/bin/python
import os, sys
sys.path = ['$HOME/html/Others/PVE/lib/'] + sys.path
sys.path = ['$HOME/html/Others/MyApp/MyAppweb'] + sys.path
sys.path.insert(0, "$HOME/html/Others/MyApp/libMyApp")

from paste.deploy import loadapp
wsgi_app = loadapp('config:$HOME/html/Others/MyApp/MyAppweb/
development.ini')

# Deploy it using FastCGI


if __name__ == '__main__':
from flup.server.fcgi import WSGIServer

WSGIServer(wsgi_app).run()


====================The problems that I have with FCGI================

On top of the errors listed above (the app is not able to find
javascript files, css files and gif files I also have
the following problem:

The address of the application is:

http://www.mydomain.com/cgi/MyApp.fcgi/ (doesn't work without "/" at
the end, I found that out accidentally)

The application has some menus which are all pointed to a shortest
path, see below:

"Login" should be

http://www.mydomain.com/cgi/MyApp.fcgi/account/login

but the application is pointing to

http://www.mydomain.com/cgi/account/login

ans so on. As you can see MyApp.fcgi seems to be eliminated
automatically and I believe that is because the application
was not designed to work this way. How can I fix this?

Thank you all
PF


On Jan 28, 11:28 pm, Graham Dumpleton <graham.dumple...@gmail.com>

Graham Dumpleton

unread,
Jan 30, 2010, 7:23:12 PM1/30/10
to pylons-discuss

On Jan 31, 4:46 am, PF4Pylons <ultimulunic...@gmail.com> wrote:
> Hi guys
>
> Here is what I have manged to get working:
>
> =========HelloWorld.fcgi====working, OK====================
>
> #!$HOME/html/Others/PVE/bin/python
> import sys
> sys.path.insert(0, '$HOME/html/Others/PVE/lib/python2.5')

You cannot use '$HOME' in Python variable strings like that. List the
path explicitly.

> def myapp(environ, start_response):
>     start_response('200 OK', [('Content-Type', 'text/plain')])
>     return ['Hello World!\n']
>
> if __name__ == '__main__':
>     from flup.server.fcgi import WSGIServer
>     WSGIServer(myapp).run()

If this work when you had $HOME above, they must already have flup
installed.

You need some mod_rewrite magic, but they have to have
allowed .htaccess file usage and required overrides to allow you to
use mod_rewrite directives.

Do you have that access?

Graham

PF4Pylons

unread,
Jan 30, 2010, 9:08:22 PM1/30/10
to pylons-discuss
That's true I just used $HOME to replace the too long string I had
there.

Yes they allow .htaccess and modrewrite
I am squzingmy brains to get the right rewrite rule and I can't.
I move the MyApp.fcgi in the application folder and right now I have

www.mydomain.com/Others/MyApp/account/login

instead of

www.mydomain.com/Others/MyApp/MyApp.fcgi/account/login

How do I Rewrite this string? I am using the following .htaccess in
the web folder /Others/MyApp/

Options ExecCGI
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/Others/MyApp/(\[-_a-zA-Z0-9/\.]+)$ /Others/MyApp/
MyApp.fcgi/$1


and this is not doing anything

Thanks
PF

On Jan 30, 7:23 pm, Graham Dumpleton <graham.dumple...@gmail.com>

jbakwd

unread,
Mar 5, 2010, 3:20:56 AM3/5/10
to pylons-discuss
>Namespaces can also import regular Python functions from modules as long as they accept an
>argument named context as their first argument. As an example, a module file my/module.pymight
>contain the following callable:
>def write_greeting(context):
>    context.write("hello world")
>Atemplate can then use this module as follows:
><%namespace name="my" module="my.module" />
>${my.write_greeting()}
>Note that the context argument is not needed in the call. When Mako generates the cached
>Python version, it creates a locally scoped callable, which is responsible for passing the context
>object in for you.
I read the book of <<The Definitive Guide To Pylons>>,
the top note is the book's part of content.
I don't know where the module.py file is placed!
jbakwd@163.com.jpg
Reply all
Reply to author
Forward
0 new messages