|
Luca Montecchiani
l.montecchiani at teamsystem.com
Wed Apr 23 11:28:22 EDT 2008
Hi all,
I'm in the process to improve the function we use to get an unique id
each time we call it.
This is the current implementation, initially it was based only on
req.request_time,
bad assumption because different request could have the same
request_time value
and so I've added a random value that should limit this side effect.
I've also added a counter (req.uniqidprog) to support multiple calls
inside the
same request.
def getuniqid(req,prefix=''):
from random import random
req.uniqidprog = req.uniqidprog + 1
_tmpid = "%s%s%d%s" % ( prefix ,str(req.request_time),
req.uniqidprog, str(random()) )
return _tmpid.replace('.','')
Our production environment is :
Windows 32bit / Linux 32bit
Apache 2.2.8
Python 2.5.2
Modpython 3.3.1
Postgresql 8.2.7
Psycopg 2.0.7
This seem to works fine but I'm worried about its correctness and possible
collisions under heavy loads.
Can I use the Session._new_sid() function without worrying about lock/unlock
and other issues ? Something very simple like that :
def getuniqid(req,prefix=''):
from mod_python import Session
return "%s%s" % ( prefix , Session._new_sid(req) )
Googling a bit I've found a "mod_unique_id" apache module that could do the
job unfortunately it states that is not reliable on Windows environment
:( and I
don't know how could impact on performance...
Thanks in advance,
luca
--
Luca Montecchiani
Software Di Base
TeamSystem S.p.a.
------------------------------------------------------------------------------------------
Informativa ai sensi del D. Lgs. 196-30/06/2003.
Il contenuto di questa e.mail e degli eventuali allegati, deve essere nella disponibilità
del solo destinatario. Se ricevete per errore questa e-mail siete pregati di informarci
(rispedendola al mittente) e di provvedere alla sua rimozione.
Possono essere presenti informazioni riservate e non corrette (parzialmente o totalmente).
Le e-mail in partenza e in arrivo possono essere oggetto di monitoraggio
da parte di Teamsystem spa. Del contenuto è responsabile il mittente della presente.
Chiunque venga in possesso non autorizzato di questa e-mail è vincolato
dalla Legge a non leggerne il contenuto, a non copiarla, a non diffonderla e a non usarla.
Informiamo che per l' esercizio dei diritti di cui all'art. 7 del d.lgs.196/2003 ci si può
rivolgere al Titolare del trattamento Teamsystem S.r.l. via Gagarin 205 61100 PESARO
per posta o fax, indicando sulla busta o sul foglio la dicitura "Inerente alla Privacy",
o inviando una e-mail all' indirizzo privacy at teamsystem.com .
------------------------------------------------------------------------------------------
|