On Jul 1, 2007, at 11:36 AM, mc wrote:

>
> Thanks.
>
> You say you are not a fan. What is the preferred way to solve the
> problem I described?

optimistically.  i would ensure that appropriate constraints are  
placed upon the table such that two conflicting INSERT statements  
would result in one of them raising an exception; when the second  
client encounters this exception, it starts over again and re-SELECTs  
the row from the table.   The case for the optimistic approach is one  
of "how often will a confict reasonably take place ?"  I think  
conficts on INSERT, for all the use cases I can think of (such as  
inserting unique keywords), are exceedingly rare, since they  
correspond usually to end-user activities, where two users come up  
with the same new information at the exact same time.   Even if you  
did have thousands of users hammering an application where many are  
expected to come up with the exact same information (such as,  
everyone is going to tag their photos with "kids" and "pets" which  
get added to a table of unique keywords),  once a fair degree of all  
that "unique" data is inserted, then you'd no longer have conflicts,  
and the pessimistic locking would then add tremendous and almost  
always unnecessary latency to an applciation that has thousands of  
users hammering it.  If I were running a really big website, id even  
try pre-populate the table with expected values before going live.

on the other hand, if end users are not the issue, and you are  
instead writing an application that expects to have INSERT conflicts  
because it spawns a huge number of worker threads that are all  
operating upon the same data, locking the whole table for each INSERT  
will completely defeat the purpose of having worker threads, and you  
might as well not use them. 
  

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

Reply via email to