Commit b10b913e authored by Nilesh Jagdish's avatar Nilesh Jagdish

Throughput measure added

parent dc82dc4c
......@@ -5,6 +5,8 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
int connectToServer(char *addr, char *portNo) {
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
......@@ -33,6 +35,9 @@ void sendToServer(int sockfd) {
printf("------OPTIONS------\n1. GET\n2. PUT\n3. DELETE\n4. EXIT\n");
int choice;
char *buffer = (char *)malloc(513*sizeof(char));
int number_of_requests = 0;
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
while(1) {
printf("Enter choice: ");
scanf("%d", &choice);
......@@ -69,6 +74,20 @@ void sendToServer(int sockfd) {
printf("%s\n", recvBuffer);
if(choice==4)
{
clock_gettime(CLOCK_MONOTONIC_RAW, &end);
uint64_t delta_us = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000;
printf("Throughput : %f\n", (float)number_of_requests / (float)delta_us);
float tput;
FILE *ptr = fopen("client.txt", "r");
if(!ptr) {
ptr = fopen("client.txt", "w");
}
fscanf(ptr, "%f", &tput);
fclose(ptr);
ptr = fopen("client.txt", "w");
tput += (float)number_of_requests / (float)delta_us;
fprintf(ptr, "%f", tput);
fclose(ptr);
return NULL;
}
}
......
......@@ -140,16 +140,18 @@ int acceptConnections(char *addr, char *portNo, int nThreads) {
printf("Waiting for connection...\n");
while(1) {
pthread_mutex_lock(&lock);
int clientFd = accept(sockfd, NULL, NULL);
printf("Connected to client with fd: %d\n", clientFd);
int* clientFd = (int *)malloc(sizeof(int));
// memcpy(clientFd, accept(sockfd, NULL, NULL), sizeof(int));
*clientFd = accept(sockfd, NULL, NULL);
// printf("Connected to client with fd: %d\n", clientFd);
// pthread_mutex_lock(&lock);
clientNo++;
// pthread_mutex_unlock(&lock);
// int fid = fork();
// if(fid==0) {
// create thread
int *cfd = &clientFd;
pthread_create(&clientThreads[clientNo], NULL, respondToClient, (void *)cfd);
// int *cfd = &clientFd;
pthread_create(&clientThreads[clientNo], NULL, respondToClient, (void *)clientFd);
pthread_mutex_unlock(&lock);
// } else {
......
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