Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Session optimizations #9600

Merged
merged 49 commits into from Nov 29, 2020
Merged

Session optimizations #9600

merged 49 commits into from Nov 29, 2020

Conversation

TimothyBanks
Copy link
Contributor

Change Description

Removed cache.hpp and moved it entirely into session. Updated session by rolling all the containers used to managed various state information into 1 container.

Change Type

Select ONE

  • Documentation
  • Stability bug fix
  • Other
  • Other - special case

Consensus Changes

  • Consensus Changes

API Changes

  • API Changes

Documentation Additions

  • Documentation Additions

auto key = eosio::session::shared_bytes{sizeof(uint64_t) + prefix_key.size() + move_to_rocks->kv_key.size()};
std::copy(std::begin(prefix_key), std::end(prefix_key), std::begin(key));
b1::chain_kv::insert_key(key, prefix_key.size(), move_to_rocks->contract.to_uint64_t());
std::copy(std::begin(move_to_rocks->kv_key), std::end(move_to_rocks->kv_key), std::begin(key) + prefix_key.size() + sizeof(uint64_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

So how is it safe for eosio::session::shared_bytes to share a key buffer that can be updated? I thought the point was that it was created and was constant from then on.

Also, is this faster than using the make_shared_bytes method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how I originally intended it to be but it seemed like there was a lot of temporary buffers being created when I could just allow the user to write directly into the shared_bytes.

It depends. If you already have a buffer that you are wanting to copy from then you'd want to instantiate the shared_bytes with that buffer. If you have to construct a buffer, then it will be a bit more efficient to just create the shared_bytes instance with a length and construct it in place.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does the session return the same shared_bytes keys and values that it holds internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussion about this was on slack.

Copy link
Contributor

@larryk85 larryk85 left a comment

Choose a reason for hiding this comment

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

As this isn't on the critical path for the immediate future, it will be a while before this PR is reviewed.

This also introduces breaking changes to the API that some of the other engineers are actively developing against, so I suggest that this gets put on the back burner until all issues with RocksDB as a feature are hammered out.

Don't merge this PR until it has my go-ahead.

@TimothyBanks TimothyBanks changed the title Various updates to address optimization problems with Session Session optimizations Nov 20, 2020
Copy link
Contributor

@larryk85 larryk85 left a comment

Choose a reason for hiding this comment

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

Some requests to get started on.

libraries/chain/combined_database.cpp Outdated Show resolved Hide resolved
libraries/chain_kv/include/b1/session/rocks_comparator.hpp Outdated Show resolved Hide resolved
libraries/chain_kv/include/b1/session/rocks_session.hpp Outdated Show resolved Hide resolved
libraries/chain_kv/include/b1/session/rocks_session.hpp Outdated Show resolved Hide resolved
// keys that have been deleted during this session.
mutable std::unordered_set<shared_bytes> m_deleted_keys;
parent_variant_type m_parent{ nullptr };
mutable cache_type m_cache;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know of a good reason why we want the cache to be mutable.

I would say that from a logical const-ness view point, the cache manipulations have external observable side effects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That means that all methods on this type cannot be const. So if you're fine with that I will remove mutable from this data member. The problem is that the "iterator cache" needs to be updated, so if we are calling that an observable side effect, then none of the methods can be const. I can imagine that this change will cascade out to other interfaces that take a const session type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't really feasible. Once we remove mutable, it forces us to remove const on those member functions in session which cascades into other types that hold a reference to session and forces us to either const cast that reference or remove const on those member functions (for example, db_context_rocksdb holds a session and it has const member functions and I'm assuming that whomever holds a reference to db_context_rocksdb also has const member functions). It is quite the rabbit hole.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll see how far down it goes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It stopped at db_context_rocksdb. Change has been made and pushed up.

libraries/chain_kv/include/b1/session/session.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@brianjohnson5972 brianjohnson5972 left a comment

Choose a reason for hiding this comment

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

Some of these are optional, but I feel like the mutable interface of shared_bytes should be changed to have an mutable class, with no copy ctor or operator=, for creation and then that class is moved to the shared_bytes, which is immutable. Not sure how big an impact that is, but ir it is not huge I think shared_bytes, since the session is handing off access to its cached data, should not give everyone the right to write over its cache, particularly since half of those shared_bytes are used for sorting in containers.

libraries/chain/backing_store/db_context_rocksdb.cpp Outdated Show resolved Hide resolved
libraries/chain/combined_database.cpp Outdated Show resolved Hide resolved
libraries/chain/combined_database.cpp Outdated Show resolved Hide resolved
auto key = eosio::session::shared_bytes{sizeof(uint64_t) + prefix_key.size() + move_to_rocks->kv_key.size()};
std::copy(std::begin(prefix_key), std::end(prefix_key), std::begin(key));
b1::chain_kv::insert_key(key, prefix_key.size(), move_to_rocks->contract.to_uint64_t());
std::copy(std::begin(move_to_rocks->kv_key), std::end(move_to_rocks->kv_key), std::begin(key) + prefix_key.size() + sizeof(uint64_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the session return the same shared_bytes keys and values that it holds internally?

libraries/chain_kv/include/b1/session/rocks_comparator.hpp Outdated Show resolved Hide resolved
libraries/chain_kv/include/b1/session/session.hpp Outdated Show resolved Hide resolved
libraries/chain_kv/include/b1/session/session.hpp Outdated Show resolved Hide resolved
libraries/chain_kv/include/b1/session/undo_stack.hpp Outdated Show resolved Hide resolved
@TimothyBanks
Copy link
Contributor Author

Updated.

@brianjohnson5972 brianjohnson5972 dismissed their stale review November 25, 2020 22:58

The important issues were addressed, but leaving approval for Bucky.

@larryk85 larryk85 merged commit e8c3d7d into develop Nov 29, 2020
@larryk85 larryk85 deleted the session-optimizations-new branch November 29, 2020 23:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants