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

optimize populate_startup_nodes method #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

optimize populate_startup_nodes method #11

wants to merge 1 commit into from

Conversation

pathbox
Copy link

@pathbox pathbox commented Dec 13, 2017

Hi antirez,

How do you do? I build the redis cluster for work recently. Then I read the source code in redis-rb-cluster seriously. Yeah, I am a Rubist. I find populate_startup_nodes method in cluster.rb that it can be optimized.

In populate_startup_nodes method, this line

@nodes.each{|n| @startup_nodes << n}

It run 16384 times @startup_nodes << n , I optimize this,

@cluster_slots.each do |item|
            ip, port = item[2]
            name = "#{ip}:#{port}"
            node = {
                :host => ip,
                :port => port,
                :name => name
            }
            @startup_nodes << node
        end

@cluster_slots is array, and its size is startup_nodes's size. My startup_nodes is

startup_nodes = [
        {:host => "127.0.0.1", :port => 7000},
        {:host => "127.0.0.1", :port => 7001},
        {:host => "127.0.0.1", :port => 7002}
    ]

@cluster_slots.each do |item| just run 3 times.

And I puts the @startup_nodes.uniq! , the result is same as old code.

Please review my code, if you think it is good, you can merge the pull request.

I'm happy to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant