strange that nobody reported issue with that before..... @derek: unfortunately, every nested structure would need to be ordered to produce the same string. pickle just "states" that the object that you dump is the same one that you load, i.e. dict1 == dict2, but doesn't guarantee that the serialization format is always the same for "equal" objects.
PS: neeeeeds to be tested.... apparently deepcopying the object before dumps-ing it result in the exact same serialization. Don't know if it's a viable way. On Tuesday, June 11, 2013 8:01:33 PM UTC+2, Derek wrote: > > To add on a bit more to this... > it appears the hash is calculated by doing an md5 of the globals digest. > However, it appears the 'update or insert' logic is strange. Line 555 of > globals.py adds request.now to the modified_datetime, so in this case, > wouldn't it always insert and never update? > In any case, I think maybe this will help... > editing storage.py, change the PickleableStorage to this... > > def PickleableStorage(data): > return Storage(dict(sorted((k,v) for (k,v) in data.items() if > isinstance(v,PICKABLE), key=lambda t: t[0]))) > > I haven't tested it, but the idea is to sort it by key first... > > On Tuesday, June 11, 2013 9:46:36 AM UTC-7, Derek wrote: >> >> I don't think it would be too difficult to solve. Just use an >> 'OrderedDict' instead of a regular dict. >> >> http://docs.python.org/2/library/collections.html#collections.OrderedDict >> >> On Tuesday, June 11, 2013 9:21:21 AM UTC-7, Aravindan Rs wrote: >>> >>> Hi, >>> >>> We use web2py in GAE environment and during our performance tuning we >>> realized that session objects are getting written in every request - even >>> in requests which do not modify the session object. I raised an issue >>> regarding this in the web2py issue tracker where I've provided details ( >>> https://code.google.com/p/web2py/issues/detail?id=1524). After some >>> debugging I realized that actual session object does not change but the >>> pickled string changes each time (e.g. order of items is not guaranteed in >>> a dictionary) resulting is different hash each time which in turn results >>> in the object being written to DB each time. >>> >>> Most of my requests does not write to the session object - still every >>> request results in write to session table. This impacts my system >>> performance adversely + incurs higher cost as GAE charges for every DB >>> read/write. >>> >>> I think it is a difficult problem for web2py to solve - I assume I have >>> to find a workaround in my code. >>> >>> I'm thinking of using session.forget() in the right places. I know the >>> code places where I write to session object. I assume web2py code writes to >>> session object in login, logout and possibly few other authentication >>> related flows. Are there other places to take care of? >>> >>> Is there a more elegant solution to my problem? >>> >>> Thanks and regards, >>> Aravind. >>> >>> PS: Though one can implement the above solution with just "forget" >>> method - I would have loved also to have "unforget" method - I could have >>> simply said forget() in one of the model files and unforget() in every >>> place there is write to session object. >>> >>> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

