Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
35a62f74
R
redis
项目概览
hanoi2005
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
35a62f74
编写于
7月 01, 2014
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Latency monitor: more hooks around the code.
上级
855c97ce
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
5 deletion
+40
-5
src/aof.c
src/aof.c
+20
-0
src/rdb.c
src/rdb.c
+6
-0
src/redis.c
src/redis.c
+14
-5
未找到文件。
src/aof.c
浏览文件 @
35a62f74
...
...
@@ -230,6 +230,7 @@ int startAppendOnly(void) {
void
flushAppendOnlyFile
(
int
force
)
{
ssize_t
nwritten
;
int
sync_in_progress
=
0
;
mstime_t
latency
;
if
(
sdslen
(
server
.
aof_buf
)
==
0
)
return
;
...
...
@@ -266,7 +267,11 @@ void flushAppendOnlyFile(int force) {
* While this will save us against the server being killed I don't think
* there is much to do about the whole server stopping for power problems
* or alike */
latencyStartMonitor
(
latency
);
nwritten
=
write
(
server
.
aof_fd
,
server
.
aof_buf
,
sdslen
(
server
.
aof_buf
));
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"aof-write"
,
latency
);
if
(
nwritten
!=
(
signed
)
sdslen
(
server
.
aof_buf
))
{
static
time_t
last_write_error_log
=
0
;
int
can_log
=
0
;
...
...
@@ -360,7 +365,10 @@ void flushAppendOnlyFile(int force) {
if
(
server
.
aof_fsync
==
AOF_FSYNC_ALWAYS
)
{
/* aof_fsync is defined as fdatasync() for Linux in order to avoid
* flushing metadata. */
latencyStartMonitor
(
latency
);
aof_fsync
(
server
.
aof_fd
);
/* Let's try to get this data on the disk */
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"aof-fsync-always"
,
latency
);
server
.
aof_last_fsync
=
server
.
unixtime
;
}
else
if
((
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
&&
server
.
unixtime
>
server
.
aof_last_fsync
))
{
...
...
@@ -1031,6 +1039,7 @@ int rewriteAppendOnlyFileBackground(void) {
}
else
{
/* Parent */
server
.
stat_fork_time
=
ustime
()
-
start
;
latencyAddSampleIfNeeded
(
"fork"
,
server
.
stat_fork_time
/
1000
);
if
(
childpid
==
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Can't rewrite append only file in background: fork: %s"
,
...
...
@@ -1080,13 +1089,17 @@ void aofRemoveTempFile(pid_t childpid) {
* to the current length, that is much faster. */
void
aofUpdateCurrentSize
(
void
)
{
struct
redis_stat
sb
;
mstime_t
latency
;
latencyStartMonitor
(
latency
);
if
(
redis_fstat
(
server
.
aof_fd
,
&
sb
)
==
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Unable to obtain the AOF file length. stat: %s"
,
strerror
(
errno
));
}
else
{
server
.
aof_current_size
=
sb
.
st_size
;
}
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"aof-fstat"
,
latency
);
}
/* A background append only file rewriting (BGREWRITEAOF) terminated its work.
...
...
@@ -1096,12 +1109,14 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
int
newfd
,
oldfd
;
char
tmpfile
[
256
];
long
long
now
=
ustime
();
mstime_t
latency
;
redisLog
(
REDIS_NOTICE
,
"Background AOF rewrite terminated with success"
);
/* Flush the differences accumulated by the parent to the
* rewritten AOF. */
latencyStartMonitor
(
latency
);
snprintf
(
tmpfile
,
256
,
"temp-rewriteaof-bg-%d.aof"
,
(
int
)
server
.
aof_child_pid
);
newfd
=
open
(
tmpfile
,
O_WRONLY
|
O_APPEND
);
...
...
@@ -1117,6 +1132,8 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
close
(
newfd
);
goto
cleanup
;
}
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"aof-rewrite-diff-write"
,
latency
);
redisLog
(
REDIS_NOTICE
,
"Parent diff successfully flushed to the rewritten AOF (%lu bytes)"
,
aofRewriteBufferSize
());
...
...
@@ -1162,6 +1179,7 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
/* Rename the temporary file. This will not unlink the target file if
* it exists, because we reference it with "oldfd". */
latencyStartMonitor
(
latency
);
if
(
rename
(
tmpfile
,
server
.
aof_filename
)
==
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Error trying to rename the temporary AOF file: %s"
,
strerror
(
errno
));
...
...
@@ -1169,6 +1187,8 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
if
(
oldfd
!=
-
1
)
close
(
oldfd
);
goto
cleanup
;
}
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"aof-rename"
,
latency
);
if
(
server
.
aof_fd
==
-
1
)
{
/* AOF disabled, we don't need to set the AOF file descriptor
...
...
src/rdb.c
浏览文件 @
35a62f74
...
...
@@ -745,6 +745,7 @@ int rdbSaveBackground(char *filename) {
}
else
{
/* Parent */
server
.
stat_fork_time
=
ustime
()
-
start
;
latencyAddSampleIfNeeded
(
"fork"
,
server
.
stat_fork_time
/
1000
);
if
(
childpid
==
-
1
)
{
server
.
lastbgsave_status
=
REDIS_ERR
;
redisLog
(
REDIS_WARNING
,
"Can't save in background: fork: %s"
,
...
...
@@ -1201,9 +1202,14 @@ void backgroundSaveDoneHandler(int exitcode, int bysignal) {
redisLog
(
REDIS_WARNING
,
"Background saving error"
);
server
.
lastbgsave_status
=
REDIS_ERR
;
}
else
{
mstime_t
latency
;
redisLog
(
REDIS_WARNING
,
"Background saving terminated by signal %d"
,
bysignal
);
latencyStartMonitor
(
latency
);
rdbRemoveTempFile
(
server
.
rdb_child_pid
);
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"rdb-unlink-temp-file"
,
latency
);
/* SIGUSR1 is whitelisted, so we have a way to kill a child without
* tirggering an error conditon. */
if
(
bysignal
!=
SIGUSR1
)
...
...
src/redis.c
浏览文件 @
35a62f74
...
...
@@ -805,10 +805,11 @@ void activeExpireCycle(int type) {
* expire. So after a given amount of milliseconds return to the
* caller waiting for the other active expire cycle. */
iteration
++
;
if
((
iteration
&
0xf
)
==
0
&&
/* check once every 16 iterations. */
(
ustime
()
-
start
)
>
timelimit
)
{
timelimit_exit
=
1
;
if
((
iteration
&
0xf
)
==
0
)
{
/* check once every 16 iterations. */
long
long
elapsed
=
ustime
()
-
start
;
latencyAddSampleIfNeeded
(
"expire-cycle"
,
elapsed
/
1000
);
if
(
elapsed
>
timelimit
)
timelimit_exit
=
1
;
}
if
(
timelimit_exit
)
return
;
/* We don't repeat the cycle if there are less than 25% of keys
...
...
@@ -2836,6 +2837,7 @@ void monitorCommand(redisClient *c) {
int
freeMemoryIfNeeded
(
void
)
{
size_t
mem_used
,
mem_tofree
,
mem_freed
;
int
slaves
=
listLength
(
server
.
slaves
);
mstime_t
latency
;
/* Remove the size of slaves output buffers and AOF buffer from the
* count of used memory. */
...
...
@@ -2868,6 +2870,7 @@ int freeMemoryIfNeeded(void) {
/* Compute how much memory we need to free. */
mem_tofree
=
mem_used
-
server
.
maxmemory
;
mem_freed
=
0
;
latencyStartMonitor
(
latency
);
while
(
mem_freed
<
mem_tofree
)
{
int
j
,
k
,
keys_freed
=
0
;
...
...
@@ -2971,8 +2974,14 @@ int freeMemoryIfNeeded(void) {
if
(
slaves
)
flushSlavesOutputBuffers
();
}
}
if
(
!
keys_freed
)
return
REDIS_ERR
;
/* nothing to free... */
if
(
!
keys_freed
)
{
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"eviction-cycle"
,
latency
);
return
REDIS_ERR
;
/* nothing to free... */
}
}
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"eviction-cycle"
,
latency
);
return
REDIS_OK
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录