1

I was developing an in-memory version of B+Tree with crabbing technique (you have to obtain lock of child before releasing lock on parent).

My target language of implementation is C# in my implementation I have a backing Dictionary<Page, Node>, for X S and U latches I use a distinct ReaderWriterLockSlim for every available node in Dictionary. So obtaining SLatch basically looks like :

internal void SLatch(long page)
{
    nodes[page].locker.EnterReadLock();
}

I see a very strange pattern in tree behavior when i run multi-threaded test. For test i used 16 core machine and 10 000 000 longs. Tree key count is 16 so there is near 600 000 DataNode objects and 70 000 IndexNode objects.

When I run test on 8 threads simultaneously inserting values in tree. I see that at first core usage is rising linear from 1 core to 3 . But after some time from start it returns to 1.5 cores on average and core usage become constant. In parallel profiler I see that before peak 3 cores process were mostly sleeping waiting one another but after peak they started wait to each other being blocked.

Can anyone suggest any ideas where shall I look the problem or what are the flaws in approach I use.

Thanks.

Egor
  • 175
  • 8

0 Answers0