On Dec 17, 2009, at 8:56 PM, Kevin Ar18 wrote:

> * If I setup 2 sessions, that means I will have 2 connections to the 
> database, meaning the database is the one that will handle threading 
> conflicts per what is described here: 
> http://www.postgresql.org/docs/8.4/static/mvcc.html

> So, I have 1 app with multiple processes and threads.  Each thread and/or 
> process may end up trying to do something to the database at the same time.  
> What is the solution to threading?  How do web frameworks solve it?  Is there 
> some inherent design in databases and/or SQLAlchemy that makes this not a 
> actual problem?   What do I do if I have 2 separate apps?  3?

it really is that - simultaneous transactions are isolated from one another, 
and their results are only made visible to other transactions after they're 
committed.  as far as locking,  you generally choose between an "optimistic" 
and a "pessimistic" approach:

http://en.wikipedia.org/wiki/Concurrency_control
http://en.wikipedia.org/wiki/Optimistic_concurrency_control

as far as the in-memory state of key components like connections, sessions and 
cursors, the general approach is to share nothing between threads.  this is 
what pretty much every web framework ultimately ends up doing - all the 
state/etc. is per thread.

its a large subject of discussion so hopefully some other list members can 
expound upon some of this.






> 
> I really don't like relying on that.
> However, the SQLAlchemy docs suggest making many small Sessions for short 
> interaction with the database.  The problem is if I have many 
> threads/processes accessing the DB simultaneously (through separate 
> sessions\connections), then I could get into threading problems working with 
> the database, right?
> 
> Is the solution to use one single session for the entire application (the 
> application consisting of many processes and threads) and making all my 
> processes communicate with this single session when it needs to do database 
> stuff?
> 
> Somehow, I have my doubts that it how it should be done -- and even the 
> SQLAlchemy docs say otherwise (although again, very vague about what it is 
> talking about).
> 
> 
> 
> Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. Sign up now.
> --
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to