int initconfig(ZHTClient &clientRet, string cfgFile, string memberList) { if (clientRet.initialize(cfgFile, memberList, TCP) != 0) { cout << "Crap! ZHTClient initialization failed, program exits." << endl; return -1; } return 0; }
int benchmarkInsert(string cfgFile, string memberList, vector<string> &pkgList, ZHTClient &clientRet, int numTest, int lenString) { // if (clientRet.initialize(cfgFile, memberList) != 0) { //zhouxb if (clientRet.initialize(cfgFile, memberList, TCP) != 0) { cout << "Crap! ZHTClient initialization failed, program exits." << endl; return -1; } for (int i = 0; i < numTest; i++) { Package package, package_ret; package.set_virtualpath(randomString(lenString)); //as key package.set_isdir(true); package.set_replicano(5); //orginal--Note: never let it be nagative!!! package.set_operation(3); // 3 for insert, 1 for look up, 2 for remove package.set_realfullpath( "Some-Real-longer-longer-and-longer-Paths--------"); package.add_listitem("item-----2"); package.add_listitem("item-----3"); package.add_listitem("item-----4"); package.add_listitem("item-----5"); package.add_listitem("item-----6"); string str = package.SerializeAsString(); // cout << "package size = " << str.size() << endl; // cout<<"Client.cpp:benchmarkInsert: "<<endl; // cout<<"string: "<<str<<endl; // cout<<"Insert str: "<<str.c_str()<<endl; // cout<<"data(): "<< str.data()<<endl; pkgList.push_back(str); } double start = 0; double end = 0; start = getTime_msec(); int errCount = 0; vector<string>::iterator it; int c = 0; // cout << "-----2" << endl; for (it = pkgList.begin(); it != pkgList.end(); it++) { // cerr <<"insert count "<< c << endl; c++; string str_ins = *it; //cout << "-----1" << endl; int ret = clientRet.insert(str_ins); //cout << "-----2" << endl; if (ret < 0) { errCount++; } } //close(sock); end = getTime_msec(); cout << "Inserted " << numTest - errCount << " packages out of " << numTest << ", cost " << end - start << " ms" << endl; return 0; }
int c_zht_init(const char *memberConfig, const char *zhtConfig, bool tcp) { string zhtStr(zhtConfig); string memberStr(memberConfig); if (zhtClient.initialize(zhtStr, memberStr, tcp) != 0) { printf("Crap! ZHTClient initialization failed, program exits."); return -1; } return 0; }
int c_zht_init_std(ZHTClient_c * zhtClient, const char *memberConfig, const char *zhtConfig, bool tcp) { ZHTClient * zhtcppClient = new ZHTClient(); string zhtStr(zhtConfig); string memberStr(memberConfig); if (zhtcppClient->initialize(zhtStr, memberStr, tcp) != 0) { printf("Crap! ZHTClient initialization failed, program exits."); return -1; } *zhtClient = (ZHTClient_c) zhtcppClient; return 0; }
int benmarkTimeAnalize(string cfgFile, string memberList, vector<string> &pkgList, ZHTClient &clientRet, int numTest, int lenString, string Recordpath) { ZHTClient client; // if (client.initialize(cfgFile, memberList) != 0) { if (client.initialize(cfgFile, memberList, TCP) != 0) { cout << "Crap! ZHTClient initialization failed, program exits." << endl; return -1; } double timeRecord[numTest]; //={0}; // bzero(timeRecord, sizeof(timeRecord)); clientRet = client; //reserve this client object for other benchmark(lookup/remove) to use. //vector<string> pkgList; int i = 0; for (i = 0; i < numTest; i++) { Package package, package_ret; package.set_virtualpath(randomString(lenString)); //as key package.set_isdir(true); package.set_replicano(5); //orginal--Note: never let it be nagative!!! package.set_operation(3); // 3 for insert, 1 for look up, 2 for remove package.set_realfullpath( "Some-Real-longer-longer-and-longer-Paths--------"); package.add_listitem("item-----1"); package.add_listitem("item-----2"); package.add_listitem("item-----3"); package.add_listitem("item-----4"); package.add_listitem("item-----5"); string str = package.SerializeAsString(); // cout << "package size = " << str.size() << endl; // cout<<"Client.cpp:benchmarkInsert: "<<endl; // cout<<"string: "<<str<<endl; // cout<<"Insert str: "<<str.c_str()<<endl; // cout<<"data(): "<< str.data()<<endl; pkgList.push_back(str); } double start = 0; double end = 0; double istart = 0; double iend = 0; int errCount = 0; vector<string>::iterator it; int c = 0; ofstream record; record.open(Recordpath.c_str()); start = getTime_msec(); for (it = pkgList.begin(); it != pkgList.end(); it++) { // cout<<c<<endl; c++; double interval = 0; istart = getTime_usec(); int op_ret = client.insert((*it)); iend = getTime_usec(); if (op_ret < 0) { errCount++; interval = -1; } else interval = iend - istart; record << interval << endl; timeRecord[c] = interval; } end = getTime_msec(); record.close(); cout << "Inserted " << numTest - errCount << " packages out of " << numTest << ", cost " << end - start << " ms" << endl; return 0; }
/* * Serializes the metadata of the file and then inserts it in ZHT */ int insertMetadata(string cfgFile, string memberList, vector<string> &pkgList, ZHTClient &clientRet, int numTest, int lenString, string localPath, int codingId, int k, int m, int bufsize) { if (clientRet.initialize(cfgFile, memberList) != 0) { cout << "Crap! ZHTClient initialization failed, program exits." << endl; return -1; } // Define the package for the file, the chunk ids and more Package package, package_ret; package.set_virtualpath(randomString(lenString)); // as key TODO package.set_isdir(true); package.set_replicano(5); // original--Note: never let it be negative!!! package.set_operation(3); // 3 for insert, 1 for look up, 2 for remove package.set_realfullpath(localPath); // Assign the chunk ids to the metadata // TODO: Each insertion for just one chunk or all of them? package.set_ecChunkIds(chunkId); package.set_ecCoding(codingId); package.set_ecK(k); package.set_ecM(m); package.set_ecBufSize(bufsize); string str = package.SerializeAsString(); // cout << "package size = " << str.size() << endl; // cout<<"Client.cpp:insertMetadata: "<<endl; // cout<<"string: "<<str<<endl; // cout<<"Insert str: "<<str.c_str()<<endl; // cout<<"data(): "<< str.data()<<endl; pkgList.push_back(str); //clientRet = client; //reserve this client object for other benchmark(lookup/remove) to use. //vector<string> pkgList; /* int i = 0; for (i = 0; i < numTest; i++) { Package package, package_ret; package.set_virtualpath(randomString(lenString)); //as key package.set_isdir(true); package.set_replicano(5); //orginal--Note: never let it be nagative!!! package.set_operation(3); // 3 for insert, 1 for look up, 2 for remove package.set_realfullpath( "Some-Real-longer-longer-and-longer-Paths--------"); package.add_listitem("item-----2"); package.add_listitem("item-----3"); package.add_listitem("item-----4"); package.add_listitem("item-----5"); package.add_listitem("item-----6"); string str = package.SerializeAsString(); //cout << "package size = " << str.size() << endl; //cout<<"Client.cpp:insertMetadata: "<<endl; //cout<<"string: "<<str<<endl; //cout<<"Insert str: "<<str.c_str()<<endl; //cout<<"data(): "<< str.data()<<endl; pkgList.push_back(str); } */ double start = 0; double end = 0; start = getTime_msec(); int errCount = 0; vector<string>::iterator it; int c = 0; //cout << "-----2" << endl; //string sampleString = *(pkgList.begin()); //struct HostEntity aHost = client.str2Host(sampleString); /* int sock = makeClientSocket("localhost", 50000, 1); cout<<"client sock = "<< sock<<endl; reuseSock(sock); */ for (it = pkgList.begin(); it != pkgList.end(); it++) { //cout <<"insert count "<< c << endl; c++; string str_ins = *it; //cout << "-----1" << endl; int ret = clientRet.insert(str_ins); //cout << "-----2" << endl; if (ret < 0) { errCount++; } } //close(sock); end = getTime_msec(); cout << "Inserted " << numTest - errCount << " packages out of " << numTest << ", cost " << end - start << " ms" << endl; return 0; }