ArrayDB uses less memory and is almost as fast as memcached

We have performed benchmark test of ArrayDB and memcached. The memcached server is started with the following settings:

memcached -d -p 11211 -u memcached -m 512 -c 1024 -P /var/run/memcached/memcached.pid

The following C listing is the client program to insert and lookup 3000000 random strings in memcached:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <libmemcached/memcached.h>

char *randomString( int size );
int main(int argc, char *argv[])
{
int i;
int max = 100;
if ( argc > 1 ) {
max = atoi( argv[1] );
}

memcached_server_st *servers = NULL;
memcached_st *memc;
memcached_return rc;
char *key;
char *value;
size_t vlen;
uint32_t flags;
memcached_return_t err;

memcached_server_st *memcached_servers_parse (server_strings);
memc= memcached_create(NULL);
servers= memcached_server_list_append(servers, “localhost”, 11211, &rc);
rc= memcached_server_push(memc, servers);

if (rc == MEMCACHED_SUCCESS) {
printf(“Added server successfully\n”);
} else {
printf(“Couldn’t add server: %s\n”,memcached_strerror(memc, rc));
}
time_t t1 = time(NULL);
srand(10);
for ( i = 0; i < max; ++i ) {
key = randomString( 16 );
value = randomString( 16 );
rc= memcached_set(memc, key, 16, value, 16, (time_t)0, (uint32_t)0);
if (rc != MEMCACHED_SUCCESS) {
fprintf(stderr,”Couldn’t store key: %s\n”,memcached_strerror(memc, rc));
}
}
time_t t2 = time(NULL);
printf(“Insert %d strings took %d seconds\n”, max, t2-t1 );

t1 = time(NULL);
char *res;
srand(10);
for ( i = 0; i < max; ++i ) {
key = randomString( 16 );
value = randomString( 16 );
res = memcached_get( memc, key, 16, &vlen, &flags, &err );
if ( res ) {
free( res );
} else {
printf(“error in memcached_get NULL\n”);
}
}
t2 = time(NULL);
printf(“Lookup %d strings took %d seconds\n”, max, t2-t1 );
return 0;

}

char *randomString( int size )
{
int i, j;
static char cset[] = “0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”; // 62 total
char *mem = (char*)malloc(size+1);
for ( i = 0; i< size; i++) {
j = rand() % 62;
mem[i] = cset[j];
}
mem[i] = ”;
return mem;
}

 

To insert and query data in ArrayDB, the following commands are executed:

$ rbench -r “3000000:0:0”  -k 0   (create table and insert data)

$ rbench -r “0:0:3000000”        (read data)

 

———————————————————————————–

Insert Time     |    Lookup Time   |    Memory

———————————————————————————–

Memcached    |     359 sec            |       317 sec           |    370 MB

————————————————————————————

ArrayDB          |    486 sec             |       440 sec           |   46 MB

————————————————————————————

 

The benchmark shows that ArrayDB uses much less memory but achieves similar speed to memcached. ArrayDB could be very valuable in cloud computing environment where memory resource is expensive.

Advertisements