Re: Thread safety and performance

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Kevin Fenters (KevinFenters_at_discussions.microsoft.com)
Date: 01/31/05


Date: Mon, 31 Jan 2005 11:47:01 -0800

Sarge

Not sure about commands being more efficient than a rowset, but I would
guess they would be. From your latest post, one thing I would add is that a
prepared command should be agnostic with respect to transactions and you can
serialize as many transactions against a session as you want. I create the
session on starting each thread and keep them open for the duration. The
advantage, in my opinion, of my method is in setting up the buffers and
preparing the command once, and then just calling ICommand::Execute() as many
times as needed after transferring the data to the buffer. I would guess that
it's up to each DB to handle row and page level locking, but a command locks,
writes and unlocks in one call - does it not?

"Sarge" wrote:

>
> "Kevin Fenters" <KevinFenters@discussions.microsoft.com> wrote in message
> news:7992E995-D89A-4BD1-9D7C-D79688FEDCA4@microsoft.com...
> > Sarge,
> >
> > My opinion is that one session per thread is the way to go. OLEDB will
> > support multi-threaded access to a global or static IDBInitialize* in a
> > free-threaded server. I developed a similar thing some time ago, but ran
> into
> > a problem where one thread managed records that the others depended on. If
> > your design creates such a dependency you'll have to serialize multiple
> > threads anyway. If you design it with speed in mind, executing commands
> with
> > parameters is ideal and all that will really happen on executing a command
> > will be to transfer the data into a global or static buffer and calling
> > ICommand Execute. The command, parameters, columns and buffers need only
> be
> > "prepared" once. The same holds true for multiple commands per thread if
> you
> > set them up beforehand and hold them over the lifetime of the threads.
> >
> > Kevin Fenters
> >
>
> Kevin, thanks for your thoughts on this.
>
> I think I can manage the thread serialization by aborting and retrying
> transaction-protected updates and inserts that fail due to locking. I'm
> already used to doing this with Berkeley DB. For example, if you are
> performing an INSERT under ITransactionLocal, it should fail with an
> appropriate HRESULT that tells you another thread has already gained
> ownership of that portion of the table.
>
> So you feel that prepared commands are more efficient than rowsets. I must
> figure out how to reuse prepared commands under transactions. The SDK is
> not clear on the scope of transactions. Supposedly, a transaction only
> applies to the current session, but I don't know if you have to release and
> create the session each time. If so, I would have to prepare all the
> commands again.
>
> --Sarge
>
>
>



Relevant Pages

  • RE: CommitBatchSize vs. CommitBatchThreshold for transactional dis
    ... Let's suppose the bar maid on duty tonight is the high IQ type. ... You issue 2 transactions with a varied amount ... large numbers of transactions and commands to the distribution agent. ... CommitBatchThreshold only refers to individual commands outside of a grouped ...
    (microsoft.public.sqlserver.replication)
  • Re: Transactional Replication is reapplying commands
    ... from the log, written to the distribution database, and then just when the ... transactions in the log, write them to the distribution database, and mark ... cascading updates and deletes for replication enabled. ... > executing a batch of commands. ...
    (microsoft.public.sqlserver.replication)
  • Re: 1 transaction with 800000 commands were delivered
    ... to your developer about breaking these commands up into multiple transactions. ... Depending on what you are actually doing, this could cause replication to ...
    (microsoft.public.sqlserver.replication)
  • Re: Thread safety and performance
    ... > My opinion is that one session per thread is the way to go. ... If you design it with speed in mind, executing commands ... So you feel that prepared commands are more efficient than rowsets. ... figure out how to reuse prepared commands under transactions. ...
    (microsoft.public.data.oledb)
  • Re: Distribution database is growing large...
    ... Also it could be that you merely issued transactions that affected a large ... if these commands have been replicated to all ... Looking for a SQL Server replication book? ... The data on subscribers are valid. ...
    (microsoft.public.sqlserver.replication)