[storm] Consistent multithreaded operations

Raphael Saint-Pierre rsaintpi at matrox.com
Fri Sep 5 18:26:27 BST 2008


Hi, 

> ________________________________
>
> De : storm-bounces at lists.canonical.com
[mailto:storm-bounces at lists.canonical.com] De la part de NeedBenzyn
NeedBenzyn
> Envoyé : 05 September 2008 5:42
> À : Jamu Kakar
> Cc : storm at lists.canonical.com
> Objet : Re: [storm] Consistent multithreaded operations


> Hi,
> thanks for you answer, i'm sorry I forgot to notice that my store object
is retrieved from an helper function which 
> handle one store instance by thread :

> Database = create_database("mysql://"+ 
>
ServerConfig.dbUser+":"+ServerConfig.dbPassword+"@"+ServerConfig.dbHost+"/"+
ServerConfig.dbName)
> LocalStoreHolder = threading.local()


> def GetStore():
>     global LocalStoreHolder
>     global Database
    
>     if (not hasattr(LocalStoreHolder,"store")):
        LocalStoreHolder.store = Store(Database)
        
>     log.msg("Returning store instance :%s for thread :
%s"%(LocalStoreHolder.store,threading.currentThread().getName()))

>     return LocalStoreHolder.store

> _________________________________

In this case, although you have one store per thread, you still share one
connection to the database. Transactions are handled on a per-connection
basis, therefore you should create one connection for each thread and then
associate it to a new store, as Jamu suggested.

Raphaël




More information about the storm mailing list