Skip to content

optimize populate_startup_nodes method#11

Open
pathbox wants to merge 1 commit intoantirez:masterfrom
pathbox:master
Open

optimize populate_startup_nodes method#11
pathbox wants to merge 1 commit intoantirez:masterfrom
pathbox:master

Conversation

@pathbox
Copy link
Copy Markdown

@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