Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
b70b459b
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b70b459b
编写于
1月 31, 2013
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TCP_NODELAY after SYNC: changes to the implementation.
上级
c85647f3
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
40 addition
and
26 deletion
+40
-26
redis.conf
redis.conf
+15
-0
src/anet.c
src/anet.c
+6
-6
src/anet.h
src/anet.h
+2
-2
src/cluster.c
src/cluster.c
+1
-1
src/config.c
src/config.c
+10
-6
src/networking.c
src/networking.c
+1
-1
src/redis.c
src/redis.c
+1
-1
src/redis.h
src/redis.h
+1
-1
src/replication.c
src/replication.c
+3
-8
未找到文件。
redis.conf
浏览文件 @
b70b459b
...
...
@@ -196,6 +196,21 @@ slave-read-only yes
#
# repl-timeout 60
# Disable TCP_NODELAY on the slave socket after SYNC?
#
# If you select "yes" Redis will use a smaller number of TCP packets and
# less bandwidth to send data to slaves. But this can add a delay for
# the data to appear on the slave side, up to 40 milliseconds with
# Linux kernels using a default configuration.
#
# If you select "no" the delay for data to appear on the slave side will
# be reduced but more bandwidth will be used for replication.
#
# By default we optimize for low latency, but in very high traffic conditions
# or when the master and slaves are many hops away, turning this to "yes" may
# be a good idea.
repl
-
disable
-
tcp
-
nodelay
no
# The slave priority is an integer number published by Redis in the INFO output.
# It is used by Redis Sentinel in order to select a slave to promote into a
# master if the master is no longer working correctly.
...
...
src/anet.c
浏览文件 @
b70b459b
...
...
@@ -75,9 +75,9 @@ int anetNonBlock(char *err, int fd)
return
ANET_OK
;
}
static
int
_anetTcpNoDelay
(
char
*
err
,
int
fd
,
int
yes
)
static
int
anetSetTcpNoDelay
(
char
*
err
,
int
fd
,
int
val
)
{
if
(
setsockopt
(
fd
,
IPPROTO_TCP
,
TCP_NODELAY
,
&
yes
,
sizeof
(
yes
))
==
-
1
)
if
(
setsockopt
(
fd
,
IPPROTO_TCP
,
TCP_NODELAY
,
&
val
,
sizeof
(
val
))
==
-
1
)
{
anetSetError
(
err
,
"setsockopt TCP_NODELAY: %s"
,
strerror
(
errno
));
return
ANET_ERR
;
...
...
@@ -85,14 +85,14 @@ static int _anetTcpNoDelay(char *err, int fd, int yes)
return
ANET_OK
;
}
int
anetTcpNoDelay
(
char
*
err
,
int
fd
)
int
anet
Enable
TcpNoDelay
(
char
*
err
,
int
fd
)
{
return
_an
etTcpNoDelay
(
err
,
fd
,
1
);
return
anetS
etTcpNoDelay
(
err
,
fd
,
1
);
}
int
anet
TcpNoDelayOff
(
char
*
err
,
int
fd
)
int
anet
DisableTcpNoDelay
(
char
*
err
,
int
fd
)
{
return
_an
etTcpNoDelay
(
err
,
fd
,
0
);
return
anetS
etTcpNoDelay
(
err
,
fd
,
0
);
}
...
...
src/anet.h
浏览文件 @
b70b459b
...
...
@@ -51,8 +51,8 @@ int anetTcpAccept(char *err, int serversock, char *ip, int *port);
int
anetUnixAccept
(
char
*
err
,
int
serversock
);
int
anetWrite
(
int
fd
,
char
*
buf
,
int
count
);
int
anetNonBlock
(
char
*
err
,
int
fd
);
int
anetTcpNoDelay
(
char
*
err
,
int
fd
);
int
anet
TcpNoDelayOff
(
char
*
err
,
int
fd
);
int
anet
Enable
TcpNoDelay
(
char
*
err
,
int
fd
);
int
anet
DisableTcpNoDelay
(
char
*
err
,
int
fd
);
int
anetTcpKeepAlive
(
char
*
err
,
int
fd
);
int
anetPeerToString
(
int
fd
,
char
*
ip
,
int
*
port
);
...
...
src/cluster.c
浏览文件 @
b70b459b
...
...
@@ -1685,7 +1685,7 @@ int migrateGetSocket(redisClient *c, robj *host, robj *port, long timeout) {
server
.
neterr
);
return
-
1
;
}
anetTcpNoDelay
(
server
.
neterr
,
fd
);
anet
Enable
TcpNoDelay
(
server
.
neterr
,
fd
);
/* Check if it connects within the specified timeout. */
if
((
aeWait
(
fd
,
AE_WRITABLE
,
timeout
)
&
AE_WRITABLE
)
==
0
)
{
...
...
src/config.c
浏览文件 @
b70b459b
...
...
@@ -230,6 +230,10 @@ void loadServerConfigFromString(char *config) {
err
=
"repl-timeout must be 1 or greater"
;
goto
loaderr
;
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"repl-disable-tcp-nodelay"
)
&&
argc
==
2
)
{
if
((
server
.
repl_disable_tcp_nodelay
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
err
=
"argument must be 'yes' or 'no'"
;
goto
loaderr
;
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"masterauth"
)
&&
argc
==
2
)
{
server
.
masterauth
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"slave-serve-stale-data"
)
&&
argc
==
2
)
{
...
...
@@ -389,8 +393,6 @@ void loadServerConfigFromString(char *config) {
if
((
server
.
stop_writes_on_bgsave_err
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
err
=
"argument must be 'yes' or 'no'"
;
goto
loaderr
;
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"slave-tcp-nodelay-off"
)
&&
argc
==
2
)
{
server
.
slave_tcp_nodelay_off
=
atoi
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"slave-priority"
)
&&
argc
==
2
)
{
server
.
slave_priority
=
atoi
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"notify-keyspace-events"
)
&&
argc
==
2
)
{
...
...
@@ -724,10 +726,11 @@ void configSetCommand(redisClient *c) {
if
(
flags
==
-
1
)
goto
badfmt
;
server
.
notify_keyspace_events
=
flags
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"
slave-tcp-nodelay-off
"
))
{
i
f
(
getLongLongFromObject
(
o
,
&
ll
)
==
REDIS_ERR
)
goto
badfmt
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"
repl-disable-tcp-nodelay
"
))
{
i
nt
yn
=
yesnotoi
(
o
->
ptr
)
;
server
.
slave_tcp_nodelay_off
=
ll
;
if
(
yn
==
-
1
)
goto
badfmt
;
server
.
repl_disable_tcp_nodelay
=
yn
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"slave-priority"
))
{
if
(
getLongLongFromObject
(
o
,
&
ll
)
==
REDIS_ERR
||
ll
<=
0
)
goto
badfmt
;
...
...
@@ -821,7 +824,6 @@ void configGetCommand(redisClient *c) {
config_get_numerical_field
(
"repl-timeout"
,
server
.
repl_timeout
);
config_get_numerical_field
(
"maxclients"
,
server
.
maxclients
);
config_get_numerical_field
(
"watchdog-period"
,
server
.
watchdog_period
);
config_get_numerical_field
(
"slave-tcp-nodelay-off"
,
server
.
slave_tcp_nodelay_off
);
config_get_numerical_field
(
"slave-priority"
,
server
.
slave_priority
);
config_get_numerical_field
(
"hz"
,
server
.
hz
);
...
...
@@ -838,6 +840,8 @@ void configGetCommand(redisClient *c) {
config_get_bool_field
(
"rdbcompression"
,
server
.
rdb_compression
);
config_get_bool_field
(
"rdbchecksum"
,
server
.
rdb_checksum
);
config_get_bool_field
(
"activerehashing"
,
server
.
activerehashing
);
config_get_bool_field
(
"repl-disable-tcp-nodelay"
,
server
.
repl_disable_tcp_nodelay
);
/* Everything we can't handle with macros follows. */
...
...
src/networking.c
浏览文件 @
b70b459b
...
...
@@ -58,7 +58,7 @@ redisClient *createClient(int fd) {
* contexts (for instance a Lua script) we need a non connected client. */
if
(
fd
!=
-
1
)
{
anetNonBlock
(
NULL
,
fd
);
anetTcpNoDelay
(
NULL
,
fd
);
anet
Enable
TcpNoDelay
(
NULL
,
fd
);
if
(
aeCreateFileEvent
(
server
.
el
,
fd
,
AE_READABLE
,
readQueryFromClient
,
c
)
==
AE_ERR
)
{
...
...
src/redis.c
浏览文件 @
b70b459b
...
...
@@ -1200,7 +1200,7 @@ void initServerConfig() {
server
.
repl_serve_stale_data
=
1
;
server
.
repl_slave_ro
=
1
;
server
.
repl_down_since
=
time
(
NULL
);
server
.
slave_tcp_nodelay_off
=
1
;
server
.
repl_disable_tcp_nodelay
=
0
;
server
.
slave_priority
=
REDIS_DEFAULT_SLAVE_PRIORITY
;
/* Client output buffer limits */
...
...
src/redis.h
浏览文件 @
b70b459b
...
...
@@ -763,7 +763,7 @@ struct redisServer {
int
repl_serve_stale_data
;
/* Serve stale data when link is down? */
int
repl_slave_ro
;
/* Slave is read only? */
time_t
repl_down_since
;
/* Unix time at which link with master went down */
int
slave_tcp_nodelay_off
;
/* turn off slave's tcp nodelay
*/
int
repl_disable_tcp_nodelay
;
/* Disable TCP_NODELAY after SYNC?
*/
int
slave_priority
;
/* Reported in INFO and used by Sentinel. */
/* Limits */
unsigned
int
maxclients
;
/* Max number of simultaneous clients */
...
...
src/replication.c
浏览文件 @
b70b459b
...
...
@@ -118,14 +118,6 @@ void syncCommand(redisClient *c) {
/* ignore SYNC if already slave or in monitor mode */
if
(
c
->
flags
&
REDIS_SLAVE
)
return
;
if
(
server
.
slave_tcp_nodelay_off
)
{
redisLog
(
REDIS_NOTICE
,
"Turning off slave's :%d TCP NODELAY SETTING"
,
c
->
fd
);
char
err
[
1024
];
if
(
anetTcpNoDelayOff
(
err
,
c
->
fd
)
==
ANET_ERR
)
redisLog
(
REDIS_WARNING
,
"Can't turn off %d 's tcp nodelay setting: %s"
,
c
->
fd
,
err
);
}
/* Refuse SYNC requests if we are a slave but the link with our master
* is not ok... */
if
(
server
.
masterhost
&&
server
.
repl_state
!=
REDIS_REPL_CONNECTED
)
{
...
...
@@ -180,6 +172,9 @@ void syncCommand(redisClient *c) {
}
c
->
replstate
=
REDIS_REPL_WAIT_BGSAVE_END
;
}
if
(
server
.
repl_disable_tcp_nodelay
)
anetDisableTcpNoDelay
(
NULL
,
c
->
fd
);
/* Non critical if it fails. */
c
->
repldbfd
=
-
1
;
c
->
flags
|=
REDIS_SLAVE
;
c
->
slaveseldb
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录