binary exponential backoff for soft abort
authoradash <adash>
Tue, 9 Feb 2010 20:14:52 +0000 (20:14 +0000)
committeradash <adash>
Tue, 9 Feb 2010 20:14:52 +0000 (20:14 +0000)
Robust/src/Runtime/DSTM/interface/trans.c

index d233b2dfa82fffff122e34fe671427aeeef34632..1eeca47fb4c32257481433bb97eedbb2a66aa42d 100644 (file)
@@ -87,12 +87,15 @@ int myIndexInHostArray;
 unsigned int oidsPerBlock;
 unsigned int oidMin;
 unsigned int oidMax;
-
 sockPoolHashTable_t *transReadSockPool;
 sockPoolHashTable_t *transPrefetchSockPool;
 sockPoolHashTable_t *transRequestSockPool;
 pthread_mutex_t notifymutex;
 pthread_mutex_t atomicObjLock;
+struct timespec exponential_backoff;
+static int count_exponential_backoff = 0;
+static const int max_exponential_backoff = 1000; // safety limit
+
 
 /***********************************
  * Global Variables for statistics
@@ -534,6 +537,17 @@ void randomdelay() {
   return;
 }
 
+void exponentialdelay() {
+  exponential_backoff.tv_nsec = exponential_backoff.tv_nsec * 2;
+  nanosleep(&exponential_backoff, NULL);
+  ++count_exponential_backoff;
+  if (count_exponential_backoff >= max_exponential_backoff) {
+    printf(" reached max_exponential_backoff at %s, %s(), %d\n", __FILE__, __func__, __LINE__);
+    exit(-1);
+  }
+  return;
+}
+
 /* This function initializes things required in the transaction start*/
 void transStart() {
   t_cache = objstrCreate(1048576);
@@ -943,6 +957,9 @@ int transCommit() {
 #endif
 
 
+  int treplyretryCount = 0;
+  exponential_backoff.tv_sec = 0;
+  exponential_backoff.tv_nsec = (long)(10000);//10 microsec
   do {
     treplyretry = 0;
 
@@ -1159,7 +1176,11 @@ int transCommit() {
       pDelete(pile_ptr);
     /* wait a random amount of time before retrying to commit transaction*/
     if(treplyretry) {
-      randomdelay();
+      treplyretryCount++;
+      if(treplyretryCount >= NUM_TRY_TO_COMMIT)
+        exponentialdelay();
+      else 
+        randomdelay();
 #ifdef TRANSSTATS
       nSoftAbort++;
 #endif
@@ -1167,6 +1188,11 @@ int transCommit() {
     /* Retry trans commit procedure during soft_abort case */
   } while (treplyretry);
 
+  /* Reset to initial timeout for exponential delay */
+  exponential_backoff.tv_sec = 0;
+  exponential_backoff.tv_nsec = (long)(10000);//10 microsec_
+  count_exponential_backoff = 0;
+
   if(finalResponse == TRANS_ABORT) {
 #ifdef TRANSSTATS
     LOGEVENT('A');