提交 3d73f088 编写于 作者: A azure provisioned user 提交者: antirez

redis-benchmark AUTH command to be discarded after the first send #2150

上级 76d53a67
...@@ -90,9 +90,10 @@ typedef struct _client { ...@@ -90,9 +90,10 @@ typedef struct _client {
long long start; /* Start time of a request */ long long start; /* Start time of a request */
long long latency; /* Request latency */ long long latency; /* Request latency */
int pending; /* Number of pending requests (replies to consume) */ int pending; /* Number of pending requests (replies to consume) */
int selectlen; /* If non-zero, a SELECT of 'selectlen' bytes is currently int prefix_pending; /* If non-zero, number of pending prefix commands. Commands
used as a prefix of the pipline of commands. This gets such as auth and select are prefixed to the pipeline of
discarded the first time it's sent. */ benchmark commands and discarded after the first send. */
int prefixlen; /* Size in bytes of the pending prefix commands */
} *client; } *client;
/* Prototypes */ /* Prototypes */
...@@ -212,20 +213,21 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) { ...@@ -212,20 +213,21 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
} }
freeReplyObject(reply); freeReplyObject(reply);
// This is an OK for prefix commands such as auth and select.
if (c->selectlen) { if (c->prefix_pending > 0) {
size_t j; c->prefix_pending--;
/* This is the OK from SELECT. Just discard the SELECT
* from the buffer. */
c->pending--; c->pending--;
sdsrange(c->obuf,c->selectlen,-1); // Discard prefix commands on first response.
/* We also need to fix the pointers to the strings if (c->prefixlen > 0) {
* we need to randomize. */ size_t j;
for (j = 0; j < c->randlen; j++) sdsrange(c->obuf, c->prefixlen, -1);
c->randptr[j] -= c->selectlen; /* We also need to fix the pointers to the strings
c->selectlen = 0; * we need to randomize. */
continue; for (j = 0; j < c->randlen; j++)
c->randptr[j] -= c->prefixlen;
c->prefixlen = 0;
}
continue;
} }
if (config.requests_finished < config.requests) if (config.requests_finished < config.requests)
...@@ -299,8 +301,7 @@ static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) { ...@@ -299,8 +301,7 @@ static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
* 2) The offsets of the __rand_int__ elements inside the command line, used * 2) The offsets of the __rand_int__ elements inside the command line, used
* for arguments randomization. * for arguments randomization.
* *
* Even when cloning another client, the SELECT command is automatically prefixed * Even when cloning another client, prefix commands are applied if needed.*/
* if needed. */
static client createClient(char *cmd, size_t len, client from) { static client createClient(char *cmd, size_t len, client from) {
int j; int j;
client c = zmalloc(sizeof(struct _client)); client c = zmalloc(sizeof(struct _client));
...@@ -325,12 +326,16 @@ static client createClient(char *cmd, size_t len, client from) { ...@@ -325,12 +326,16 @@ static client createClient(char *cmd, size_t len, client from) {
* Queue N requests accordingly to the pipeline size, or simply clone * Queue N requests accordingly to the pipeline size, or simply clone
* the example client buffer. */ * the example client buffer. */
c->obuf = sdsempty(); c->obuf = sdsempty();
/* Prefix the request buffer with AUTH and/or SELECT commands, if applicable.
* These commands are discarded after the first response, so if the client is
* reused the commands will not be used again. */
c->prefix_pending = 0;
if (config.auth) { if (config.auth) {
char *buf = NULL; char *buf = NULL;
int len = redisFormatCommand(&buf, "AUTH %s", config.auth); int len = redisFormatCommand(&buf, "AUTH %s", config.auth);
c->obuf = sdscatlen(c->obuf, buf, len); c->obuf = sdscatlen(c->obuf, buf, len);
free(buf); free(buf);
c->prefix_pending++;
} }
/* If a DB number different than zero is selected, prefix our request /* If a DB number different than zero is selected, prefix our request
...@@ -340,26 +345,23 @@ static client createClient(char *cmd, size_t len, client from) { ...@@ -340,26 +345,23 @@ static client createClient(char *cmd, size_t len, client from) {
if (config.dbnum != 0) { if (config.dbnum != 0) {
c->obuf = sdscatprintf(c->obuf,"*2\r\n$6\r\nSELECT\r\n$%d\r\n%s\r\n", c->obuf = sdscatprintf(c->obuf,"*2\r\n$6\r\nSELECT\r\n$%d\r\n%s\r\n",
(int)sdslen(config.dbnumstr),config.dbnumstr); (int)sdslen(config.dbnumstr),config.dbnumstr);
c->selectlen = sdslen(c->obuf); c->prefix_pending++;
} else {
c->selectlen = 0;
} }
c->prefixlen = sdslen(c->obuf);
/* Append the request itself. */ /* Append the request itself. */
if (from) { if (from) {
c->obuf = sdscatlen(c->obuf, c->obuf = sdscatlen(c->obuf,
from->obuf+from->selectlen, from->obuf+from->prefixlen,
sdslen(from->obuf)-from->selectlen); sdslen(from->obuf)-from->prefixlen);
} else { } else {
for (j = 0; j < config.pipeline; j++) for (j = 0; j < config.pipeline; j++)
c->obuf = sdscatlen(c->obuf,cmd,len); c->obuf = sdscatlen(c->obuf,cmd,len);
} }
c->written = 0; c->written = 0;
c->pending = config.pipeline; c->pending = config.pipeline+c->prefix_pending;
c->randptr = NULL; c->randptr = NULL;
c->randlen = 0; c->randlen = 0;
if (c->selectlen) c->pending++;
/* Find substrings in the output buffer that need to be randomized. */ /* Find substrings in the output buffer that need to be randomized. */
if (config.randomkeys) { if (config.randomkeys) {
...@@ -371,7 +373,7 @@ static client createClient(char *cmd, size_t len, client from) { ...@@ -371,7 +373,7 @@ static client createClient(char *cmd, size_t len, client from) {
for (j = 0; j < (int)c->randlen; j++) { for (j = 0; j < (int)c->randlen; j++) {
c->randptr[j] = c->obuf + (from->randptr[j]-from->obuf); c->randptr[j] = c->obuf + (from->randptr[j]-from->obuf);
/* Adjust for the different select prefix length. */ /* Adjust for the different select prefix length. */
c->randptr[j] += c->selectlen - from->selectlen; c->randptr[j] += c->prefixlen - from->prefixlen;
} }
} else { } else {
char *p = c->obuf; char *p = c->obuf;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册