Skip to content

box: dynamically adjust xlog readahead size#8113

Merged
locker merged 1 commit intotarantool:masterfrom
Gumix:iverbin/gh-8108-increase-xlog_read_ahead
Jan 30, 2023
Merged

box: dynamically adjust xlog readahead size#8113
locker merged 1 commit intotarantool:masterfrom
Gumix:iverbin/gh-8108-increase-xlog_read_ahead

Conversation

@Gumix
Copy link
Contributor

@Gumix Gumix commented Jan 9, 2023

XLOG_READ_AHEAD defines the number of bytes added to the count argument
of the pread syscall, currently it equals to 16 KB. However xlog and snap
files are written by 128 KB chunks of data, which turn into ~80 KB chunks
after compression (in average, depending on the data), so the 16 KB read-
ahead doesn't make any sense.

According to performance experiments, 8 MB readahead gives the best results
for large files. However, 8 MB read buffers would increase memory
consumption of the replication relays, which usually read small portions of
data and does not need such a big buffers. For this reason, dynamically-
sized read buffer is implemented by this patch. The minimum readahead is
now 128 KB, and the maximum is 8 MB. As a result, the recovery time of a
900 MB snapshot decreased from 25 sec to 13 sec (when reading from HDD).
Performance of a recovery from SSD is not affected.

Closes #8108

Do not merge until tarantool/small#58 is merged!

@Gumix Gumix requested a review from locker January 9, 2023 12:11
@coveralls
Copy link

coveralls commented Jan 9, 2023

Coverage Status

Coverage: 85.49% (+0.01%) from 85.478% when pulling 00dc490 on Gumix:iverbin/gh-8108-increase-xlog_read_ahead into 7e86a4c
on tarantool:master
.

@locker locker assigned Gumix and unassigned locker Jan 9, 2023
@Gumix Gumix marked this pull request as draft January 10, 2023 09:43
@Gumix Gumix changed the title box: increase XLOG_READ_AHEAD from 16 KB to 8 MB box: dynamically adjust xlog readahead size Jan 13, 2023
@Gumix Gumix added the do not merge Not ready to be merged label Jan 13, 2023
@Gumix Gumix marked this pull request as ready for review January 13, 2023 18:54
@Gumix Gumix requested a review from alyapunov January 13, 2023 18:54
@Gumix Gumix assigned alyapunov and locker and unassigned Gumix Jan 13, 2023
@Gumix Gumix requested a review from locker January 16, 2023 09:50
@locker locker assigned Gumix and unassigned locker Jan 16, 2023
@Gumix Gumix requested a review from locker January 17, 2023 19:34
@Gumix Gumix assigned locker and unassigned Gumix Jan 17, 2023
@locker locker assigned Gumix and unassigned locker Jan 18, 2023
@Gumix Gumix requested a review from locker January 18, 2023 11:45
@Gumix Gumix assigned locker and unassigned Gumix Jan 18, 2023
@locker locker removed their assignment Jan 18, 2023
@Gumix Gumix assigned Gumix and unassigned alyapunov Jan 19, 2023
XLOG_READ_AHEAD defines the number of bytes added to the `count' argument
of the `pread' syscall, currently it equals to 16 KB. However xlog and snap
files are written by 128 KB chunks of data, which turn into ~80 KB chunks
after compression (in average, depending on the data), so the 16 KB read-
ahead doesn't make any sense.

According to performance experiments, 8 MB readahead gives the best results
for large files. However, 8 MB read buffers would increase memory
consumption of the replication relays, which usually read small portions of
data and does not need such a big buffers. For this reason, dynamically-
sized read buffer is implemented by this patch. The minimal readahead is
now 128 KB, and the maximal is 8 MB. As a result, the recovery time of a
900 MB snapshot decreased from 25 sec to 13 sec (when reading from HDD).
Performance of a recovery from SSD is not affected.

Closes #8108

NO_DOC=performance improvement
NO_TEST=performance improvement
@Gumix
Copy link
Contributor Author

Gumix commented Jan 27, 2023

Updated the src/lib/small submodule and the unit test accordingly:

diff --git a/test/unit/xlog.c b/test/unit/xlog.c
index ee9d52971..ae4d920ef 100644
--- a/test/unit/xlog.c
+++ b/test/unit/xlog.c
@@ -131,14 +131,10 @@ test_dynamic_sized_ibuf(void)
                fail_if(row.lsn != prev_lsn + 1);
                prev_lsn = row.lsn;
        }
-       size_t capacity = ibuf_capacity(&cursor.rbuf);
-       size_t start_capacity = cursor.rbuf.start_capacity;

        is(cursor.read_ahead, XLOG_READ_AHEAD_MIN,
           "read_ahead decreased to %d", XLOG_READ_AHEAD_MIN);
-       ok(capacity >= start_capacity && capacity < 2 * start_capacity,
-          "ibuf capacity decreased to [%zu..%zu)",
-          start_capacity, 2 * start_capacity);
+       ok(ibuf_capacity(&cursor.rbuf) == 0, "ibuf capacity decreased to 0");

        xlog_cursor_close(&cursor, false);
        fail_if(xlog_close(&xlog, false) < 0);

@Gumix Gumix removed do not merge Not ready to be merged labels Jan 27, 2023
@Gumix Gumix assigned locker and unassigned Gumix Jan 27, 2023
@locker locker added the full-ci Enables all tests for a pull request label Jan 30, 2023
@locker locker merged commit 0479cfa into tarantool:master Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Enables all tests for a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increase XLOG_READ_AHEAD

4 participants