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

Add support for ReadFrom.subnet #1569

Closed
yueki1993 opened this issue Dec 28, 2020 · 2 comments
Closed

Add support for ReadFrom.subnet #1569

yueki1993 opened this issue Dec 28, 2020 · 2 comments
Labels
type: feature A new feature
Milestone

Comments

@yueki1993
Copy link
Contributor

yueki1993 commented Dec 28, 2020

Feature Request

I want ReadFrom.Subnet feature which read from any node in the configured subnets.
Original motivation of this proposal is, I want to read from a (AWS elasticache) redis node in the same availability zone from an application.
Reading from the same availability zone reduces latency and costs as AWS charges traffics between different availability zones.
While AWS claims AZs are engineered to provide low latency network connectivity to other AZs in the same region (see link), a simple benchmark shows crossing availability zone leads bad latency:

$ redis-cli -h <same AZ node>  --latency
min: 0, max: 19, avg: 0.38 (2088 samples)
$ redis-cli -h <different AZ node>  --latency
min: 1, max: 21, avg: 1.21 (2061 samples)

Currently lettuce supports ReadFrom.NEAREST, a option of reading from any node with the lowest latency.
For my usecase it would work well if there is only one node in an availability zone.
However if there are more than two nodes in an availability zone, the option may lead unbalanced loads between the nodes.
Imagine that an extreme case - there are two read replicas in an availability zone and one lettuce application with NEAREST option deployed to the same availability zone with the replicas, the application always reads from one read replica and the other one is not used until the next topology refresh. (I did not test NEAREST actually, sorry if I am wrong)

I believe lettuce should be vendor-independent and avoid AWS specific APIs, so I want to propose to use subnets to read from a node of the same availability zone.
I think we can use this feature for other clouds or on-premises.

As you know lettuce is well-designed and I can implement such ReadFromSubnet class by myself in my project, but I believe this feature will be in demand to other developers.

If my proposal seems reasonable I can submit a PR.

Is your feature request related to a problem? Please describe

Crossing availbility zone leads bad latency and costs.

Describe the solution you'd like

Add support ReadFromSubnet feature:

    static final class ReadFromSubnet extends ReadFrom {

        private final List<IpSubnetFilterRule> rules = new ArrayList<>();

        ReadFromSubnet(String... cidrNotations) {
            // ...
        }

        @Override
        public List<RedisNodeDescription> select(Nodes nodes) {
            ArrayList<RedisNodeDescription> result = new ArrayList<>();
            for (RedisNodeDescription node : nodes) {
                if (isInSubnetRange(node.getUri())) {
                    result.add(node);
                }
            }

            return result;
        }

        private boolean isInSubnetRange(RedisURI redisURI) {
            // return true if redisURI is in the subnets otherwise false.
        }
    }

To calculate subnet netty's IpSubnetFilterRule seems good as we do not need additional dependency.

Describe alternatives you've considered

AWS API like DescribeCacheClusters would work,
but we need an elephant awssdk dependency and this makes lettuce vendor locked-in.

Teachability, Documentation, Adoption, Migration Strategy

We need to add information to wiki page.

Example

image

@yueki1993
Copy link
Contributor Author

#1570
I've just submitted a PR of this proposal.
If this proposal is nonsense, please close this issue and pull request.
(In Japan we have long new year holidays but you know, due to covid-19 I need to stay home and am really bored to stay home. Sorry for sending PR before your response. Happy new year and stay safe!)

@yueki1993 yueki1993 changed the title Add support ReadFromSubnet Add support for ReadFrom.subnet Jan 1, 2021
yueki1993 added a commit to yueki1993/lettuce-core that referenced this issue Jan 1, 2021
Lettuce now supports ReadFrom.subnet which is an option of reading from any node in the given subnets.
@mp911de mp911de added the type: feature A new feature label Jan 1, 2021
@mp911de
Copy link
Collaborator

mp911de commented Jan 1, 2021

Thanks a lot. It makes sense to use netty utilities to build a subnet-based ReadFrom rule. Not depending on AWS SDK makes sense as we don't want to include any cloud-vendor specific dependencies.

@mp911de mp911de added this to the 6.1 M1 milestone Feb 3, 2021
mp911de pushed a commit that referenced this issue Feb 3, 2021
Lettuce now supports ReadFrom.subnet which is an option of reading from any node in the given subnets.

Original pull request: #1570.
mp911de added a commit that referenced this issue Feb 3, 2021
Introduce LRU cache to reduce GC pressure when creating BigInteger and int address objects. Extract methods and tweak assertion wording. Update since tags. Accept orderSensitive when creating regex-based ReadFrom variant.

Original pull request: #1570.
@mp911de mp911de closed this as completed Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants