Skip to content

Commit 126147c

Browse files
author
fusikai
committed
add redis cluster experiment
1 parent bd0943b commit 126147c

File tree

26,526 files changed

+2910245
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

26,526 files changed

+2910245
-7
lines changed

Dockerfile

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
FROM ubuntu:16.04
22

33
ADD ./sources.list /etc/apt/sources.list
4+
ADD ./ruby /root/ruby
45

5-
RUN apt-get update && apt-get install -y git build-essential
6+
ENV PATH /root/redis/redis/bin:/usr/local/ruby/bin:$PATH
67

7-
ENV PATH /root/redis/redis/bin:$PATH
8+
RUN apt-get update && apt-get install -y git build-essential wget
9+
10+
RUN cd /root/ruby && ./ruby.sh
11+
12+
ADD ./redis-5.0.5/src/redis-trib.rb /usr/local/bin/redis-trib.rb

docker-compose.yml

+17-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,23 @@ services:
3131
- "7005:7005"
3232
networks:
3333
mynet:
34-
ipv4_address: 172.25.1.103
34+
ipv4_address: 172.25.1.103
35+
ruby-redis:
36+
build: .
37+
volumes:
38+
- ./:/root/redis
39+
working_dir: /root/redis/ruby-redis
40+
command: 'bash run.sh'
41+
ports:
42+
- "8001:8001"
43+
- "8002:8002"
44+
- "8003:8003"
45+
- "8004:8004"
46+
- "8005:8005"
47+
- "8006:8006"
48+
networks:
49+
mynet:
50+
ipv4_address: 172.25.1.104
3551
networks:
3652
mynet:
3753
driver: bridge

makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY:run
22
run:
3-
docker-compose run --rm redis1 bash
3+
docker-compose run --rm redis-sentinel bash
44
.PHONY:attach
55
attach:
6-
docker-compose exec redis1 bash
6+
docker-compose exec redis-sentinel bash

redis-cluster/makefile

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
.PHONY: info7000
33
info7000:
44
redis-cli -p 7000 info replication
5+
.PHONY: cluter7000
6+
cluter7000:
7+
redis-cli -p 7000 cluster info
8+
.PHONY: infonodes
9+
infonodes:
10+
redis-cli -p 7000 cluster nodes
11+
.PHONY: infoslots
12+
infoslots:
13+
redis-cli -p 7000 cluster slots
514
# clean the project
615
.PHONY: clean
716
clean:
8-
rm *.log
17+
rm *.log

redis-cluster/run.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@ for port in ${redisserverports[@]}; do
55
mkdir -p /root/data/$port
66
redis-server redis-$port.conf
77
done
8-
8+
# meet
99
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7001
1010
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7002
1111
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7003
1212
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7004
1313
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7005
1414

15+
# assign nodes
1516
redis-cli -h 127.0.0.1 -p 7000 cluster addslots {0..5461}
1617
redis-cli -h 127.0.0.1 -p 7001 cluster addslots {5462..10922}
1718
redis-cli -h 127.0.0.1 -p 7002 cluster addslots {10923..16383}
1819

20+
# replicate
21+
# redis-cli -p 7003 cluster replicate ?
22+
# redis-cli -p 7004 cluster replicate ?
23+
# redis-cli -p 7005 cluster replicate ?
24+
1925
while true
2026
do
2127
sleep 5s

ruby-redis/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.log

ruby-redis/7000.log

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
7:C 01 Nov 2019 05:41:31.123 # Can't chdir to '/root/data/7000': No such file or directory
2+
7:C 01 Nov 2019 05:44:57.175 # Can't chdir to '/root/data/7000': No such file or directory
3+
7:C 01 Nov 2019 05:49:18.382 # Can't chdir to '/root/data/7000': No such file or directory

ruby-redis/7003.log

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
18:C 01 Nov 2019 05:41:31.182 # Can't chdir to '/root/data/7003': No such file or directory
2+
18:C 01 Nov 2019 05:44:57.247 # Can't chdir to '/root/data/7003': No such file or directory

ruby-redis/7005.log

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
23:C 01 Nov 2019 05:41:31.202 # Can't chdir to '/root/data/7005': No such file or directory
2+
26:C 01 Nov 2019 05:44:57.266 # Can't chdir to '/root/data/7005': No such file or directory

ruby-redis/8000.log

Whitespace-only changes.

ruby-redis/8001.log

Whitespace-only changes.

ruby-redis/8002.log

Whitespace-only changes.

ruby-redis/8003.log

Whitespace-only changes.

ruby-redis/8004.log

Whitespace-only changes.

ruby-redis/8005.log

Whitespace-only changes.

ruby-redis/makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY:kill
2+
kill:
3+
ps -ef |grep redis-server |grep 800 | awk '{print $2}' | xargs kill

ruby-redis/redis-8000.conf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
port 8000
2+
bind 0.0.0.0
3+
daemonize yes
4+
pidfile /var/run/redis-8000.pid
5+
logfile "8000.log"
6+
dir "/root/data/8000"
7+
dbfilename "dump-8000.rdb"
8+
cluster-enabled yes
9+
cluster-node-timeout 15000
10+
# cluster-config-file "nodes.conf"
11+
cluster-require-full-coverage no

ruby-redis/redis-8001.conf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
port 8001
2+
bind 0.0.0.0
3+
daemonize yes
4+
pidfile /var/run/redis-8001.pid
5+
logfile "8001.log"
6+
dir "/root/data/8001"
7+
dbfilename "dump-8001.rdb"
8+
9+
cluster-enabled yes
10+
cluster-node-timeout 15000
11+
# cluster-config-file "nodes.conf"
12+
cluster-require-full-coverage no

ruby-redis/redis-8002.conf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
port 8002
2+
bind 0.0.0.0
3+
daemonize yes
4+
pidfile /var/run/redis-8002.pid
5+
logfile "8002.log"
6+
dir "/root/data/8002"
7+
dbfilename "dump-8002.rdb"
8+
9+
cluster-enabled yes
10+
cluster-node-timeout 15000
11+
# cluster-config-file "nodes.conf"
12+
cluster-require-full-coverage no

ruby-redis/redis-8003.conf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
port 8003
2+
bind 0.0.0.0
3+
daemonize yes
4+
pidfile /var/run/redis-8003.pid
5+
logfile "8003.log"
6+
dir "/root/data/8003"
7+
dbfilename "dump-8003.rdb"
8+
9+
cluster-enabled yes
10+
cluster-node-timeout 15000
11+
# cluster-config-file "nodes.conf"
12+
cluster-require-full-coverage no

ruby-redis/redis-8004.conf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
port 8004
2+
bind 0.0.0.0
3+
daemonize yes
4+
pidfile /var/run/redis-8004.pid
5+
logfile "8004.log"
6+
dir "/root/data/8004"
7+
dbfilename "dump-8004.rdb"
8+
9+
cluster-enabled yes
10+
cluster-node-timeout 15000
11+
# cluster-config-file "nodes.conf"
12+
cluster-require-full-coverage no

ruby-redis/redis-8005.conf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
port 8005
2+
bind 0.0.0.0
3+
daemonize yes
4+
pidfile /var/run/redis-8005.pid
5+
logfile "8005.log"
6+
dir "/root/data/8005"
7+
dbfilename "dump-8005.rdb"
8+
9+
cluster-enabled yes
10+
cluster-node-timeout 15000
11+
# cluster-config-file "nodes.conf"
12+
cluster-require-full-coverage no

ruby-redis/run.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
redisserverports=("8000" "8001" "8002" "8003" "8004" "8005")
3+
for port in ${redisserverports[@]}; do
4+
echo "start redis server $port"
5+
mkdir -p /root/data/$port
6+
redis-server redis-$port.conf
7+
done
8+
# 使用redis原生命令行生成redis cluster
9+
# redis-cli --cluster create --cluster-replicas 1 127.0.0.1:8000 127.0.0.1:8001 127.0.0.1:8002 127.0.0.1:8003 127.0.0.1:8004 127.0.0.1:8005
10+
while true
11+
do
12+
sleep 5s
13+
done

ruby/redis-4.1.3.gem

56 KB
Binary file not shown.

ruby/ruby-2.6.5.tar.gz

15.4 MB
Binary file not shown.

ruby/ruby-2.6.5/.document

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This file determines which files in the
2+
# Ruby hierarchy will be processed by the RDoc
3+
# tool when it is given the top-level directory
4+
# as an argument
5+
6+
# Process all the C source files
7+
*.c
8+
*.y
9+
10+
# prelude
11+
prelude.rb
12+
13+
rbconfig.rb
14+
15+
# the lib/ directory (which has its own .document file)
16+
lib
17+
18+
# and some of the ext/ directory (which has its own .document file)
19+
ext
20+
21+
# rdoc files
22+
NEWS
23+
24+
README.md
25+
README.ja.md
26+
27+
COPYING
28+
COPYING.ja
29+
CONTRIBUTING.md
30+
31+
LEGAL
32+
33+
# win32/README.win32 linked from README.md
34+
win32
35+
36+
doc

ruby/ruby-2.6.5/.editorconfig

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
indent_size = 4
6+
indent_style = space
7+
insert_final_newline = true
8+
tab_width = 8
9+
trim_trailing_whitespace = true
10+
11+
[*.bat]
12+
end_of_line = crlf
13+
14+
[*.gemspec]
15+
indent_size = 2
16+
17+
[*.rb]
18+
indent_size = 2
19+
20+
[*.yml]
21+
indent_size = 2
22+
23+
[{*[Mm]akefile*,*.mak,*.mk,depend}]
24+
indent_style = tab
25+
26+
[reg*.[ch]]
27+
indent_size = 2

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.bigdecimal.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.digest.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.fiddle.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.forwardable.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.io.-.console.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.json.-.add.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.json.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.psych.-.handlers.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.psych.-.json.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.psych.-.nodes.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.psych.-.visitors.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.psych.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.ripper.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.-.syslog.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.RUBYCOMMONDIR.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.enc-trans.so.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.enc-trans.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/.include.-.ruby.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/rb_mjit_header.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.arith_seq.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.array.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.dln.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.fatal.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.gvl.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.load.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.marshal.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.popen_deadlock.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.st.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.-.vm.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.-test-.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.bigdecimal.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.cgi.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.digest.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.io.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.json.-.ext.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.racc.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.rbconfig.time

Whitespace-only changes.

ruby/ruby-2.6.5/.ext/.timestamp/x86_64-linux/.time

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'bigdecimal.so'
2+
3+
def BigDecimal.new(*args, **kwargs)
4+
warn "BigDecimal.new is deprecated; use BigDecimal() method instead.", uplevel: 1
5+
BigDecimal(*args, **kwargs)
6+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# frozen_string_literal: false
2+
#
3+
# require 'bigdecimal/jacobian'
4+
#
5+
# Provides methods to compute the Jacobian matrix of a set of equations at a
6+
# point x. In the methods below:
7+
#
8+
# f is an Object which is used to compute the Jacobian matrix of the equations.
9+
# It must provide the following methods:
10+
#
11+
# f.values(x):: returns the values of all functions at x
12+
#
13+
# f.zero:: returns 0.0
14+
# f.one:: returns 1.0
15+
# f.two:: returns 2.0
16+
# f.ten:: returns 10.0
17+
#
18+
# f.eps:: returns the convergence criterion (epsilon value) used to determine whether two values are considered equal. If |a-b| < epsilon, the two values are considered equal.
19+
#
20+
# x is the point at which to compute the Jacobian.
21+
#
22+
# fx is f.values(x).
23+
#
24+
25+
require 'bigdecimal'
26+
27+
module Jacobian
28+
module_function
29+
30+
# Determines the equality of two numbers by comparing to zero, or using the epsilon value
31+
def isEqual(a,b,zero=0.0,e=1.0e-8)
32+
aa = a.abs
33+
bb = b.abs
34+
if aa == zero && bb == zero then
35+
true
36+
else
37+
if ((a-b)/(aa+bb)).abs < e then
38+
true
39+
else
40+
false
41+
end
42+
end
43+
end
44+
45+
46+
# Computes the derivative of f[i] at x[i].
47+
# fx is the value of f at x.
48+
def dfdxi(f,fx,x,i)
49+
nRetry = 0
50+
n = x.size
51+
xSave = x[i]
52+
ok = 0
53+
ratio = f.ten*f.ten*f.ten
54+
dx = x[i].abs/ratio
55+
dx = fx[i].abs/ratio if isEqual(dx,f.zero,f.zero,f.eps)
56+
dx = f.one/f.ten if isEqual(dx,f.zero,f.zero,f.eps)
57+
until ok>0 do
58+
deriv = []
59+
nRetry += 1
60+
if nRetry > 100
61+
raise "Singular Jacobian matrix. No change at x[" + i.to_s + "]"
62+
end
63+
dx = dx*f.two
64+
x[i] += dx
65+
fxNew = f.values(x)
66+
for j in 0...n do
67+
if !isEqual(fxNew[j],fx[j],f.zero,f.eps) then
68+
ok += 1
69+
deriv <<= (fxNew[j]-fx[j])/dx
70+
else
71+
deriv <<= f.zero
72+
end
73+
end
74+
x[i] = xSave
75+
end
76+
deriv
77+
end
78+
79+
# Computes the Jacobian of f at x. fx is the value of f at x.
80+
def jacobian(f,fx,x)
81+
n = x.size
82+
dfdx = Array.new(n*n)
83+
for i in 0...n do
84+
df = dfdxi(f,fx,x,i)
85+
for j in 0...n do
86+
dfdx[j*n+i] = df[j]
87+
end
88+
end
89+
dfdx
90+
end
91+
end

0 commit comments

Comments
 (0)