Hello, I am attaching the source code for the sample MPI code that I wrote.
On Thursday, July 14, 2016 at 2:29:06 PM UTC-5, Dormando wrote: > > Hey, > > In order to understand I'd have to see the details firsthand at this > point: Output of `stats` and `stats settings` commands, as well as any > example code you can share. > > On Thu, 14 Jul 2016, Sonia wrote: > > > Everything seems in order, but cant seem to find a reason for this odd > behaviour. > > > > On Wednesday, July 13, 2016 at 11:22:07 PM UTC-5, Dormando wrote: > > I'm not sure why. you can validate the settings via the `stats > settings` > > command. > > > > On Wed, 13 Jul 2016, Sonia wrote: > > > > > I tried inserting 10 values of size 1000000 bytes. I am able to > insert all 10 values but I guess only the last 3 are present in cache since > I am getting cache > > misses for the > > > first 7 key-value pairs.Is there a flag that we have to set in > the memcached configuration file (I currently have the '-m' option set to > 2048) > > > > > > On Wednesday, July 13, 2016 at 7:07:44 PM UTC-5, Dormando wrote: > > > Hi, > > > > > > You're trying to store exactly 1024*1024 bytes, but an > value in memcached > > > encompasses the key and the datastructure behind it. Try > (1024*1024 - > > > 4096) and see if that stores. > > > > > > On Wed, 13 Jul 2016, Sonia wrote: > > > > > > > For 100,000 1MB values I guess the memory I have > allocated is insufficient. However, I tried inserting 10 1MB values into > memcached but this too fails > > and > > > memcached_strerror() > > > > returns "ITEM TOO BIG" (The value I have is a random > alpha-numeric char array of size 1048756 bytes).I am currently using a > libmemcached client. Also > > please find > > > the output of > > > > the stats command in the attached file. > > > > I really appreciate the help. Thank you. > > > > > > > > On Wednesday, July 13, 2016 at 2:39:43 PM UTC-5, > Dormando wrote: > > > > Can you give more detail as to what exactly is > failing? what error message > > > > are you getting, what client are you using, what > is the `stats` output > > > > from some of your memcached instances, etc? > > > > > > > > 100,000 1 meg values are going to take at least > 100 gigabytes of RAM. if > > > > you have 16 2G servers, you only have 32G of RAM > available. I can't really > > > > help until knowing what your real error message is > but that math seems a > > > > little odd. > > > > > > > > On Wed, 13 Jul 2016, Sonia wrote: > > > > > > > > > I have just started working with memcached and I > am working on a test program where I want to insert 100,000 values of size > 1 MB into memcached.I > > > currently have > > > > 16 servers > > > > > setup and I have setup the memory limit in the > memcached configuration file as 2 GB but for some reason my code is still > failing. > > > > > Has anybody faced a similar situation? > > > > > > > > > > -- > > > > > > > > > > --- > > > > > You received this message because you are > subscribed to the Google Groups "memcached" group. > > > > > To unsubscribe from this group and stop > receiving emails from it, send an email to memcached+...@googlegroups.com. > > > > > > For more options, visit > https://groups.google.com/d/optout. > > > > > > > > > > > > > > > > > > -- > > > > > > > > --- > > > > You received this message because you are subscribed to > the Google Groups "memcached" group. > > > > To unsubscribe from this group and stop receiving emails > from it, send an email to memcached+...@googlegroups.com. > > > > For more options, visit > https://groups.google.com/d/optout. > > > > > > > > > > > > > > -- > > > > > > --- > > > You received this message because you are subscribed to the > Google Groups "memcached" group. > > > To unsubscribe from this group and stop receiving emails from > it, send an email to memcached+...@googlegroups.com. > > > For more options, visit https://groups.google.com/d/optout. > > > > > > > > > > -- > > > > --- > > You received this message because you are subscribed to the Google > Groups "memcached" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to memcached+...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > > > > -- --- You received this message because you are subscribed to the Google Groups "memcached" group. To unsubscribe from this group and stop receiving emails from it, send an email to memcached+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
#include <libmemcached/memcached.h> #include <stdio.h> #include <string.h> #include <limits.h> #include <unistd.h> #include "mpi.h" #include <errno.h> #define MPI_CODE 0 #define MASTER 0 #define MAX_PATH 260 #define MAX_VALUE_SIZE 1048576 void gen_random(char *s, const int len) { int i; static const char alphanum[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; for (i = 0; i < len; ++i) { s[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; } s[len] = 0; } void displayHelp() { printf("\n*******************************************************"); printf("\nBasic program for using memcached in MPI environment"); printf("\nUsage: mpirun -n <no of nodes> <path to servers file> <no. of key-value pairs> <size of value> <no. of retreiving clients>"); printf("\nTo access help, use '/?' or '-h' or run the utility without parameters"); printf("\n*******************************************************\n"); } int main(int argc, char **argv) { int i; int keyMin; int keyMax; int errCode; int valueSize; int nSubsetSize; int nKeyValPairs; int nRetrieveClients; double end; double start; double time1; double time2; double timeToSet; double timeToRetreive; char key[MAX_PATH]; memcached_st *memc; memcached_return rc; char value[MAX_VALUE_SIZE]; char *retrieved_value; memcached_server_st *servers = NULL; FILE *fp; char *line; size_t length; ssize_t readLen; size_t value_length; uint32_t flags; MPI_Status stats[2]; MPI_Request reqs[2]; int numtasks, taskid, len; // // Initialize MPI // MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD,&taskid); MPI_Comm_size(MPI_COMM_WORLD, &numtasks); //printf("Hello from %d", taskid); // // Get command line arguments // if (argc == 1) { if (taskid == MASTER) { displayHelp(); } MPI_Abort(MPI_COMM_WORLD, errCode); return(1); } else if (argc == 2) { if (strcmp(argv[1], "/?") == 0 || strcmp(argv[1], "-h") == 0) { if (taskid == MASTER) { displayHelp(); } } MPI_Abort(MPI_COMM_WORLD, errCode); return(1); } else if (argc != 5) { if (taskid == MASTER) { printf("Invalid arguments.\n"); displayHelp(); } MPI_Abort(MPI_COMM_WORLD, errCode); return (1); } if (access(argv[1], F_OK) == -1) { printf("\nFile (%s) does not exist"); MPI_Abort(MPI_COMM_WORLD, errCode); return(1); } nKeyValPairs = atoi(argv[2]); nSubsetSize = nKeyValPairs / numtasks; keyMin = taskid * nSubsetSize; keyMax = ((taskid + 1) * nSubsetSize) - 1; if (taskid == (numtasks - 1)) { if (keyMax != (nKeyValPairs - 1)) { keyMax = nKeyValPairs - 1; } } valueSize = atoi(argv[3]); nRetrieveClients = atoi(argv[4]); if (nRetrieveClients > numtasks) { printf("\nInvalid number of retriving clients\n"); MPI_Abort(MPI_COMM_WORLD, errCode); return(1); } // // Add a server // errno = 0; fp = fopen(argv[1], "r"); if (NULL == fp) { fprintf(stderr, "Couldn't open file (%s).", argv[1]); memcached_free(memc); MPI_Abort(MPI_COMM_WORLD, errCode); return(1); } line = NULL; length = 0; memc = memcached_create(NULL); while((readLen = getline(&line, &length, fp)) != -1) { line[readLen - 1] = '\0'; servers = memcached_server_list_append(servers, line, 11211, &rc); rc = memcached_server_push(memc, servers); if (rc == MEMCACHED_SUCCESS) { //fprintf(stderr, "Added server (%s) successfuly\n", line); } else { fprintf(stderr, "Couldn't add server (%s): %s\n", line, memcached_strerror(memc, rc)); memcached_free(memc); MPI_Abort(MPI_COMM_WORLD, errCode); free(line); fclose(fp); return(1); } } free(line); fclose(fp); //MPI_Barrier(MPI_COMM_WORLD); start = MPI_Wtime(); // // Generate unique key-value pairs // Write them to memcached // printf("Process %d: Min(%d) Max(%d)\n", keyMin, keyMax); while(keyMin <= keyMax) { sprintf(key, "bob:%d", keyMin); gen_random(value, valueSize); rc = memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); if (rc == MEMCACHED_SUCCESS) { fprintf(stderr, "%d) Key (%s) stored successfully\n", taskid, key); } else { fprintf(stderr, "Couldn't store key(%s): %s\n", key, memcached_strerror(memc, rc)); memcached_free(memc); MPI_Abort(MPI_COMM_WORLD, errCode); return(1); } keyMin++; } end = MPI_Wtime(); time1 = end - start; MPI_Barrier(MPI_COMM_WORLD); start = MPI_Wtime(); // // Retrieve the keys // nSubsetSize = nKeyValPairs / nRetrieveClients; if (taskid < nRetrieveClients) { keyMin = taskid * nSubsetSize; keyMax = ((taskid + 1) * nSubsetSize) - 1; if (taskid == (nRetrieveClients - 1)) { if (keyMax != (nKeyValPairs - 1)) { keyMax = nKeyValPairs - 1; } } while (keyMin <= keyMax) { sprintf(key, "%d", keyMin); printf("Process %d retrieving key %s\n", taskid, key); retrieved_value = memcached_get(memc, key, strlen(key), &value_length, &flags, &rc); if (rc == MEMCACHED_SUCCESS) { //printf("The key '%s' returned value '%s'.\n", key, retrieved_value); free(retrieved_value); } else { fprintf(stderr, "Couldn't retrieve key %s: %s\n", key, memcached_strerror(memc, rc)); } keyMin++; } } end = MPI_Wtime(); time2 = end - start; MPI_Reduce(&time2, &timeToRetreive, 1, MPI_DOUBLE, MPI_MAX, MASTER, MPI_COMM_WORLD); MPI_Reduce(&time1, &timeToSet, 1, MPI_DOUBLE, MPI_MAX, MASTER, MPI_COMM_WORLD); memcached_free(memc); //MPI_Barrier(MPI_COMM_WORLD); if (taskid == MASTER) { fp = fopen("time.txt", "w"); if (NULL == fp) { printf("\nCould not open file for writing\n"); MPI_Abort(MPI_COMM_WORLD, errCode); return (1); } fprintf(fp, "\n======================================================================================"); fprintf(fp, "\nExecution time to set key-value pairs %f", timeToSet); fprintf(fp, "\nExecution time to retreive key-value pairs %f", timeToRetreive); fprintf(fp, "\n======================================================================================\n"); fclose(fp); printf("\n"); } //MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); //printf("\n"); return 0; }