-
Notifications
You must be signed in to change notification settings - Fork 30
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
Refactoring #65
Open
benashford
wants to merge
16
commits into
master
Choose a base branch
from
refactoring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactoring #65
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Do some wholesale refactoring to tidy-up loose ends.
Summary
The previous two releases of
redis-async-rs
had some compromises that needed to be introduced for correctness while maintaining backward compatibility. In particular a Mutex had to be introduced to resolve contention when ascertaining the state of the shared connection that could be written to by multiple tasks, and due to guarantees advertised by the API, it had to be astd::sync::Mutex
rather than an async/await compatible Mutex.Of course this is an anti-pattern which should be avoided as it can cause a multi-threaded runtime to become synchronised in a way that isn't desirable. Fortunately the period of the lock is so short it didn't cause any noticeable practical problems.
However, it still shouldn't exist. So this PR makes the necessary breaking changes to enable a solution that has no Mutex.
In practice this changes the API in a few subtle ways (types of parameters), but clients should be able to upgrade with no significant difficulties.
One breaking change that I won't make as-yet is the guarantee that commands are sent to Redis in the same order as calls to
send
are made. It requires some internal complexity, and arguably it's not idiomatic, but I'm retaining it as a feature for now because if anything depends on it it may come as an unpleasant surprise if it were to suddenly stop. Basically, callingsend
isn't an asynchronous operation (and is non-blocking) but it returns a future which is asynchronous in order to read the result.I will however, stop advertising that guarantee as a feature so that a forthcoming major release might drop that guarantee.
Also...
This enables switching of runtimes with feature flags. Tokio 1.0 is the default, but Tokio 0.2 is also supported. There is also experimental support for Async-Std, but this should be considered unstable at this stage.
Performance
Removing the Mutex with an indirect queue does seem to have a fairly hefty performance penalty (40% or so) for single-threaded situations, but should be better in more complex situations where there would otherwise be contention for the lock.