Commit f5f8b956 authored by Shivaji's avatar Shivaji

Merge branch 'master' of https://git.cse.iitb.ac.in/samarthjoshi/key-value-store into lru-sample

parents ab71c925 e7b03d37
No preview for this file type
File added
File added
......@@ -148,7 +148,7 @@ int main(int argc, char const *argv[])
int seconds = 1;
int i;
if(1) {
if(0) {
sock = client_init();
interactive(sock);
return 0;
......@@ -167,8 +167,8 @@ int main(int argc, char const *argv[])
}
if(seconds%5==0) {
printf("%d, %f\n", i, ((float)sum/seconds));
//pthread_create( &seige_threads[i], NULL, seige, requestcompleted+i );
//i++;
pthread_create( &seige_threads[i], NULL, seige, requestcompleted+i );
i++;
}
if(i==max_concurrent) {
break;
......
......@@ -91,10 +91,10 @@ void *worker(void *args) {
if (flag & EPOLLIN) {
/* Parse the actual message from client */
struct message *requestMessage= malloc(sizeof(struct message));
int readlength=read(events[i].data.fd , requestMessage, sizeof(struct message));
struct message *requestMessage= malloc(sizeof(struct message));
memset(requestMessage->key, 0, 256);
memset(requestMessage->value, 0, 256);
int readlength=read(events[i].data.fd , requestMessage, sizeof(struct message));
if DEBUG printf("[%s][EVENT][EPOLLIN] \n", name);
switch(requestMessage->status) {
case STATUS_GET:
......@@ -104,8 +104,8 @@ void *worker(void *args) {
requestMessage->status = 200;
} else {
status = file_get(requestMessage->key, requestMessage->value);
cache_put(requestMessage->key, requestMessage->value);
if(status) {
cache_put(requestMessage->key, requestMessage->value);
requestMessage->status = 200;
} else {
requestMessage->status = 240;
......@@ -150,12 +150,12 @@ int main (int argc, int argv) {
int i;
int next_thread_to_assign = 0;
pthread_t *worker_threads;
int pool_thread_size = 1; // TODO: get pool thread size from config file
int pool_thread_size = 50; // TODO: get pool thread size from config file
int sockfd, newsockfd, portno, clilen, n;
struct sockaddr_in serv_addr, cli_addr;
//int *pipes = (int*) malloc(pool_thread_size * 2 * sizeof(pipes));
int pipes[1][2]; // TODO: initialize pipes dynamically
int pipes[50][2]; // TODO: initialize pipes dynamically
worker_threads = malloc(pool_thread_size * sizeof(pthread_t));
for( i=0; i < pool_thread_size; i++ ) {
......
No preview for this file type
......@@ -24,9 +24,11 @@ int readercount = 0;
unsigned modulus( unsigned char *num, size_t size, unsigned divisor) {
unsigned rem = 0;
while(size>0)
int i=0;
while(i<divisor)
{
rem+=num[size--]%divisor;
rem+=num[i]%divisor;
i++;
}
return rem%divisor;
}
......@@ -59,13 +61,17 @@ void file_del( char *key)
{
int offset;
int index=modulus(key,256,setSize);
char fkey[256];
char fval[256];
sem_wait(&mutex[index]);
offset = file_search(key, NULL, index);
if(offset >= 0) {
lseek(fds[index], offset, SEEK_SET);
write(fds[index], 0, 256);
write(fds[index], 0, 256);
memset(fkey, 0, 256);
memset(fval, 0, 256);
write(fds[index], fkey, 256);
write(fds[index], fval, 256);
}
sem_post(&mutex[index]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment