Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush memtable and compact L0 files for read only workloads #427

Open
mdcallag opened this issue Nov 15, 2016 · 11 comments
Open

Flush memtable and compact L0 files for read only workloads #427

mdcallag opened this issue Nov 15, 2016 · 11 comments

Comments

@mdcallag
Copy link
Contributor

mdcallag commented Nov 15, 2016

The state of the LSM tree (data in memtable, #files in L0) is a significant source of variance for performance on read-only and read-heavy tests. This is much worse for read-only than for read-mostly workloads. Data in the memtable and files in L0 are overhead for read-only/mostly tests. When the memtable isn't full and when there aren't too many files in L0 then the LSM can stay in that state for a long time because there are no writes to trigger it to change. This is an issue for real workloads and for benchmarks.

I lost a few days debugging this problem recently. I know our users will also be confused by this and some will be disappointed by MyRocks performance. Part of the problem is that synthetic benchmarks are synthetic, but we can't get the world to stop running sysbench.

Can we solve this in two parts?

  1. Give me an option to flush memtable and then remove all files from L0. This must be dynamic. Perhaps there is an option to flush the memtable today. Temporarily setting the L0 compaction trigger to 0 lets me flush the L0, but I doubt that is supported today.
  2. Most users won't know to do things I list in step 1, and they shouldn't have to know them. Can we make MyRocks and/or RocksDB adaptive and figure out it should flush the memtable and L0 when a test is read-only and sometimes when it is extremely read-heavy?

Someone suggested that CompactRange(nullptr, nullptr) flushes memtables and compacts L0. For step 1 we need a way to trigger that via SQL.

@mdcallag
Copy link
Contributor Author

With sysbench read-only range query tests I get 5% to 20% more QPS when the memtable and level 0 is flushed. Details at https://gist.github.com/mdcallag/68052cdd36fe122354bc23ec337fb986

@IslamAbdelRahman
Copy link
Contributor

@siying suggested that MyRocks can for now issues a Flush() and compact all L0 files using CompactFiles() API.
but a better solution will be to bring back read triggered compactions from leveldb

@yoshinorim
Copy link
Contributor

Siying pointed out that for MyRocks to know list of L0/L1 files from a CF, DB::GetColumnFamilyMetaData() can be used. Find files from there and call DB::CompactFiles() with those files.

@yoshinorim
Copy link
Contributor

We have rocksdb_compact_cf variable to rebuild specific CF. We can add another command variable to flush MemTable and L0/L1 (or SQL function).

@alxyang alxyang self-assigned this Jan 19, 2017
@zhangjinpeng87
Copy link

Since RocksDB has block-cache, is it necessary to flush memtable and compact L0 sst files for read-only queries? Because there are only at most 4 sst files in L0.

@zhangjinpeng87
Copy link

@mdcallag

@alxyang
Copy link
Contributor

alxyang commented Jan 23, 2017

While working on this I think I have discovered a bug within RocksDB.
My proposed patch is here. https://gist.github.com/alxyang/df534c195bf9fd8c516c57ab4fb5f610

The code changes are relatively straightforward and just get the column family meta data and call compactFiles().

Stacktrace: (looks like there is some issue with calling CompactFiles when there is a CompactionFilter enabled, the SuperVersion is not set correctly)
https://gist.github.com/alxyang/76efe0158eb217694264277b3289ce2b

@IslamAbdelRahman @siying do you mind taking a look? Can just pull the latest myrocks, apply my patch via git apply --stat alex.patch, and run to trigger the crash.

@IslamAbdelRahman
Copy link
Contributor

Thanks @alxyang, it looks like an issue in rocksdb that happen when CompactionFilter is issued with CompactFiles() and the CompactionFilter is using DB::Get() inside.
We are working on a fixing it

@siying
Copy link
Contributor

siying commented Jan 24, 2017

@zhangjinpeng1987 if the data working set is so small that it all cached in memory, RocksDB will lose B-tree because both read data from memory without compression, but RocksDB needs merge data from multiple levels, L0 files and memtables. In order to improve read-only workload, we can compact memtables and L0 files so we have less data to merge.

facebook-github-bot pushed a commit to facebook/rocksdb that referenced this issue Jan 25, 2017
…sion

Summary:
GetAndRefSuperVersion() should not be called again in the same thread before ReturnAndCleanupSuperVersion() is called.

If we have a compaction filter that is using DB::Get, This will happen
```
CompactFiles() {
  GetAndRefSuperVersion() // -- first call
    ..
    CompactionFilter() {
      GetAndRefSuperVersion() // -- second call
      ReturnAndCleanupSuperVersion()
    }
    ..
  ReturnAndCleanupSuperVersion()
}
```

We solve this issue in the same way Iterator is solving it, but using GetReferencedSuperVersion()

This was discovered in facebook/mysql-5.6#427 by alxyang
Closes #1803

Differential Revision: D4460155

Pulled By: IslamAbdelRahman

fbshipit-source-id: 5e54322
alxyang pushed a commit to alxyang/rocksdb that referenced this issue Feb 3, 2017
…sion

Summary:
GetAndRefSuperVersion() should not be called again in the same thread before ReturnAndCleanupSuperVersion() is called.

If we have a compaction filter that is using DB::Get, This will happen
```
CompactFiles() {
  GetAndRefSuperVersion() // -- first call
    ..
    CompactionFilter() {
      GetAndRefSuperVersion() // -- second call
      ReturnAndCleanupSuperVersion()
    }
    ..
  ReturnAndCleanupSuperVersion()
}
```

We solve this issue in the same way Iterator is solving it, but using GetReferencedSuperVersion()

This was discovered in facebook/mysql-5.6#427 by alxyang
Closes facebook#1803

Differential Revision: D4460155

Pulled By: IslamAbdelRahman

fbshipit-source-id: 5e54322
facebook-github-bot pushed a commit that referenced this issue Mar 29, 2017
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at #427.

update-submodule: rocksdb
Closes #520

Differential Revision: D4509351

Pulled By: alxyang

fbshipit-source-id: 3f04f3c
IslamAbdelRahman pushed a commit to IslamAbdelRahman/mysql-5.6 that referenced this issue May 31, 2017
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

@update-submodule: rocksdb
Closes facebook#520
Github Author: Alex Yang <alexyang@fb.com>

Github PR Sync: {sync, type="child", parent="github", parentrepo="facebook/mysql-5.6", parentprnum="520", parentprfbid="156908684811954"}

Test Plan: Imported from GitHub, without a `Test Plan:` line.

Reviewers: herman, jkedgar, svcscm

Reviewed By: svcscm

Subscribers: svcscm, webscalesql-eng@fb.com

Differential Revision: https://phabricator.intern.facebook.com/D4509351

Signature: t1:4509351:1490814923:d177f0faf2cc11c4e76afd5399343a34c152fd74
george-lorch pushed a commit to george-lorch/percona-server that referenced this issue Jul 19, 2017
Upstream commit ID : fb-mysql-5.6.35/a44d6c287111c63d35fde0222adfebeb54d601c7

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook/mysql-5.6#427.

update-submodule: rocksdb
Closes facebook/mysql-5.6#520

Differential Revision: D4509351

Pulled By: alxyang

fbshipit-source-id: 3f04f3c
george-lorch pushed a commit to george-lorch/percona-server that referenced this issue Jul 20, 2017
Upstream commit ID : fb-mysql-5.6.35/a44d6c287111c63d35fde0222adfebeb54d601c7

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook/mysql-5.6#427.

update-submodule: rocksdb
Closes facebook/mysql-5.6#520

Differential Revision: D4509351

Pulled By: alxyang

fbshipit-source-id: 3f04f3c
george-lorch pushed a commit to george-lorch/percona-server that referenced this issue Jul 21, 2017
Upstream commit ID : fb-mysql-5.6.35/a44d6c287111c63d35fde0222adfebeb54d601c7

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook/mysql-5.6#427.

update-submodule: rocksdb
Closes facebook/mysql-5.6#520

Differential Revision: D4509351

Pulled By: alxyang

fbshipit-source-id: 3f04f3c
george-lorch pushed a commit to george-lorch/percona-server that referenced this issue Jul 21, 2017
Upstream commit ID : fb-mysql-5.6.35/a44d6c287111c63d35fde0222adfebeb54d601c7

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook/mysql-5.6#427.

update-submodule: rocksdb
Closes facebook/mysql-5.6#520

Differential Revision: D4509351

Pulled By: alxyang

fbshipit-source-id: 3f04f3c
gunnarku pushed a commit to facebook/mysql-8.0 that referenced this issue Jul 21, 2017
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook/mysql-5.6#427.

update-submodule: rocksdb
Closes facebook/mysql-5.6#520

Differential Revision: D4509351

Pulled By: alxyang

fbshipit-source-id: 3f04f3c
gunnarku pushed a commit to facebook/mysql-8.0 that referenced this issue Jul 25, 2017
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook/mysql-5.6#427.

update-submodule: rocksdb
Closes facebook/mysql-5.6#520

Differential Revision: D4509351

Pulled By: alxyang

fbshipit-source-id: 3f04f3c
@mdcallag
Copy link
Contributor Author

One variant of this is an option to flush the memtable and merge L0 to L1 after at most N seconds when workload is read-mostly. The worst case is a read-only workload where the memtable flush and L0->L1 merge triggers are never reached. So all queries spend extra CPu going through the memtable and L0, when it would be better to pay the small/one-time cost of doing memtable flush and L0->L1 merge.

facebook-github-bot pushed a commit that referenced this issue Dec 23, 2019
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at #427.

update-submodule: rocksdb
Closes #520

Differential Revision: D4509351

Pulled By: alxyang

fbshipit-source-id: dd3c711
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Aug 12, 2020
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Sep 9, 2020
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Sep 16, 2020
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Oct 5, 2020
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Nov 11, 2020
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
@mdcallag
Copy link
Contributor Author

mdcallag commented Jan 6, 2021

Other things that can help if done adaptively by RocksDB depending on the workload are reducing the L0 trigger so there are fewer L0 SSTs, reducing memtable size. I think this is feasible and hope for progress. Otherwise I will continue mis-reporting perf results for MyRocks and RocksDB and I don't always have the time to fix my mistakes. But the real winners will be users.

facebook-github-bot pushed a commit that referenced this issue Mar 8, 2021
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at #427.

update-submodule: rocksdb
Closes #520

Differential Revision: D4509351 (44a522c)

Pulled By: alxyang

fbshipit-source-id: c5de1697c40
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Aug 16, 2021
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351 (facebook@44a522c)

Pulled By: alxyang

fbshipit-source-id: c5de1697c40
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Aug 17, 2021
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351 (facebook@44a522c)

Pulled By: alxyang

fbshipit-source-id: c5de1697c40
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Aug 30, 2021
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351 (facebook@44a522c)

Pulled By: alxyang

fbshipit-source-id: c5de1697c40
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Aug 30, 2021
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351 (facebook@44a522c)

Pulled By: alxyang

fbshipit-source-id: c5de1697c40
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Sep 1, 2021
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351 (facebook@44a522c)

Pulled By: alxyang

fbshipit-source-id: c5de1697c40
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Sep 2, 2021
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351 (facebook@44a522c)

Pulled By: alxyang

fbshipit-source-id: c5de1697c40
hermanlee pushed a commit that referenced this issue Jan 10, 2022
Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at #427.

@update-submodule: rocksdb
Closes #520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Jan 17, 2022
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

@update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
ldonoso pushed a commit to ldonoso/percona-server that referenced this issue Mar 15, 2022
…na#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook/mysql-5.6#427.

@update-submodule: rocksdb
Closes facebook/mysql-5.6#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue May 20, 2022
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

@update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue May 23, 2022
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

@update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
laurynas-biveinis pushed a commit to laurynas-biveinis/mysql-5.6 that referenced this issue Aug 11, 2022
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

@update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Mar 28, 2023
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

@update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Jun 1, 2023
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

@update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/mysql-5.6 that referenced this issue Jun 14, 2023
…book#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook#427.

@update-submodule: rocksdb
Closes facebook#520

Differential Revision: D4509351

Pulled By: alxyang
inikep pushed a commit to inikep/percona-server that referenced this issue Apr 9, 2024
…na#520)

Summary:
This provides an option to flush memtable and remove all files from L0, which can be useful for lessening variance in benchmarking on read-only and read-heavy tests, in cases where the memtable isn't full and/or there aren't many files in L0, and no writes are occurring.

See more details at facebook/mysql-5.6#427.

@update-submodule: rocksdb
Closes facebook/mysql-5.6#520

Differential Revision: D4509351

Pulled By: alxyang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants