using python in web applications

L

Littlefield, Tyler

Hello all:
I'm curious if there are some good solutions for using Python in web
applications.

I'm not feeling particularly masochistic, so I do not want to develop
this project in PHP; essentially I'm looking to build a web-based MMO. I
know that you can use nginx with Python with servers like Flask, but I'm
not really sure how well all of those work. Since this will be a game, I
can expect quite a few users; I've already got quite a lot of interest.
I don't much care for PHP, but the thing that can be said for it is it's
pretty quick. How does Python compare? Are there some solutions (I was
told about PyPy today) that would be quicker that I could still use for
the web app? I'm also curious what databases are suggested? I've always
done most of my work in MYSql, but from what I understand postgresql is
becoming more popular to.

Thanks all for the input,

--

Take care,
Ty
Web: http://tds-solutions.net
The Aspen project: a light-weight barebones mud engine
http://code.google.com/p/aspenmud

Sent from my toaster.
 
L

Laurent

[troll]
For a serious web based MMO you'd rather stick to low level and forget about bloated Object Relational Mapping java-like layered kind of frameworks that are made for Rapid Applications Development, not for efficiency.
[/troll]

"Eve Online", a well known MMORPG was developped with stackless python : http://highscalability.com/eve-online-architecture

You mentioned nginx so I can tell you I personally use Linux + nginx + mongodb (pymongo) + Python 3 version of cherrypy (with Mako templates) and it's working fine after some tuning.
 
L

Laurent

[troll]
For a serious web based MMO you'd rather stick to low level and forget about bloated Object Relational Mapping java-like layered kind of frameworks that are made for Rapid Applications Development, not for efficiency.
[/troll]

"Eve Online", a well known MMORPG was developped with stackless python : http://highscalability.com/eve-online-architecture

You mentioned nginx so I can tell you I personally use Linux + nginx + mongodb (pymongo) + Python 3 version of cherrypy (with Mako templates) and it's working fine after some tuning.
 
L

Littlefield, Tyler

[troll]
For a serious web based MMO you'd rather stick to low level and forget about bloated Object Relational Mapping java-like layered kind of frameworks that are made for Rapid Applications Development, not for efficiency.
[/troll]
I replied to that one off list I guess, but I figured Django was way
more overhead than I wanted, doesn't really fit with solving the speed
issue.
"Eve Online", a well known MMORPG was developped with stackless python : http://highscalability.com/eve-online-architecture

You mentioned nginx so I can tell you I personally use Linux + nginx + mongodb (pymongo) + Python 3 version of cherrypy (with Mako templates) and it's working fine after some tuning.

Awesome, thanks. I'm new to this, so some of that flew over my head, but
I'll take a look at all of them. I'm not sure of the relevance of
stackless in this case; I was looking into PyPy, but I'm not really sure
whether that can be connected with nginx. I guess I could just write the
web server in Python and use it from that point.

--

Take care,
Ty
Web: http://tds-solutions.net
The Aspen project: a light-weight barebones mud engine
http://code.google.com/p/aspenmud

Sent from my toaster.
 
L

Laurent

Well PyPy is just an implementation of Python among many others (but limited to version 2.7). It is not a web server. If you want to make PyPy interact with a web server (such as nginx) you have to use a special protocol suchas WSGI or Fast-CGI. For best performances you can for instance use uWSGI that integrates well with nginx but for this you have to recompile nginx. As you see it's a bit complex, you should read the wikis. May the Force be with you.
 
L

Laurent

Well PyPy is just an implementation of Python among many others (but limited to version 2.7). It is not a web server. If you want to make PyPy interact with a web server (such as nginx) you have to use a special protocol suchas WSGI or Fast-CGI. For best performances you can for instance use uWSGI that integrates well with nginx but for this you have to recompile nginx. As you see it's a bit complex, you should read the wikis. May the Force be with you.
 
C

Chris Angelico

[troll]
For a serious web based MMO you'd rather stick to low level and forget about bloated Object Relational Mapping java-like layered kind of frameworks that are made for Rapid Applications Development, not for efficiency.
[/troll]

I have been trolled. :)

For any sort of web-based real-time game, here's two things to avoid:

1) Snoopability and modifiability of crucial data. Everything should
be stored on the server, so that if anyone fiddles, all they do is
break their own client so it has to reload from the server.
2) Massive waste of resources due to unnecessary frameworks/facilities.

I play a lot of Flash games, and right now I'm playing one that has
coped poorly with a miniature slashdotting. A spike in popularity
resulted in a spike in server lag. I fired up a little packet sniffer,
and discovered that every time you do anything in the game, the client
makes a new POST request to its server. Why?! It's not that hard to
hold a socket connection open!

In another context, a similar issue - not a problem as yet (that I
know of), but would be if the system were to be slashdotted. A server
whose sole purpose is to handle script-instigated requests (using HTTP
POST for its transport) sends back a Set-Cookie header with a session
id. This implies that the server is holding session data for all these
clients that are never going to send that cookie back. The server
appears to be IIS with ASP scripts, so presumably stateful sessions
are enabled by default, so it's costing memory and processing to hold,
then discard, all those useless (and probably empty) session state
tags. And presumably many MANY other servers have the same thing.

What's YOUR framework doing that you don't need, and how much is it costing you?

Yeah, I was trolled bad. :)

ChrisA
 
L

Laurent

+1 for PostgreSQL. It's faster than MySQL for years now, and is much more seriously featured.
If you don't need ACID properties (transactions stuff) you should also give Document-based databases like MongoDB a try. It changed my code life.
 
L

Laurent

+1 for PostgreSQL. It's faster than MySQL for years now, and is much more seriously featured.
If you don't need ACID properties (transactions stuff) you should also give Document-based databases like MongoDB a try. It changed my code life.
 
A

alex23

I'm not feeling particularly masochistic, so I do not want to develop
this project in PHP; essentially I'm looking to build a web-based MMO.

Google have been promoting the use of appengine along with HTML5 & JS
to produce games. One advantage of using GAE to host the server is it
takes care of the scaling for you.

I found these presentations fascinating:
http://cc-2011-html5-games.appspot.com/#1
http://io-2011-html5-games-hr.appspot.com/#1

This article covers the process in a little more depth:
http://clouddbs.blogspot.com/2011/02/how-to-write-html5-game-in-30-days-with.html

Google are also aggregating platform-specific info here:
http://code.google.com/games

Hope this helps (and let us know when you have something to show off!)
 
A

Alan Plum

I replied to that one off list I guess, but I figured Django was way
more overhead than I wanted, doesn't really fit with solving the speed
issue.

Depending on your needs, you may find something like bottle or Flask a
better choice then.

Django can be scaled down a lot, but it's a full-featured framework at
its heart. Bottle is pretty minimal (IIRC it doesn't even come with any
templating). Flask is somewhere in between as it bundles Werkzeug (a
pure WSGI framework) with Jinja (a template library) with some glue code.

I have used Flask in the past but often found myself implementing half
of Django anyway, which is why I eventually switched. When I only need a
bare API with no database and without templates, I usually go for Bottle
these days.

If you feel like coding closer to the metal and care more about
performance than readability, you might also find Twisted useful.
 
R

Roy Smith

Alan Plum said:
Django can be scaled down a lot, but it's a full-featured framework at
its heart.

You can pick and chose which parts of django you want to use. You don't
need to use any of the Django model stuff. You don't need to use any of
the template system. You can tear out all or most of the default
middleware. At that point, about all that's left is the route parser
and dispatch code. The nice thing about this is that as you
incrementally discover which pieces of it you really do need, it's easy
to pull them in.

That being said, we've made a lot of use of Tornado for small
stand-alone web services with just a couple of routes. In retrospect,
it's unclear if there's any justifiable argument for why we use both
Tornado and Django, other than hysterical raisins.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top