Re: [GSOC] Eliminate O(N^2) scaling from rw-conflict tracking in serializable transactions

From: "Mengxing Liu" <liu-mx15(at)mails(dot)tsinghua(dot)edu(dot)cn>
To: "Robert Haas" <robertmhaas(at)gmail(dot)com>
Cc: "Alvaro Herrera" <alvherre(at)2ndquadrant(dot)com>, kgrittn <kgrittn(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [GSOC] Eliminate O(N^2) scaling from rw-conflict tracking in serializable transactions
Date: 2017-07-30 16:53:02
Message-ID: 76bfe8b5.2542.15d946a5427.Coremail.liu-mx15@mails.tsinghua.edu.cn
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for your reply.

Actually, the result of without "rdtsc" is reasonable. I used perf to analyze the performance and found that
even thought the function tracking conflicts (RWConflictExists) was faster, the function inserting conflicts (SetRWConflict)
was too slower. According to your suggestion, I found there were much more waiting events of predicate_lock_manager.
That means, slower SetRWConflict resulted in more lock conflicts.
So I took some effort to made it faster in the last days.

Why the code with "rdtsc" is much faster? I thought that may be caused by some mistakes.
When I changed a machine to run the code, this phenomenon didn't happen anymore..
-----Original Messages-----
From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
Sent Time: 2017-07-29 02:46:47 (Saturday)
To: "Mengxing Liu" <liu-mx15(at)mails(dot)tsinghua(dot)edu(dot)cn>
Cc: "Alvaro Herrera" <alvherre(at)2ndquadrant(dot)com>, kgrittn <kgrittn(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] [GSOC] Eliminate O(N^2) scaling from rw-conflict tracking in serializable transactions

On Wed, Jul 26, 2017 at 11:41 AM, Mengxing Liu <liu-mx15(at)mails(dot)tsinghua(dot)edu(dot)cn> wrote:

Hi, all. There was a very strange phenomenon I couldn't explain. So I was wondering if you can help me.

I was trying to replace the linked list with a skip list in serializable transaction object for faster conflict tracking. But the performance is bad.
So I used the instruction "rdtsc" to compare the speed of my skip list and the original linked list. The skip list was about 1.5x faster.

The interesting thing is that if I added the instruction "rdstc" at the end of the function "RWConflictExists",
the performance of the whole system was increased by at most 3 times!
Here is the result.

| benchmarks | without rdtsc | with rdtsc |
| simpe read/write | 4.91 | 14.16 |
| ssibench | 9.72 | 10.24 |
| tpcb | 26.45 | 26.38 |

( The simple read/write benchmark has the most number of conflicts. )

The patch is attached. All the difference of the two columns is with/without a simple line of code:
__asm__ __volatile__ ("rdtsc");
But I don't know why this instruction will influence the performance so much!

Lock contention is really expensive, so a slight delay that is just long enough to prevent the contention from happening can sometimes improve performance. This example is surprisingly dramatic, though. Of course, we can't commit it this way -- it will break on non-x86.

I would suggest that you gather information on what wait events are occurring in the "without rdtsc" case. Like this:

$ script

$ psql

psql=> select wait_event from pg_stat_activity;

psql=> \watch 0.5

...run test in another window...

^C

\q

^D

...use awk or perl or something to count up the wait events and see where the contention is happening...

--

Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--

Sincerely

Mengxing Liu

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Mengxing Liu 2017-07-30 16:54:36 [GSOC][weekly report 8] Eliminate O(N^2) scaling from rw-conflict tracking in serializable transactions
Previous Message Tom Lane 2017-07-30 16:50:10 Re: PL_stashcache, or, what's our minimum Perl version?