Skip to content

os/bluestore: [RFC] onode_map changes, better documentation for bluefs_buffered_io - #40351

Closed
markhpc wants to merge 3 commits into
ceph:masterfrom
markhpc:wip-buffered_io-merry-go-round
Closed

markhpc wants to merge 3 commits into
ceph:masterfrom
markhpc:wip-buffered_io-merry-go-round

Conversation

@markhpc

@markhpc markhpc commented Mar 23, 2021 •

Copy link
Copy Markdown
Member

This is the first part in (hopefully) a series to try to improve bluefs omap performance, especially based on the multiple user issues that have been reported in various bugs, issues, and PRs (see especially #38044) with the bluefs_buffered_io=false change.

In #39976 a new benchmark was introduced to try and better understand how OMAP performs in different situations. A number of tests were performed with 100K objects each with 100 omap entries for 10M total entries. 100 unique hobject_t hashes were used to simulate the effect of spreading those objects across 100 PGs. Each omap entry has a 64byte key and 256byte value which roughly aligns with values pulled from rocksdb sst files from an RBD volume (though especially with RGW these values could be highly variable). The aggregate dataset size (~3GB) was chosen specifically to not quite fully fit inside the rocksdb block cache once populated at the default 4GB osd_memory_target but easily will fit with a larger memory target (16GB). Debug 5 was used to confirm that the priority cache memory autotuning gave rocksdb as much memory as it could to cache OMAP data (about 2.6-2.8GB in the 4GB target tests). cgroups were used to limit the process memory to 4GB or 16GB for each respective test which appears to also be setting a quota for page cache usage (Need to verify?).

The following tables showcase some of the most interesting behaviors observed:

omap_setkeys:

onode_map
Data Structure
Store 4G Buffered 4G Direct 16G Buffered 16G Direct 4G Buffered 4G Direct 16G Buffered 16G Direct
name sorted name sorted name sorted name sorted std sorted std sorted std sorted std sorted
filestore         33.87   33.61  
unordered_map bluestore 6.10 5.82 5.90 5.88 4.64 4.72 4.72 4.67
map bluestore 4.01       4.11 4.09 4.09 4.13

omap_get:

onode_map
Data Structure
Store 4G Buffered 4G Direct 16G Buffered 16G Direct 4G Buffered 4G Direct 16G Buffered 16G Direct
name sorted name sorted name sorted name sorted std sorted std sorted std sorted std sorted
filestore 19.80 11.56
unordered_map bluestore 54.19 66.01 10.67 66.32 38.31 53.53 8.25 53.70 
map bluestore 50.38       37.30 52.37 7.31 51.98

seek_to_first iteration:

onode_map
Data Structure
Store 4G Buffered 4G Direct 16G Buffered 16G Direct 4G Buffered 4G Direct 16G Buffered 16G Direct
name sorted name sorted name sorted name sorted std sorted std sorted std sorted std sorted
filestore         7.48   7.37  
unordered_map bluestore 48.88 59.44 6.64 6.02 35.34 50.76 6.52 5.34
map bluestore 49.70       34.99 50.92 5.90 5.38

lower_bound iteration:

onode_map
Data Structure
Store 4G Buffered 4G Direct 16G Buffered 16G Direct 4G Buffered 4G Direct 16G Buffered 16G Direct
name sorted name sorted name sorted name sorted std sorted std sorted std sorted std sorted
filestore         7.19   7.23  
unordered_map bluestore 48.67 59.32 6.60 5.63 37.51 50.64 6.58 5.39
map bluestore 48.94       38.06 50.50 5.96 5.32

remove

onode_map
Data Structure
Store 4G Buffered 4G Direct 16G Buffered 16G Direct 4G Buffered 4G Direct 16G Buffered 16G Direct
name sorted name sorted name sorted name sorted std sorted std sorted std sorted std sorted
filestore         73.56   46.37  
unordered_map bluestore 2393 1835 1994 1659 106.32 115.34 11.87 45.09
map bluestore 2380       108.99 115.18 12.54 47.07

Some conclusions that appear to be reasonable to draw from these tests:

  1. Bluestore appears to be much faster than filestore for omap_setkeys. In bluestore, the onode_map is implemented with an unordered_map that is vulnerable to slow performance when there are collisions hash function. With the way we populate the hobject_t hash, this manifests when the pg count is low. These tests try to simulate a pg count of 100, but in reality a lower pg count could result in a worse performance discrepancy than shown here (In cases with many collisions the effect can be significant). There are two options for improving this: (a) Simply use a data structure like std::map, btree, flatmap, etc that isn't impacted by hash collisions. (b) provide a custom std::hash specialization for the onode_map that has fewer collisions. This PR currently switches the data structure to std::map based on the belief that the onode_map will not grow excessively large due to sharding (@aclamk) and remain fast, but it's possible that with a better hash specialization for ghobject_t, unordered_map would be faster yet.

  2. omap_get performs significantly faster when using buffered IO than direct IO. This seems to be the case even when there is enough memory available for rocksdb to cache all blocks. The primary benefit for the buffered IO tests appears to be the availability of additional page cache rather than increased block cache. This is likely the reason that filestore is faster when memory limited (filestore uses less memory than bluestore, thus more page cache is available), but in the 16GB test bluestore is faster (both have sufficient page cache to cache all SST files). Calling omap_get on ghobject_ts in the proper order (ie using std::sort rather than sorting based on object name) improves performance in all tested cases.

  3. Iteration performance is extremely fast when all OMAP entries fit in the block cache and significantly worse when they don't. It's possible that bluestore may do better with lots of page cache and buffered IO even if the block cache isn't big enough based on the filestore results. @aclamk and I believe we may be seeing a pathologically bad case here where blocks at the beginning of an iteration may be forced out of cache at the end of the iteration, causing repeated iterations to continually reload blocks from disk. More investigation needs to happen here, though using buffered IO provides a crutch in this case when there is sufficient page cache to allow repeated iteration to proceed quickly.

  4. remove performance is excessively slow in all cases when objects are removed in the wrong sorting order (ie when sorting by object name rather than by std::sort). This was the primary reason that several of the test cases were not completed in these charts. The best remove performance was removing in the properly sorted order using buffered io with lots of memory for page cache (or block cache). This was around 160x faster than the same test but removing in object name order. Using direct IO even with 16GB of memory for block cache was still 4x slower than using buffered IO, so there's more evidence here that we are doing extra disk reads even with a large block cache.

Given these findings, this PR does two things:

  1. reverts bluefs_buffered_io=false until we can at least show direct IO to be as fast as buffered IO in the new OmapBench tests from [RFC] test/objectstore/store_test: First pass at an OmapBench test #39976 (with the knowledge that users may still see the excessive page cache usage issue that was reported by the perf and scale team. Provide documentation in the configuration option stating such).

  2. switch onode_map to std::map. This is a little controversial as if there are any unexpected situations where the onode_map can grow excessively large, this should be slower than unordered_map. This is a very straightforward way to avoid the hash collision issue however and in practice @aclamk believes we should not see the onode_map grow excessively large due to sharding. There still may be a reasonable argument that we should keep unordered_map and instead provide a custom hash specialization for ghobject_t that avoids collisions, but ultimately if onode_map stays small both may be reasonable solutions to the issue.

Additional things that should be done in the future:

  1. Audit all places we keep lists/vectors/etc of ghobject_t objects and make sure we are performing operations against them in the proper sorted order when possible.
  2. Continue to debug why rocksdb's block cache does not appear to be as effective as the page cache in many of these tests.
  3. Continue to debug what's going on with rocksdb prefetch and how different versions work (there has been significant code churn over the last 3 years).
  4. Consider alternate solutions to the rocksdb block cache such as a higher level OMAP cache, KeyValueDB cache, or lower level bluefs cache.

Checklist

  • References tracker ticket
  • Updates documentation if necessary
  • Includes tests for new functionality or reproducer for bug

Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox

Comment thread src/os/bluestore/BlueStore.h Resolved
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@markhpc
markhpc force-pushed the wip-buffered_io-merry-go-round branch from 08fb0a4 to fd4b8c6 Compare March 25, 2021 14:13
@markhpc markhpc changed the title os/bluestore: [RFC] Revert bluefs_buffered_io=false, other omap improvements os/bluestore: [RFC] onode_map changes, better documentation for bluefs_buffered_io Mar 25, 2021
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@markhpc

markhpc commented Apr 30, 2021 •

Copy link
Copy Markdown
Member Author

Closing this in favor of #41109. We'll revisit the onode_map data structure after @ronen-fr has played with a specialized unordered_map hash implementation to see if he can reduce collisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants