Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
9b24d8ad
Commit
9b24d8ad
authored
Jan 03, 2011
by
antirez
Browse files
serious performance enhancement of diskstore
parent
5d46e370
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/dscache.c
View file @
9b24d8ad
...
@@ -587,6 +587,8 @@ void dsCreateIOJob(int type, redisDb *db, robj *key, robj *val) {
...
@@ -587,6 +587,8 @@ void dsCreateIOJob(int type, redisDb *db, robj *key, robj *val) {
#define REDIS_IO_LOADINPROG 4
#define REDIS_IO_LOADINPROG 4
#define REDIS_IO_SAVEINPROG 8
#define REDIS_IO_SAVEINPROG 8
void
cacheScheduleIOPushJobs
(
int
onlyloads
);
void
cacheScheduleIOAddFlag
(
redisDb
*
db
,
robj
*
key
,
long
flag
)
{
void
cacheScheduleIOAddFlag
(
redisDb
*
db
,
robj
*
key
,
long
flag
)
{
struct
dictEntry
*
de
=
dictFind
(
db
->
io_queued
,
key
);
struct
dictEntry
*
de
=
dictFind
(
db
->
io_queued
,
key
);
...
@@ -647,6 +649,7 @@ void cacheScheduleIO(redisDb *db, robj *key, int type) {
...
@@ -647,6 +649,7 @@ void cacheScheduleIO(redisDb *db, robj *key, int type) {
* in queue for the same key. */
* in queue for the same key. */
if
(
type
==
REDIS_IO_LOAD
&&
!
(
flags
&
REDIS_IO_SAVE
))
{
if
(
type
==
REDIS_IO_LOAD
&&
!
(
flags
&
REDIS_IO_SAVE
))
{
listAddNodeHead
(
server
.
cache_io_queue
,
op
);
listAddNodeHead
(
server
.
cache_io_queue
,
op
);
cacheScheduleIOPushJobs
(
1
);
}
else
{
}
else
{
/* FIXME: probably when this happens we want to at least move
/* FIXME: probably when this happens we want to at least move
* the write job about this queue on top, and set the creation time
* the write job about this queue on top, and set the creation time
...
@@ -655,17 +658,25 @@ void cacheScheduleIO(redisDb *db, robj *key, int type) {
...
@@ -655,17 +658,25 @@ void cacheScheduleIO(redisDb *db, robj *key, int type) {
}
}
}
}
void
cacheCron
(
void
)
{
/* Push scheduled IO operations into IO Jobs that the IO thread can process.
* If 'onlyloads' is true only IO_LOAD jobs are processed: this is useful
* since it's save to push LOAD IO jobs from any place of the code, while
* SAVE io jobs should never be pushed while we are processing a command
* (not protected by lookupKey() that will block on keys in IO_SAVEINPROG
* state. */
#define MAX_IO_JOBS_QUEUE 100
void
cacheScheduleIOPushJobs
(
int
onlyloads
)
{
time_t
now
=
time
(
NULL
);
time_t
now
=
time
(
NULL
);
listNode
*
ln
;
listNode
*
ln
;
int
jobs
,
topush
=
0
;
int
jobs
,
topush
=
0
;
/* Sync stuff on disk, but only if we have less than 100 IO jobs */
/* Sync stuff on disk, but only if we have less
* than MAX_IO_JOBS_QUEUE IO jobs. */
lockThreadedIO
();
lockThreadedIO
();
jobs
=
listLength
(
server
.
io_newjobs
);
jobs
=
listLength
(
server
.
io_newjobs
);
unlockThreadedIO
();
unlockThreadedIO
();
topush
=
100
-
jobs
;
topush
=
MAX_IO_JOBS_QUEUE
-
jobs
;
if
(
topush
<
0
)
topush
=
0
;
if
(
topush
<
0
)
topush
=
0
;
if
(
topush
>
(
signed
)
listLength
(
server
.
cache_io_queue
))
if
(
topush
>
(
signed
)
listLength
(
server
.
cache_io_queue
))
topush
=
listLength
(
server
.
cache_io_queue
);
topush
=
listLength
(
server
.
cache_io_queue
);
...
@@ -677,7 +688,7 @@ void cacheCron(void) {
...
@@ -677,7 +688,7 @@ void cacheCron(void) {
topush
--
;
topush
--
;
if
(
op
->
type
==
REDIS_IO_LOAD
||
if
(
op
->
type
==
REDIS_IO_LOAD
||
(
now
-
op
->
ctime
)
>=
server
.
cache_flush_delay
)
(
!
onlyloads
&&
(
now
-
op
->
ctime
)
>=
server
.
cache_flush_delay
)
)
{
{
struct
dictEntry
*
de
;
struct
dictEntry
*
de
;
robj
*
val
;
robj
*
val
;
...
@@ -732,6 +743,11 @@ void cacheCron(void) {
...
@@ -732,6 +743,11 @@ void cacheCron(void) {
break
;
/* too early */
break
;
/* too early */
}
}
}
}
}
void
cacheCron
(
void
)
{
/* Push jobs */
cacheScheduleIOPushJobs
(
0
);
/* Reclaim memory from the object cache */
/* Reclaim memory from the object cache */
while
(
server
.
ds_enabled
&&
zmalloc_used_memory
()
>
while
(
server
.
ds_enabled
&&
zmalloc_used_memory
()
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment