SPO600 Project 1 Stage 2
Redis notable
points:
·
In-memory-based
key-value store
·
Faster
than memory-based database (performance wise)
·
it
processes the data into memory
·
repository
provides primitive types
·
data
types like String, Set, Hash, List, Basic Functions (Search Add Delete of data)
·
Hiredis
- APIs that manipulates Redis as C client
Benchmark
source code
const int N = 1000000;
int main() {
printf("Connecting...\n");
redisContext *redis = redisConnect("localhost", 6379);
clock_t
start, end;
float
ftime;
if (redis->err)
{
puts(redis->errstr);
char
*p = redis->errstr;
while
(*p) {
printf("%x ", (int)(*p++));
}
printf("\n");
}
else {
start
= clock();
char
*cmd;
int
len;
for
(int i = 0; i < N; i++) {
len = redisFormatCommand(&cmd, "HSET myset:__rand_int__
element:__rand_int__");
redisAppendFormattedCommand(redis, cmd, len);
}
for
(int i = 0; i < N; i++) {
redisReply *reply;
assert(redisGetReply(redis, (void*)&reply) == REDIS_OK);
redisGetReply(redis, (void**)&reply);
freeReplyObject(reply);
}
end =
clock();
ftime
= (float)(end - start) / CLOCKS_PER_SEC;
printf("Runing Time: %f sec. \n", ftime);
}
}
Modified
source code for Hiredis
while(*c != '\0') {
if (*c != '%' || c[1] == '\0') {
if (*c == ' ') {
if (touched) {
//Change Source for optimization
int result;
__asm__ __volatile__("add %0,%1,%2 \n\t":"=r" (result) : "r"(argc), "r"(1));
newargv = realloc(curargv, sizeof(char*)*(result));
//newargv = realloc(curargv,sizeof(char*)*(argc+1)); - Original Source
if (newargv == NULL) goto memory_err;
curargv = newargv;
curargv[argc++] = curarg;
totlen += bulklen(sdslen(curarg));
/* curarg is put in argv so it can be overwritten. */
curarg = sdsempty();
if (curarg == NULL) goto memory_err;
touched = 0;
This is the
results prior to the optimization
This is
optimization results (especially with –o3)
This source
code is modified to run on x86 platform
while(*c != '\0') {
if (*c != '%' || c[1] == '\0') {
if (*c == ' ') {
if (touched) {
//Change Source for optimization
int result;
__asm__("addl %%ebx, %%eax;" : "=a" (result) : "a" (argc), "b" (1));
newargv = realloc(curargv,sizeof(char*)*(argc+1));
//newargv = realloc(curargv,sizeof(char*)*(argc+1)); - Original Source
if (newargv == NULL) goto memory_err;
curargv = newargv;
curargv[argc++] = curarg;
totlen += bulklen(sdslen(curarg));
/* curarg is put in argv so it can be overwritten. */
curarg = sdsempty();
if (curarg == NULL) goto memory_err;
touched = 0;
There were
errors when running the Hiredis library on x86 platform and here’s the picture
of prove
Comments
Post a Comment