Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
c28b42ac
Commit
c28b42ac
authored
Nov 18, 2009
by
antirez
Browse files
more experiments with long replies, glue output buffer, and writev.
parent
cc30e368
Changes
3
Hide whitespace changes
Inline
Side-by-side
benchmark.c
View file @
c28b42ac
...
@@ -486,6 +486,7 @@ int main(int argc, char **argv) {
...
@@ -486,6 +486,7 @@ int main(int argc, char **argv) {
}
}
do
{
do
{
#if 0
prepareForBenchmark();
prepareForBenchmark();
c = createClient();
c = createClient();
if (!c) exit(1);
if (!c) exit(1);
...
@@ -547,6 +548,7 @@ int main(int argc, char **argv) {
...
@@ -547,6 +548,7 @@ int main(int argc, char **argv) {
aeMain(config.el);
aeMain(config.el);
endBenchmark("PING");
endBenchmark("PING");
#endif
prepareForBenchmark
();
prepareForBenchmark
();
c
=
createClient
();
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
if
(
!
c
)
exit
(
1
);
...
@@ -556,6 +558,7 @@ int main(int argc, char **argv) {
...
@@ -556,6 +558,7 @@ int main(int argc, char **argv) {
aeMain
(
config
.
el
);
aeMain
(
config
.
el
);
endBenchmark
(
"LPUSH (again, in order to bench LRANGE)"
);
endBenchmark
(
"LPUSH (again, in order to bench LRANGE)"
);
#if 0
prepareForBenchmark();
prepareForBenchmark();
c = createClient();
c = createClient();
if (!c) exit(1);
if (!c) exit(1);
...
@@ -582,6 +585,7 @@ int main(int argc, char **argv) {
...
@@ -582,6 +585,7 @@ int main(int argc, char **argv) {
createMissingClients(c);
createMissingClients(c);
aeMain(config.el);
aeMain(config.el);
endBenchmark("LRANGE (first 450 elements)");
endBenchmark("LRANGE (first 450 elements)");
#endif
prepareForBenchmark
();
prepareForBenchmark
();
c
=
createClient
();
c
=
createClient
();
...
...
redis.c
View file @
c28b42ac
...
@@ -1351,33 +1351,29 @@ static void freeClient(redisClient *c) {
...
@@ -1351,33 +1351,29 @@ static void freeClient(redisClient *c) {
#define GLUEREPLY_UP_TO (1024)
#define GLUEREPLY_UP_TO (1024)
static void glueReplyBuffersIfNeeded(redisClient *c) {
static void glueReplyBuffersIfNeeded(redisClient *c) {
int
totlen
=
0
;
int copylen = 0;
char buf[GLUEREPLY_UP_TO];
listNode *ln;
listNode *ln;
robj *o;
robj *o;
listRewind(c->reply);
listRewind(c->reply);
while((ln = listYield(c->reply))) {
while((ln = listYield(c->reply))) {
int objlen;
o = ln->value;
o = ln->value;
totlen
+=
sdslen
(
o
->
ptr
);
objlen = sdslen(o->ptr);
/* This optimization makes more sense if we don't have to copy
if (copylen + objlen <= GLUEREPLY_UP_TO) {
* too much data */
memcpy(buf+copylen,o->ptr,objlen);
if
(
totlen
>
GLUEREPLY_UP_TO
)
return
;
copylen += objlen;
}
if
(
totlen
>
0
)
{
char
buf
[
GLUEREPLY_UP_TO
];
int
copylen
=
0
;
listRewind
(
c
->
reply
);
while
((
ln
=
listYield
(
c
->
reply
)))
{
o
=
ln
->
value
;
memcpy
(
buf
+
copylen
,
o
->
ptr
,
sdslen
(
o
->
ptr
));
copylen
+=
sdslen
(
o
->
ptr
);
listDelNode(c->reply,ln);
listDelNode(c->reply,ln);
} else {
if (copylen == 0) return;
break;
}
}
/* Now the output buffer is empty, add the new single element */
o
=
createObject
(
REDIS_STRING
,
sdsnewlen
(
buf
,
totlen
));
listAddNodeTail
(
c
->
reply
,
o
);
}
}
/* Now the output buffer is empty, add the new single element */
o = createObject(REDIS_STRING,sdsnewlen(buf,copylen));
listAddNodeHead(c->reply,o);
}
}
static void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
static void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -1387,8 +1383,6 @@ static void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask)
...
@@ -1387,8 +1383,6 @@ static void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask)
REDIS_NOTUSED(el);
REDIS_NOTUSED(el);
REDIS_NOTUSED(mask);
REDIS_NOTUSED(mask);
if
(
server
.
glueoutputbuf
&&
listLength
(
c
->
reply
)
>
1
)
glueReplyBuffersIfNeeded
(
c
);
/* Use writev() if we have enough buffers to send */
/* Use writev() if we have enough buffers to send */
#if 0
#if 0
...
@@ -1401,6 +1395,9 @@ static void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask)
...
@@ -1401,6 +1395,9 @@ static void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask)
#endif
#endif
while(listLength(c->reply)) {
while(listLength(c->reply)) {
if (server.glueoutputbuf && listLength(c->reply) > 1)
glueReplyBuffersIfNeeded(c);
o = listNodeValue(listFirst(c->reply));
o = listNodeValue(listFirst(c->reply));
objlen = sdslen(o->ptr);
objlen = sdslen(o->ptr);
...
...
test-redis.tcl
View file @
c28b42ac
...
@@ -912,6 +912,10 @@ proc main {server port} {
...
@@ -912,6 +912,10 @@ proc main {server port} {
lappend aux
[
$r
dbsize
]
lappend aux
[
$r
dbsize
]
}
{
0 0
}
}
{
0 0
}
test
{
Perform a final SAVE to leave a clean DB on disk
}
{
$r save
}
{
OK
}
puts
"
\n
[
expr $::passed+$::failed
]
tests,
$::passed
passed,
$::failed
failed"
puts
"
\n
[
expr $::passed+$::failed
]
tests,
$::passed
passed,
$::failed
failed"
if
{
$::failed
> 0
}
{
if
{
$::failed
> 0
}
{
puts
"
\n
*** WARNING!!!
$::failed
FAILED TESTS ***
\n
"
puts
"
\n
*** WARNING!!!
$::failed
FAILED TESTS ***
\n
"
...
...
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