|
Luca Montecchiani
l.montecchiani at teamsystem.com
Thu Apr 24 03:23:19 EDT 2008
Hi Graham,
so you implicit suggest to avoid "Session._new_sid(req)" ?
I've already used req.connection.id and instead of req.connection.remote_ip
I've used the req.connection.remote_addr because there is also the
client port but I've noticed that this three values doesn't change
if I repeatedly refresh the page :( probably the tcp client stack cache
the last free
used port for an immediate reuse... on windows I've to wait at least 6
seconds
between a refresh to have different values :(
def _getunique(req):
import os
import thread
req.uniqidprog = req.uniqidprog + 1
_tmpid = "%d:%d:%s:%s:%d:%s:%d" % ( os.getpid(),
thread.get_ident(),
req.connection.remote_addr[0],
req.connection.remote_addr[1],
req.connection.id,
req.request_time,
req.uniqidprog )
return _tmpid
Any other suggestion ?
thanks
Graham Dumpleton ha scritto:
> You could try also mixing in:
>
> req.connection.id
>
> This is unique for a request at any particular point in time for that
> Apache process. Apache may reuse connection IDs though, so good to
> also make use of current time and process ID.
>
> Other things you could factor in to it are:
>
> req.connection.remote_ip
>
> although if coming in through a proxy, this may not be true remote
> client so not enough to uniquely identify client.
>
> Graham
>
> 2008/4/24 Luca Montecchiani <l.montecchiani at teamsystem.com>:
>
>> 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 .
>>
>> ------------------------------------------------------------------------------------------
>>
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
>>
>>
--
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 .
------------------------------------------------------------------------------------------
|