db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: Releasing latches when waiting for locks. When and why?
Date Tue, 21 Nov 2006 13:55:33 GMT
Mike Matrigali <mikem_app@sbcglobal.net> writes:

> Having said that it would be interesting if someone had time to
> implement a higher performance latch implementation and plug it in
> and see how much it helps.  It would decrease the total time spent
> in lock manager.

Ok, a new experiment: I removed the calls to LockFactory.latchObject()
and LockFactory.unlatch() in BasePage. Instead, I let BasePage check
manually whether it was latched and use wait/notifyAll if it was. The
patch (which is very simple) is attached.

To see the effect of this change, I tested the patch on a dual-CPU
machine with the test client from DERBY-1961 running single-record
select operations. Derby was running in embedded mode, and the entire
database was in the page cache. The results for 1 to 100 concurrent
clients compared to the code in trunk are shown in the attached graph
(latch.png).

For one client, there was not much gained, but for two clients, the
throughput increased 20% compared to trunk. For three clients, the
increase was 40%, and it was 145% for 30 clients. This was a lot more
than I expected! I also ran a TPC-B like test with 20 clients and saw
a 17% increase in throughput (disk write cache was enabled).

I would guess that the improvement is mainly caused by

  a) Less contention on the lock table since the latches no longer
     were stored in the lock table.

  b) Less context switches because the fair queue in the lock manager
     wasn't used, allowing clients to process more transactions before
     they needed to give the CPU to another thread.

I hadn't thought about b) before, but I think it sounds reasonable
that using a fair wait queue for latches would slow things down
considerably if there is a contention point like the root node of a
B-tree. I also think it sounds reasonable that the latching doesn't
use a fair queue, since the latches are held for such a short time
that starvation is not likely to be a problem.

-- 
Knut Anders

Mime
View raw message