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

Introduce optimize_filters_for_hits to cf_config #3733

Merged
merged 5 commits into from
Nov 27, 2018

Conversation

solotzg
Copy link
Contributor

@solotzg solotzg commented Nov 3, 2018

Signed-off-by: Tong Zhigao tongzhigao@pingcap.com

What have you changed? (mandatory)

  • Introduce the option optimize_filters_for_hits of RocksDB into cf_config.
  • By now, the default cf is used to store kv data which could be determined whether really exists by upper logic instead of bloom filters.
  • So, we use this option to optimizes bloom filters. If true, RocksDB won't create bloom filters for the max level of the LSM to reduce metadata that should fit in RAM. The saved memory could be used for more block caches or others.
  • optimize_filters_for_hits is setted true for default cf by default.

What are the type of the changes? (mandatory)

  • improvement

How has this PR been tested? (mandatory)

  • unit test
  • stress test

Benchmark result if necessary (optional)

  • When we use cgroup to limit memory or disable block cache, the result show that the improvement is little.
  • So, we set max-open-files=-1 and set block-cache-size to a large value in order to test the situation that default cf store all data in memory.
    • PD x 1, TiKV x 1.
    • Setting of go-ycsb:
      • tikv.type=txn
      • operationcount=5000000
      • recordcount=5000000
      • fieldcount=2, fieldlength=10
  • After several tests, the result show that QPS and Latency of are nearly equal, but the memory usage of TiKV with optimize_filters_for_hits=true is about up to 15% less.
  • Details are in [Jira TIKV-1809]

@siddontang
Copy link
Contributor

Em, if we use Raw mode, we can't disable it. Can we change this dynamically?

@huachaohuang
Copy link
Contributor

@solotzg It's not friendly for the community to put an internal link here, please show your result here directly so that everyone can understand it, thanks.

@huachaohuang
Copy link
Contributor

Have you observed the cache hit ratio? If you save 15% memory usage, it means that it can cache more data in memory, so the cache hit ratio is expected to increase more or less.

@siddontang
Copy link
Contributor

IMO, maybe we can disable bloom filter for Raft CF and Raft DB. because we can ensure the data can be found. /cc @BusyJay

@solotzg
Copy link
Contributor Author

solotzg commented Nov 5, 2018

@huachaohuang I haven't observed the cache hit ratio. I recorded and compared the memory usage of TiKV after job load of go-ycsb finished. I will test cache hit ratio when total memory is limited.

@Connor1996 Connor1996 added the component/rocksdb Component: RocksDB engine label Nov 6, 2018
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
Signed-off-by: Tong Zhigao <tongzhigao@pingcap.com>
@solotzg
Copy link
Contributor Author

solotzg commented Nov 12, 2018

If the size of value is less than 64B, this kind of short value would be embed into write cf instead of default cf. So, set fieldcount=15, fieldlength=10.
Load Config:

recordcount=4000000
operationcount=4000000
workload=core
fieldcount=15
fieldlength=10
insertorder=hashed
readproportion=1.0
updateproportion=0
insertproportion=0
scanproportion=0
readallfields=false

Read Config:

recordcount=10000000
operationcount=10000000
workload=core
fieldcount=15
fieldlength=10
insertorder=hashed
readproportion=1.0
updateproportion=0
insertproportion=0
scanproportion=0
readallfields=false

TiKV master:

[rocksdb.defaultcf]
optimize-filters-for-hits = false
[rocksdb.lockcf]
optimize-filters-for-hits = false
[rocksdb.writecf]
optimize-filters-for-hits = false
[raftdb]
optimize-filters-for-hits = false
[raftdb.defaultcf]
optimize-filters-for-hits = false

result:

INSERT - Takes(s): 143.5, Count: 3999992, OPS: 27869.3, Avg(us): 3552, Min(us): 1072, Max(us): 253773, 95th(us): 7000, 99th(us): 8000
READ - Takes(s): 122.1, Count: 9999959, OPS: 81896.3, Avg(us): 1213, Min(us): 286, Max(us): 45484, 95th(us): 3000, 99th(us): 5000

TiKV _optimize_filters_for_hits:

[rocksdb.defaultcf]
optimize-filters-for-hits = true
[rocksdb.lockcf]
optimize-filters-for-hits = false
[rocksdb.writecf]
optimize-filters-for-hits = false
[raftdb]
optimize-filters-for-hits = true
[raftdb.defaultcf]
optimize-filters-for-hits = true

result:

INSERT - Takes(s): 136.7, Count: 4000000, OPS: 29252.0, Avg(us): 3381, Min(us): 1009, Max(us): 371471, 95th(us): 7000, 99th(us): 8000
READ - Takes(s): 116.5, Count: 10000000, OPS: 85840.5, Avg(us): 1158, Min(us): 280, Max(us): 49137, 95th(us): 3000, 99th(us): 5000

@huachaohuang

@huachaohuang
Copy link
Contributor

What are the size of memory and dataset, how about the cache hit ratio?

@solotzg
Copy link
Contributor Author

solotzg commented Nov 12, 2018

TiKV master:

memory: 5353607168
disk:
  12K     ./data/import
  367M    ./data/raft
  3.0G    ./data/db
  4.0K    ./data/snap
  3.4G    ./data
block_cache_data_hit: 71.1K ops

TiKV _optimize_filters_for_hits:

memory: 5177335808
disk:
  12K     ./data/import
  188M    ./data/raft
  3.0G    ./data/db
  4.0K    ./data/snap
  3.2G    ./data
block_cache_data_hit: 72.7K ops

@huachaohuang But the benchmark result is not stable. Sometimes, TiKV master is better.

@solotzg
Copy link
Contributor Author

solotzg commented Nov 13, 2018

TiKV master:

image
image
image
image
image

TiKV _optimize_filters_for_hits:

image
image
image
image
image

Test

Both test cases have loaded 30m records, and benchmark reading under situation

memory limit 2G
max-open-files = 4096
max-write-buffer-number = 2
rocksdb.defaultcf.block-cache-size = "512MB"
rocksdb.lockcf.block-cache-size = "128MB"
rocksdb.writecf.block-cache-size = "256MB"
raftdb.defaultcf.block-cache-size = "128MB"

But performance of the one optimized is not as good as expected. Maybe there are some other operations in txn of go-ycsb.
Further research needs to be done.

@solotzg solotzg added the S: DNM label Nov 13, 2018
@solotzg solotzg changed the title Introduce optimize_filters_for_hits to cf_config [DNM] Introduce optimize_filters_for_hits to cf_config Nov 13, 2018
@solotzg
Copy link
Contributor Author

solotzg commented Nov 19, 2018

Newest Test

TiKV _optimize_filters_for_hits

TiKV Configuration

[rocksdb.defaultcf]
optimize-filters-for-hits = true
level0-file-num-compaction-trigger=2
level0-slowdown-writes-trigger=2
level0-stop-writes-trigger=2
max-write-buffer-number=2
max-bytes-for-level-base="500GB"
block-cache-size="1GB"

[rocksdb.lockcf]
optimize-filters-for-hits = false
max-write-buffer-number=2
block-cache-size="128MB"

[rocksdb.writecf]
optimize-filters-for-hits = false
max-write-buffer-number=2
block-cache-size="256MB"

[raftdb]

[raftdb.defaultcf]
optimize-filters-for-hits = true
max-write-buffer-number=2
block-cache-size="128MB"

Test Result

go-ycsb load data

recordcount=20000000
operationcount=20000000
fieldcount=15
fieldlength=10

go-ycsb read data

READ - Takes(s): 883.8, Count: 10249737, OPS: 11597.1, Avg(us): 8618, Min(us): 311, Max(us): 90707, 95th(us): 12000, 99th(us): 15000

TiKV master

TiKV Configuration

[rocksdb.defaultcf]
optimize-filters-for-hits = false
level0-file-num-compaction-trigger=2
level0-slowdown-writes-trigger=2
level0-stop-writes-trigger=2
max-write-buffer-number=2
max-bytes-for-level-base="500GB"
block-cache-size="1GB"

[rocksdb.lockcf]
optimize-filters-for-hits = false
max-write-buffer-number=2
block-cache-size="128MB"

[rocksdb.writecf]
optimize-filters-for-hits = false
max-write-buffer-number=2
block-cache-size="256MB"

[raftdb]

[raftdb.defaultcf]
optimize-filters-for-hits = false
max-write-buffer-number=2
block-cache-size="128MB"

Test Result

go-ycsb load data

recordcount=20000000
operationcount=20000000
fieldcount=15
fieldlength=10

go-ycsb read data

READ - Takes(s): 1079.1, Count: 12212303, OPS: 11316.7, Avg(us): 8832, Min(us): 551, Max(us): 115857, 95th(us): 12000, 99th(us): 16000

Grafana

The previous is optimized, the next is master.
image
image
image
image

@solotzg solotzg removed the S: DNM label Nov 19, 2018
@solotzg solotzg changed the title [DNM] Introduce optimize_filters_for_hits to cf_config Introduce optimize_filters_for_hits to cf_config Nov 19, 2018
@huachaohuang
Copy link
Contributor

Setup

Hardware

  • CPU: 40 vCPUs, Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
  • SSD: 1.6T, Intel 3610
  • MEM: 2GB

Configurations

[readpool.storage]
normal-concurrency = 16
[rocksdb.defaultcf]
block-cache-size = "512MB"
[rocksdb.lockcf]
block-cache-size = "128MB"
[rocksdb.writecf]
block-cache-size = "256MB"
[raftdb.defaultcf]
block-cache-size = "128MB"

Dataset: number of keys = 100,000,000, value size = 64B

Results

optimize filters for hits data size index and filter size (default) index and filter size (write) block cache hit (data) read ops
false 11965MB 141.3MB 138.2MB 30.1% 6741.4
true 11820MB 26.9MB 137.7MB 31.9% 7119.8

Conclusion: the optimization in this PR increases the read ops in this PR for 5.6%.

@solotzg solotzg added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 27, 2018
Copy link
Contributor

@DorianZheng DorianZheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DorianZheng DorianZheng merged commit 14812b7 into tikv:master Nov 27, 2018
@solotzg solotzg deleted the _optimize_filters_for_hits branch October 16, 2019 11:18
sticnarf pushed a commit to sticnarf/tikv that referenced this pull request Oct 27, 2019
Signed-off-by: Tong Zhigao <tongzhigao@pingcap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/rocksdb Component: RocksDB engine status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants