Browse Source

Patch to microbenchmark for PIROS

sshsshy 1 year ago
parent
commit
722ac684e5

+ 14 - 3
apps/client/PIRClient.cpp

@@ -15,11 +15,11 @@
  *  along with XPIR.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+
 #include "PIRClient.hpp"
 //Use this to limit the upload speed to UPLOAD_LIMIT bits per second
 //#define UPLOAD_LIMIT 100000000UL
 
-
 PIRClientSimple::PIRClientSimple(boost::asio::io_service& ios, ClientParams params, FixedVars vars):
 	socket_up(ios),
   replyWriter(pirParams, writeListeners, messageListeners),
@@ -301,7 +301,10 @@ void PIRClientSimple::startProcessQuery()
 
   if(no_pipeline_mode) {
     std::cout << "PIRClient: Calling query generation and upload without pipelining" << std::endl;
-    queryGen.generateQuery(); 
+	
+	gq_start = clock();
+    queryGen.generateQuery();
+	gq_stop = clock(); 
   } else {
     queryGen.startGenerateQuery();
   }
@@ -365,8 +368,16 @@ void PIRClientSimple::startProcessResult()
   {
     std::cout << "PIRClient: Calling reply download, extraction and writting without pipelining" << std::endl;
     downloadWorker(*replyExt);
+
+	er_start = clock();
     replyExt->extractReply(catalog.getMaxFileSize()*pirParams.alpha, replyWriter.getClearDataQueue());
-    // Tell reply writer we finished the extraction
+	er_stop = clock();
+	
+	tclock = gq_stop - gq_start;	
+	std::cout<<"GenQuery Time = %f ms"<< tclock/CLOCKS_PER_SEC <<endl;   
+	tclock = er_stop - er_start;	
+	std::cout<<"ExtractReply Time = %f ms"<< tclock/CLOCKS_PER_SEC <<endl;   
+ // Tell reply writer we finished the extraction
     replyWriter.writeAggregatedFileSecurely(chosenElement, catalog);
   }
   else 

+ 5 - 0
apps/client/PIRClient.hpp

@@ -61,6 +61,9 @@ struct ClientParams
 
   // Dry-run mode
   bool dryrunmode;
+
+  // Batch-query
+  int batchSize;
 };
 
 class PIRClientSimple
@@ -113,6 +116,8 @@ class PIRClientSimple
     void joinAllThreads();
     void no_pipeline(bool b);
 
+	clock_t gq_start, gq_stop, er_start, er_stop, tclock;
+
     /*Add Observers*/
     boost::signals2::connection addMessageListener(messageListener::slot_function_type subscriber);
     boost::signals2::connection addMenuListener(menuListener::slot_function_type subscriber);

+ 2 - 0
apps/client/PIRViewCLI.cpp

@@ -92,6 +92,7 @@ void PIRViewCLI::writeUpdate(WriteEvent& event)
 {
 	using namespace std;
 
+	/*
 	std::cout << "\033[1GPIRReplyWriter: Remaning Bytes to write : " << event.getSizeToWrite() -  event.getWrittenSize() << "                                  \033[5G"  << "\xd"<< std::flush;
 
 	if(event.getSizeToWrite() == event.getWrittenSize())
@@ -99,6 +100,7 @@ void PIRViewCLI::writeUpdate(WriteEvent& event)
 		cout << endl << endl <<"\t## SUCESS ! ##" << endl;
 		cout << "\t   °°°°°°" << endl;
 	}
+	*/
 }
 
 /**

+ 13 - 1
apps/client/main.cpp

@@ -21,6 +21,7 @@
 static const std::string DEFAULT_IP("127.0.0.1");
 static const int DEFAULT_PORT = 1234;
 static const bool DEFAULT_AUTOCHOICE = false;
+static const int DEFAULT_BATCHSIZE = 1;
 
 // Optimizer constants
 static const int DEFAULT_SECURITY = 80;
@@ -67,6 +68,10 @@ void defineClientOptions(ClientParams* paramsPtr, po::options_description* odptr
     
     ("autochoice,c", 
      "Auto-choose the first file")
+
+    ("batchqueries,b",
+	po::value<int>(&paramsPtr->batchSize)->default_value(DEFAULT_BATCHSIZE), 
+     "Auto-choose the first file")
     
     ("dry-run", 
      "Enable dry-run mode")
@@ -400,16 +405,23 @@ int main(int argc, char** argv)
   
   double start = omp_get_wtime();
   
-  
+  clock_t pq_start, pq_stop, pr_start, pr_stop;
+	pq_start = clock();
   /* Asynchronously generate and send the request
      separately in two threads*/
   client.startProcessQuery();
+	pq_stop = clock();
   /* Receive asynchronously the response from the server and
      asynchronously writes it */
+	pr_start = clock();
   client.startProcessResult();
+	pr_stop = clock();
+
 
   client.joinAllThreads();
   double end = omp_get_wtime();
+//cout<<"ssasy : ProcessQuery time taken was " << (double) 1000 * double(pq_stop - pq_start) / double(CLOCKS_PER_SEC)<< "ms" <<endl;
+//cout<<"ssasy : ProcessResult time taken was " << (double) 1000 * double(pr_stop - pq_start) / double(CLOCKS_PER_SEC)<< "ms" <<endl;
   cout << "CLI: Query RTT was " << end-start << " seconds" << endl;
   cout << "CLI: Exiting..." << endl;
 

+ 40 - 4
pir/queryGen/PIRQueryGenerator_internal.cpp

@@ -34,8 +34,19 @@ PIRQueryGenerator_internal::PIRQueryGenerator_internal(PIRParameters& pirParamet
  * Generates asyncronously queries for each files.
  * Makes encrypted of 0 or 1.
  **/
+uint64_t simple_power(uint32_t d, uint32_t n){
+	uint64_t out = n;
+	for(int i=1;i<d;i++)
+		out*=n;	
+	return out;	
+}
+
 void PIRQueryGenerator_internal::generateQuery() 
 {
+  clock_t gq_start, gq_end; 
+	gq_start = clock();
+	size_t single_encrypted_val_size=0, size_se =0;
+
   double start = omp_get_wtime();
 	coord = new unsigned int[pirParams.d]();
 
@@ -44,15 +55,40 @@ void PIRQueryGenerator_internal::generateQuery()
 	{
 		for (unsigned int i = 0 ; i < pirParams.n[j] ; i++) 
 		{
-			if (i == coord[j]) queryBuffer.push(cryptoMethod.encrypt(1, j + 1 ));
-			else queryBuffer.push(cryptoMethod.encrypt(0, j + 1));
+
+			if(j==0&&i==0){
+				char *tmp = cryptoMethod.encrypt(0, j + 1);
+				single_encrypted_val_size=strlen(tmp);
+				size_se = cryptoMethod.getPublicParameters().getQuerySizeFromRecLvl(j+1) / (8);
+				//std::cout << "ssasy_size: PIRQueryGenerator_internal: Generated a " << single_encrypted_val_size << " char(byte)-sized element query" << std::endl;
+				std::cout << "measure_size_single:PIRQueryGenerator_internal:single_query_size:"<< size_se <<":bytes" << std::endl;
+				//std::cout << "measure_size:PIRQueryGenerator_internal:single_query_size:"<< (size_t)(size_se*(size_t)(simple_power(pirParams.d, pirParams.n[0]))) <<":bytes" << std::endl;
+				//std::cout << "measure_size:PIRQueryGenerator_internal:single_query_size:"<< (size_t)(size_se*(size_t)(compute_recursive_query_size(pirParams.d, pirParams.n))) <<":bytes" << std::endl;
+				}
+				if (i == coord[j]) queryBuffer.push(cryptoMethod.encrypt(1, j + 1 ));
+				else 
+					queryBuffer.push(cryptoMethod.encrypt(0, j + 1));
 	  }
-  std::cout << "PIRQueryGenerator_internal: Generated a " << pirParams.n[j] << " element query" << std::endl;
   }
+   
+  size_t final_size = 0, size = 0;
+  for (unsigned int i=1; i<=pirParams.d; i++) {
+    size_t size_se = cryptoMethod.getPublicParameters().getQuerySizeFromRecLvl(i) / (8);
+    size=(pirParams.n[i-1] * size_se);
+    final_size+=size;
+  }
+  std::cout << "measure_size:PIRQueryGenerator_internal:single_query_size:"<< final_size <<":bytes" << std::endl;
+  std::cout << "other_params:"<<pirParams.d<<":"<<pirParams.alpha<<std::endl;
+
   double end = omp_get_wtime();
+  gq_end = clock();
   delete[] coord;
-  
   std::cout << "PIRQueryGenerator_internal: All the queries have been generated, total time is " << end - start << " seconds" << std::endl;
+  std::cout << "consensgx1 : QueryGeneration time is " << (double)1000 * double(gq_end - gq_start)/(double)CLOCKS_PER_SEC << " ms" << std::endl; 
+  std::cout << "measure_params:PIRQueryGenerator_internal:pirParams.d :" <<pirParams.d<< ":pirParams.alpha:"<<pirParams.alpha<<":pirParams.n[]:" ;  
+	for (unsigned int i = 0 ; i < pirParams.d ; i++) 
+		std::cout << pirParams.n[i] << ", ";
+  std::cout<<std::endl << std::flush;
 }
 
 /**

+ 13 - 3
pir/replyExtraction/PIRReplyExtraction_internal.cpp

@@ -40,15 +40,18 @@ PIRReplyExtraction_internal::PIRReplyExtraction_internal(PIRParameters& param_,
  **/
 void PIRReplyExtraction_internal::extractReply(int aggregated_maxFileSize, shared_queue<char*>* clearChunks)
 {
+  uint64_t response_size=0;
   unsigned long ciphertext_nbr = 1;
   unsigned int data_size, data_size2b;
   char *data, *in_data, *in_data_2b;
   double start = omp_get_wtime();
+	clock_t er_start, er_stop;
   uint64_t total_ciphertext_nbr= 0;
-
+	er_start=clock();
   for (unsigned int rec_lvl = pirParams.d ; rec_lvl >= 1 ; rec_lvl--)
   {
     ciphertext_nbr = ceil(static_cast<float>(aggregated_maxFileSize) / static_cast<float>(cryptoMethod.getPublicParameters().getAbsorptionBitsize(0)/GlobalConstant::kBitsPerByte));
+    std::cout<<"consensgx:PIRReplyExtraction_internal: First layer ciphertext_nbr="<<ciphertext_nbr<<", AbsorptionBitsize = "<<cryptoMethod.getPublicParameters().getAbsorptionBitsize(0)<<", aggregated_maxFileSize="<<aggregated_maxFileSize<<std::endl;
 #ifdef DEBUG
 	std::cout<<"PIRReplyExtraction_internal: First layer ciphertext_nbr="<<ciphertext_nbr<<std::endl;
 #endif
@@ -58,7 +61,7 @@ void PIRReplyExtraction_internal::extractReply(int aggregated_maxFileSize, share
       ciphertext_nbr =  ceil(float(ciphertext_nbr) * float(cryptoMethod.getPublicParameters().getCiphBitsizeFromRecLvl(i)/GlobalConstant::kBitsPerByte) / float(cryptoMethod.getPublicParameters().getAbsorptionBitsize(i)/GlobalConstant::kBitsPerByte));
     }
     total_ciphertext_nbr += ciphertext_nbr;
-
+    std::cout<<"consensgx: Total_ciphertext_nbr = "<<total_ciphertext_nbr<<std::endl;
 #ifdef DEBUG
 	std::cout<<"PIRReplyextraction: Last layer ciphertext_nbr="<<ciphertext_nbr<<std::endl;
 #endif
@@ -67,6 +70,7 @@ void PIRReplyExtraction_internal::extractReply(int aggregated_maxFileSize, share
 
     data_size  = cryptoMethod.getPublicParameters().getCiphBitsizeFromRecLvl(rec_lvl) / GlobalConstant::kBitsPerByte ;
     data_size2b = cryptoMethod.getPublicParameters().getAbsorptionBitsize(rec_lvl-1)/GlobalConstant::kBitsPerByte;
+    std::cout<<"consensgx: data_size="<<data_size<<" data_size2b="<<data_size2b;
     if (rec_lvl > 1) in_data_2b = (char*) calloc(data_size2b * ciphertext_nbr, sizeof(char));
 
 #ifdef DEBUG
@@ -80,6 +84,7 @@ void PIRReplyExtraction_internal::extractReply(int aggregated_maxFileSize, share
       if (rec_lvl == pirParams.d && j == 0 ) 
       { 
         cout << "PIRReplyExtraction_internal: Starting reply extraction..." << endl;
+
       }
       out_data = cryptoMethod.decrypt(data, rec_lvl, data_size, data_size2b);
      if (rec_lvl > 1) {
@@ -101,8 +106,13 @@ void PIRReplyExtraction_internal::extractReply(int aggregated_maxFileSize, share
     if (rec_lvl < pirParams.d) free(in_data);
     in_data = in_data_2b;
   }
+	er_stop = clock();
+  response_size = data_size * total_ciphertext_nbr;
+  std::cout<<"measure_response_size:"<<response_size<<std::endl;
   cout << "PIRReplyExtraction_internal: Reply extraction finished, " << total_ciphertext_nbr <<
-    " reply elements decrypted in " << omp_get_wtime() - start << " seconds" << endl;
+    " reply elements decrypted in " << omp_get_wtime() - start << " seconds" << std::endl;
+  cout << "consensgx2 : ReplyExtraction finished, time taken was " << (double)1000 * (double)(er_stop - er_start) /(double)(CLOCKS_PER_SEC) << " ms" << std::endl;
+    cout << "PIRReplyExtraction_internal: data_size=" << data_size << " data_size2b=" << data_size2b << std::endl << std::flush;
 }
 
 

+ 16 - 4
pir/replyGenerator/PIRReplyGeneratorNFL_internal.cpp

@@ -204,6 +204,7 @@ imported_database_t PIRReplyGeneratorNFL_internal::generateReplyGeneric(bool kee
   imported_database_t database_wrapper;
   uint64_t usable_memory, database_size, max_memory_per_file, max_readable_size, nbr_of_iterations;
   double start, end;
+clock_t rg_start, rg_stop;
 
   // Init database_wrapper to NULL values so that we are able to know if it has been initialized
   database_wrapper.imported_database_ptr = NULL;
@@ -253,6 +254,8 @@ imported_database_t PIRReplyGeneratorNFL_internal::generateReplyGeneric(bool kee
   }
 
   start = omp_get_wtime();
+rg_start = clock();
+
 // #pragma omp parallel for
   for (unsigned iteration = 0; iteration < nbr_of_iterations; iteration++)
   {
@@ -270,6 +273,8 @@ imported_database_t PIRReplyGeneratorNFL_internal::generateReplyGeneric(bool kee
     repliesAmount = computeReplySizeInChunks(dbhandler->getmaxFileBytesize());
     generateReply();
     end = omp_get_wtime();
+rg_stop = clock();
+
 
     if(keep_imported_data && iteration == nbr_of_iterations - 1)  // && added for Perf test but is no harmful
     {
@@ -282,10 +287,13 @@ imported_database_t PIRReplyGeneratorNFL_internal::generateReplyGeneric(bool kee
       freeInputData();
     }
   }
-
+	std::cout<<"nbr_of_iterations:"<<nbr_of_iterations<<std::endl;
+	std::cout<<"measure_reply_size:"<<repliesAmount<<std::endl;
+	std::cout<<"consensgx : ReplyGeneration time was " << (double) 1000 * double(rg_stop - rg_start) / double(CLOCKS_PER_SEC)<< " ms" <<endl<<std::flush;
 	std::cout<<"PIRReplyGeneratorNFL_internal: Total process time " << end - start << " seconds" << std::endl;
 	std::cout<<"PIRReplyGeneratorNFL_internal: DB processing throughput " << 8*database_size/(end - start) << "bps" << std::endl;
 	std::cout<<"PIRReplyGeneratorNFL_internal: Client cleartext reception throughput  " << 8*dbhandler->getmaxFileBytesize()/(end - start) << "bps" << std::endl;
+
   freeQueries();
 
   return database_wrapper;
@@ -301,6 +309,7 @@ void PIRReplyGeneratorNFL_internal::generateReplyGenericFromData(const imported_
   currentMaxNbPolys = database.polysPerElement;
 	boost::mutex::scoped_lock l(mutex);
   double start = omp_get_wtime();
+  clock_t rg_start = clock();
   repliesAmount = computeReplySizeInChunks(database.beforeImportElementBytesize);
   generateReply();
 #else
@@ -312,10 +321,11 @@ void PIRReplyGeneratorNFL_internal::generateReplyGenericFromData(const imported_
   max_readable_size = min(max_readable_size, database.beforeImportElementBytesize);
   // Given readable size we get how many iterations we need
   nbr_of_iterations = ceil((double)database.beforeImportElementBytesize/max_readable_size);
-
+  std::cout<<"nbr_of_iterations:"<<nbr_of_iterations<<std::endl;
 
   boost::mutex::scoped_lock l(mutex);
   double start = omp_get_wtime();
+  clock_t rg_start = clock();
   for (unsigned iteration = 0; iteration < nbr_of_iterations; iteration++)
   {
 
@@ -326,8 +336,11 @@ void PIRReplyGeneratorNFL_internal::generateReplyGenericFromData(const imported_
   }
   freeInputData();
 #endif
+	clock_t rg_stop = clock();
   double end = omp_get_wtime();
-	std::cout<<"PIRReplyGeneratorNFL_internal: Total process time " << end - start << " seconds" << std::endl;
+	std::cout<<"measure_reply_size:"<<repliesAmount<<std::endl;
+	std::cout<<"consensgx : ReplyGeneration time was " << (double) 1000 * double(rg_stop - rg_start) / double(CLOCKS_PER_SEC)<< " ms" <<endl;
+	std::cout<<"PIRReplyGeneratorNFL_internal: Total process time " << end - start << " seconds" << std::endl << std::flush;
 	std::cout<<"PIRReplyGeneratorNFL_internal: DB processing throughput " << 8*dbhandler->getmaxFileBytesize()*dbhandler->getNbStream()/(end - start) << "bps" << std::endl;
 	std::cout<<"PIRReplyGeneratorNFL_internal: Client cleartext reception throughput  " << 8*dbhandler->getmaxFileBytesize()/(end - start) << "bps" << std::endl;
   freeQueries();
@@ -354,7 +367,6 @@ void PIRReplyGeneratorNFL_internal::generateReply()
   if (repliesArray != NULL) freeResult();
   repliesArray = (char**)calloc(repliesAmount,sizeof(char*)); 
 
-
   // Start global timers
   double start = omp_get_wtime();