all groups > sql server programming > june 2004 >
You're in the

sql server programming

group:

DBLib locking pattern


Re: DBLib locking pattern oj
6/15/2004 8:47:58 PM
sql server programming:
You want to start with this article:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q224453

[quoted text, click to view]

DBLib locking pattern Don Miller
6/15/2004 11:00:32 PM
I have a small C program that uses the DBlib routines to send around 40
transactions per second to a SQLserver 2000 database. The 40 transactions
are either INSERT or UPDATE statements to one of about five different tables
in the database.

When I run the SQLserver Profiler, I typically see between 7 and 9 lock
acquired and lock released events per transaction. Why is this happening,
is it normal, and, if not, what can I do to minimize it?

The reason I'm asking stems from a weird problem. The application runs just
fine for about an hour. But at each hour interval after the start of the
application, I see the transaction count drop from the normal 40 per second
to 1 or 2 per second for at least 2 or 3 minutes. I am queueing up
transactions while this block occurs, and sometimes I can get over 7000
transactions queued before things get back to normal. Sometimes I must kill
the application and restart it to get things back to normal.

When the application is blocked, I can use the SQL Enterprise Manager to
view current activity and I see that my application has several locks active
on the database (sometimes the file and sometimes the page). These locks
can remain even if I kill my application using the Windows task manager.
When that happens, even restarting my application is fruitless. But, if I
kill the process using SQL Enterprise Manager, at least sometimes it appears
that I've broken the "log jam" and things return to normal after I restart
the application.

What in the world is going on here? The one hour symptoms occur with or
without the SQLserver Agent running (I thought at one time that some system
job might be interfering).

Thanks for any insights you might have...
Don Miller

RE: DBLib locking pattern Al
6/16/2004 1:31:01 AM

Regarding the locks, what you may be seeing are the Intent locks. If an exclusive row lock was required, the first lock to be taken would be an Exclusive Intent Table lock. This lock would then act as a block for anyone trying to obtain either a real Share or Exclusive lock at the Table level. It's just there so you don't have to search for all locks held on a table, and then determine their compatability for the type of lock you want.

There are also Schema locks, which you may be seeing, to stop a change to the table you are dealing with. And DB locks also exist, which I think are to see what DBs someone is accessing.

I wouldn't worry, unless you are having a streadily increasing number of locks over the hour.

As for the performance problem, you might want to look at the avalaible space in the data file and/or log file.s If the SQL Server is trying to allocate a lot of new space, and your disk drives are pretty full, (and possibly highly fragmented) this might be the cause of the slow down. Defeinatly have a look at your disk queue lengths and the amount of hard page faults that are occuring. SQL Server will generally generate a lot of soft page faults, but they aren't a problem.

AddThis Social Bookmark Button