Browse Source

Improved speed on Operations Signature Validation

PascalCoin 5 years ago
parent
commit
48702cae46
2 changed files with 17 additions and 14 deletions
  1. 1 4
      src/core/UNode.pas
  2. 16 10
      src/core/UPCOperationsSignatureValidator.pas

+ 1 - 4
src/core/UNode.pas

@@ -319,10 +319,7 @@ begin
               inc(j);
             end;
           end;
-          if j>0 then begin
-            TLog.NewLog(ltInfo,ClassName,'Buffer Sent operations: Deleted '+IntToStr(j)+' old operations');
-          end;
-          TLog.NewLog(ltdebug,ClassName,'Buffer Sent operations: '+IntToStr(FSentOperations.Count));
+          TLog.NewLog(ltdebug,ClassName,'Buffer Sent operations: '+IntToStr(FSentOperations.Count)+' Deleted old operations: '+IntToStr(j));
           // Notify to clients
           {$IFnDEF TESTING_NO_POW_CHECK}
           if FBroadcastData then begin

+ 16 - 10
src/core/UPCOperationsSignatureValidator.pas

@@ -101,16 +101,19 @@ begin
 end;
 
 function TPCOperationsSignatureValidator.GetNextOperation(AValidatorThread : TPCOperationsSignatureValidatorThread) : TPCOperation;
-var LIndex : Integer;
+var LOp : TPCOperation;
 begin
   FLock.Acquire;
   try
-    // Search new
-    LIndex := FLastIndexOperations + 1; // Move to next
-    if (LIndex<FOperationsList.Count) then begin
-      Result := FOperationsList[LIndex];
-      FLastIndexOperations := Lindex;
-    end else Result := Nil;
+    Result := Nil;
+    // Search next Operation without valid signature
+    While (Result=Nil) do begin
+      Inc(FLastIndexOperations);
+      if (FLastIndexOperations<FOperationsList.Count) then begin
+        LOp := FOperationsList[FLastIndexOperations];
+        if Not LOp.HasValidSignature then Result := LOp;
+      end else Break;
+    end;
   finally
     FLock.Release;
   end;
@@ -127,7 +130,7 @@ begin
   if _Cpus<=0 then begin
     _Cpus := TCPUTool.GetLogicalCPUCount;
   end;
-  if _Cpus<=1 then Exit;
+  if (_Cpus<=1) or (APCOperationsList.Count < (_Cpus*10)) then Exit; // Minimum 2 CPU's and more than 10 ops per CPU
 
     LTC := TPlatform.GetTickCount;
     LMultiThreadValidator := TPCOperationsSignatureValidator.Create(ASafeBoxTransaction,AProgressNotify);
@@ -165,6 +168,9 @@ begin
       Inc(LGlobalOperationsCount, APCOperationsCompList[i].Count );
       APCOperationsCompList[i].OperationsHashTree.GetOperationsList(LList,True);
     end;
+
+    if (LList.Count < (_Cpus*10)) then Exit; // Minimum 10 operations per CPU
+
     LTC := TPlatform.GetTickCount;
     LMultiThreadValidator := TPCOperationsSignatureValidator.Create(ASafeBoxTransaction,AProgressNotify);
     try
@@ -197,7 +203,7 @@ begin
     _Cpus := TCPUTool.GetLogicalCPUCount;
   end;
   if _Cpus<=1 then Exit;
-  if AOperationsHashTree.OperationsCount<_Cpus then Exit;   // If less than cpus, no need for multithreading...
+  if AOperationsHashTree.OperationsCount<(_Cpus*10) then Exit;   // Minimum 10 operations per CPU
 
   LGlobalOperationsCount := AOperationsHashTree.OperationsCount;
   LTC := TPlatform.GetTickCount;
@@ -206,7 +212,7 @@ begin
     LList := TList<TPCOperation>.Create;
     Try
       AOperationsHashTree.GetOperationsList(Llist,True);
-      if LList.Count<_Cpus then Exit; // No need for multithreading...
+      if LList.Count<(_Cpus*10) then Exit; // No need for multithreading...
 
       LValidatedTotal := LMultiThreadValidator.Validate(LList);
       LValidatedOk := LMultiThreadValidator.FValidatedOkCount;