Details
-
Task
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Won't Do
-
None
Description
read_view_open_now() and read_cursor_view_create_for_mysql() do a scan
|
of the list of all open transactions (trx_sys->trx_list) with the
|
kernel_mutex locked. On high-concurrency workloads (i.e. sysbench
|
read-only with number of threads >= 512) the cost of this scan is
|
huge.
|
|
|
The patch is ported from Percona Server, and contains 2 optimizations
|
to reduce the cost during read view creating.
|
|
|
1. Pre-allocate a read view structure for every transaction
|
|
|
No need to allocate a read view struct for each read_view_open_now()
|
call in a transaction, which is too expensive, allocate once and reused
|
it aterwards when need.
|
|
|
2. Maintain a trx_id array. While creating a read view, simply copy
|
the array without traversing the transaction rw_list.
|
|
|
Introduces a concept of "trx descriptors" which is a global
|
ordered array containing IDs of transactions in either TRX_ACTIVE or
|
TRX_PREPARED state. It allows to replace the trx_list scan in
|
read_view_open_now() and read_cursor_view_create_for_mysql() with a
|
binary search on the descriptors array and two memcpy()s.
|
The initial size of the descriptors array is 1000 slots (i.e. 8000
|
bytes). It is resized whenever we need more descriptors.
|
|
|
Since there is no transaction serialization numbers (i.e. trx->no) in the
|
descriptors array, this check was replaced by keeping a separate,
|
trx->no ordered list (trx_sys->trx_serial_list). Getting the current
|
minimum for the current read view is then simply a matter of getting
|
trx->no of the first element from trx_serial_list.
|
https://github.com/alibaba/AliSQL/commit/cb4273343da551de37cf9c46a257340fbc9a5127