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

StateDB Cache #350

Merged
merged 17 commits into from
Feb 7, 2018
Merged

StateDB Cache #350

merged 17 commits into from
Feb 7, 2018

Conversation

Corey-Zumar
Copy link
Contributor

Fixes #329

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/818/
Test FAILed.

@dcrankshaw
Copy link
Contributor

jenkins test this please

Copy link
Contributor

@dcrankshaw dcrankshaw left a comment

Choose a reason for hiding this comment

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

This looks pretty good. It doesn't look like you ever evict things from the cache. Is that intentional?

std::string redis_key = generate_redis_key(key);
const std::vector<std::string> cmd_vec{"GET", redis_key};
auto result =
redis::send_cmd_with_reply<std::string>(redis_connection_, cmd_vec);
Copy link
Contributor

Choose a reason for hiding this comment

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

If you fetch the value from Redis, you should cache it here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

auto entry_search = cache_.find(key);
bool new_entry = (entry_search == cache_.end());
if (!new_entry) {
std::lock_guard<std::mutex> lock(entry_search->second->entry_mtx_);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of this lock? It will be released once it goes out of scope, so it won't be held after the if-statement.

// This method is being invoked as part of the 'add application'
// procedure in the query frontend. Because any subsequent feedback
// updates to the StateDB depend on the completion of 'add application',
// it's safe to add a new cache entry immediately
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm will this always be true? This seems like a complicated behavior to rely on for safety. What if another code path ends up putting things in the StateDB? Will that break this code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh I understand your comment now. Can you clarify in the comment that if we are creating a new entry, it means that the method is being invoked as part of adding an application?

But my previous question still remains, this seems like tricky behavior to rely on for safety.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/819/
Test PASSed.

@Corey-Zumar
Copy link
Contributor Author

@dcrankshaw A couple questions regarding performance vs consistency tradeoffs:

  1. In order to ensure strong consistency, it's necessary to update the cache and database as a single atomic operation. Therefore, writers need to hold a lock on both the cache and redox handle until the write is complete. This seems fine if most StateDB operations are reads and we don't frequently evict elements (this is currently the case). However, if the distribution of reads and writes becomes more balanced and we intend to evict elements, we may not see much of an improvement in performance by adding the cache. Can we make any assumptions about StateDB access patterns going forward?

  2. Another option is to use a weaker consistency model. If we take a lock on the redox handle during a write, we can ensure consistent ordering between writers. However, readers will continue to read old values from the cache until the thread that completed the Redox write operation is able to write the new cache value. This model will perform significantly faster in the case of simultaneous reads and writes. Does this sound like a better approach?

@Corey-Zumar
Copy link
Contributor Author

@dcrankshaw I redesigned the put and get procedures to meet the following requirements:

  1. Write operations are serialized
  2. Read operation results reflect all prior writes (they may also reflect subsequent writes)

This design no longer makes any assumptions about the origin of the first put call.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/912/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/914/
Test FAILed.

@Corey-Zumar
Copy link
Contributor Author

jenkins test this please

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/917/
Test FAILed.

Copy link
Contributor

@dcrankshaw dcrankshaw left a comment

Choose a reason for hiding this comment

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

LGTM. Will merge once tests pass.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/935/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/945/
Test FAILed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/969/
Test PASSed.

@Corey-Zumar Corey-Zumar merged commit 137cc85 into ucbrise:develop Feb 7, 2018
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