Skip to content

Commit

Permalink
Create request for redis-ycsbe
Browse files Browse the repository at this point in the history
  • Loading branch information
marioskogias committed Mar 26, 2020
1 parent cd42543 commit 0131122
Showing 1 changed file with 120 additions and 17 deletions.
137 changes: 120 additions & 17 deletions agents/redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,35 @@
#include <lancet/key_gen.h>
#include <lancet/rand_gen.h>

#define YCSBE_SCAN_RATIO 0.95
#define YCSBE_INSERT_RATIO 0.05
#define YCSBE_KEY_COUNT 1000000
#define YCSBE_MAX_SCAN_LEN 100
#define YCSBE_FIELD_COUNT 2
#define YCSBE_FIELD_SIZE 100

struct ycsbe_info {
double scan_ratio;
double insert_ratio;
int key_count;
int scan_len;
int field_count;
int field_size;
char *fixed_req_body;
};

static char set_prem[] = "*3\r\n$3\r\nSET\r\n$";
static char get_prem[] = "*2\r\n$3\r\nGET\r\n$";
static char ln[] = "\r\n";
static char dollar[] = "$";
static char ycsbe_insert_prem[] = "ycsbe.insert ";
static char ycsbe_scan_prem[] = "ycsbe.scan ";
static __thread char ycsbe_key[64];
static __thread char ycsbe_scan[64];
static __thread char key_len_str[64];
static __thread char val_len_str[64];

int static parse_string(char *buf, int bytes_left)
static int parse_string(char *buf, int bytes_left)
{
int processed = 0;
char *p;
Expand All @@ -58,7 +79,7 @@ int static parse_string(char *buf, int bytes_left)
return processed;
}

int static parse_bulk_string(char *buf, int bytes_left)
static int parse_bulk_string(char *buf, int bytes_left)
{
int len, processed = 0, extra;
char *p;
Expand All @@ -84,7 +105,7 @@ int static parse_bulk_string(char *buf, int bytes_left)
return processed;
}

struct byte_req_pair redis_consume_response(struct application_protocol *proto,
static struct byte_req_pair redis_kv_consume_response(struct application_protocol *proto,
struct iovec *resp)
{
struct byte_req_pair res;
Expand Down Expand Up @@ -120,7 +141,7 @@ struct byte_req_pair redis_consume_response(struct application_protocol *proto,
return res;
}

int redis_create_request(struct application_protocol *proto,
static int redis_kv_create_request(struct application_protocol *proto,
struct request *req)
{
struct kv_info *info;
Expand Down Expand Up @@ -177,15 +198,7 @@ int redis_create_request(struct application_protocol *proto,
return 0;
}

int redis_get_key_count(struct application_protocol *proto)
{
struct kv_info *info;

info = (struct kv_info *)proto->arg;
return info->key->key_count;
}

int redis_init(char *proto, struct application_protocol *app_proto)
static int init_redis_kv(char *proto, struct application_protocol *app_proto)
{
struct kv_info *data;
char *token, *key_dist;
Expand All @@ -196,8 +209,6 @@ int redis_init(char *proto, struct application_protocol *app_proto)
data = malloc(sizeof(struct kv_info));
assert(data != NULL);

assert(strncmp("redis", proto, 5) == 0);

/* key size dist */
strtok_r(proto, "_", &saveptr);

Expand Down Expand Up @@ -231,8 +242,100 @@ int redis_init(char *proto, struct application_protocol *app_proto)

app_proto->type = PROTO_REDIS;
app_proto->arg = data;
app_proto->consume_response = redis_consume_response;
app_proto->create_request = redis_create_request;
app_proto->consume_response = redis_kv_consume_response;
app_proto->create_request = redis_kv_create_request;

return 0;
}

static int redis_ycsbe_create_request(struct application_protocol *proto,
struct request *req)
{
int key, scan_count;
struct ycsbe_info *info;

info = (struct ycsbe_info *)proto->arg;

key = rand() % info->key_count;
sprintf(ycsbe_key, " %d ", key);

if (drand48()<=info->scan_ratio) {
// perform a scan
scan_count = rand() % info->scan_len + 1;
sprintf(ycsbe_scan, " %d\n", scan_count);

req->iovs[0].iov_base = ycsbe_scan_prem;
req->iovs[0].iov_len = 11;
req->iovs[1].iov_base = ycsbe_key;
req->iovs[1].iov_len = strlen(ycsbe_key);
req->iovs[2].iov_base = ycsbe_scan;
req->iovs[2].iov_len = strlen(ycsbe_scan);
req->iov_cnt = 3;
} else {
// perform an insert
req->iovs[0].iov_base = ycsbe_insert_prem;
req->iovs[0].iov_len = 13;
req->iovs[1].iov_base = ycsbe_key;
req->iovs[1].iov_len = strlen(ycsbe_key);
req->iovs[2].iov_base = info->fixed_req_body;
req->iovs[2].iov_len = info->field_count*(info->field_size+1);
req->iov_cnt = 3;
}

return 0;
}

static struct byte_req_pair redis_ycsbe_consume_response(struct application_protocol *proto,
struct iovec *resp)
{
struct byte_req_pair res;

return res;
}

static int init_redis_ycsbe(char *proto, struct application_protocol *app_proto)
{
struct ycsbe_info *yinfo;
int i;
char *body;

yinfo = malloc(sizeof(struct ycsbe_info));
assert(yinfo);

yinfo->scan_ratio = YCSBE_SCAN_RATIO;
yinfo->insert_ratio = YCSBE_INSERT_RATIO;
yinfo->key_count = YCSBE_KEY_COUNT;
yinfo->scan_len = YCSBE_MAX_SCAN_LEN;
yinfo->field_count = YCSBE_FIELD_COUNT;
yinfo->field_size = YCSBE_FIELD_SIZE;
yinfo->fixed_req_body = malloc(yinfo->field_count*(yinfo->field_size+1));
assert(yinfo->fixed_req_body);

body = yinfo->fixed_req_body;
for (i=0;i<yinfo->field_count;i++) {
memset(body, 'x', yinfo->field_size);
body += yinfo->field_count;
*body++ = ' ';
}
*(body-1) = '\n';


app_proto->type = PROTO_REDIS_YCSBE;
app_proto->arg = yinfo;
app_proto->consume_response = redis_ycsbe_consume_response;
app_proto->create_request = redis_ycsbe_create_request;

return 0;
}

int redis_init(char *proto, struct application_protocol *app_proto)
{
assert(strncmp("redis", proto, 5) == 0);

if (strncmp("redis-ycsbe", proto, 11) == 0)
init_redis_ycsbe(proto, app_proto);
else
init_redis_kv(proto, app_proto);

return 0;
}

0 comments on commit 0131122

Please sign in to comment.