Performance of cPickle module

sh_at_defuze.org
Date: 05/11/04


Date: Tue, 11 May 2004 08:26:45 -0400
To: python-list@python.org

Hi guys,

Well, I have a (maybe dumb) question.

I want to write my own little blog using Python (as a fairly small but doable
project for myself to learn more deaply Python in a web context).

I don't want so far to use a database as a backend, I'd prefer use XML which is
enough for a small amount of data the blog would have to deal with.

My problem is that, as HTTP is stateless, I can't keep some objects alive across
multiple requests like for instance an instance of a Users class which is an
interface to manage my users.

Let's say for example, that an user wants to access a resource (a simple web
page), my code would call that Users class though an instance of it and would
call something like getUser(self,login) returning an instance of an UserData
class which would provide me with all the details of that user (name, email,
etc.)

I want to save my users not in a database like I said but in an XML file on the
server.

As HTTP is stateless, I believe that I will have to create again and again the
Users object for every requests.

I don't want to parse the xml file each time, instead I want to save the Users
object (that keeps a map to all my UserData objects) into a file using the
cPickle module.

My question therefore is, is my architecture efficient enough ?

If I had to use a database, the database would keep track of my users and I
would only need to do a SQL statement. Would the cPickle more efficient in my
case than a database ?

To give a bit of code let's say that I have something like :

import cPickle

class UserData:
def __init__(self,name,email):
self.name = name
self.email = email

class Users:
def __init__(self):
self.users = {}
self.hasChanged = false

def _deserialize(self):
if self.hasChanged == false:
self.users = cPickle.load('users.dat')
else:
#parse the xml file...

Is it an efficient method ?

Thanks
- Sylvain



Relevant Pages

  • Re: dynamic class instantiation
    ... I think mixing XML, ... LDF to python parser is a LOT ... This xml file is then fed into the database at the ...
    (comp.lang.python)
  • Re: Using python for a CAD program
    ... relational database models. ... While it might be possible to do this fast enough with Python, ... Basically what the retained mode engine does for you is it ... The retained mode engine will take care of things such as ...
    (comp.lang.python)
  • Re: DBIx::XML::DataLoader
    ... Is there a package or utility that can read an XML file of the sort I ... The dbinfo specifies the login ... credentials to the database, and the database. ... And, I have no idea what XPATH is, let alone what to do with it. ...
    (comp.lang.perl.misc)
  • ANN: eGenix mxODBC Connect Database Interface for Python 0.9.1 (beta)
    ... Database Interface for Python ... The mxODBC Connect Database Interface for Python allows users to ... configure ODBC drivers on the client side. ...
    (comp.lang.python)
  • ANN: eGenix mxODBC Connect Database Interface for Python 0.9.1 (beta)
    ... Database Interface for Python ... The mxODBC Connect Database Interface for Python allows users to ... configure ODBC drivers on the client side. ...
    (comp.lang.python.announce)