Browse Source

Apply abstractmem improvements/optimizations on PascalCoin

PascalCoin 4 years ago
parent
commit
2184bd8928

+ 6 - 0
src/core/UAccounts.pas

@@ -3395,6 +3395,9 @@ begin
   tc := TPlatform.GetTickCount;
   StartThreadSafe;
   try
+    {$IFDEF USE_ABSTRACTMEM}
+    FPCAbstractMem.SavingNewSafeboxMode := True;
+    {$ENDIF}
     LStartTickCount := tc;
     // Read Header info
     If not LoadSafeBoxStreamHeader(Stream,sbHeader) then begin
@@ -3695,6 +3698,9 @@ begin
       if Not Result then Clear else errors := '';
     End;
   Finally
+    {$IFDEF USE_ABSTRACTMEM}
+    FPCAbstractMem.SavingNewSafeboxMode := False;
+    {$ENDIF}
     EndThreadSave;
   end;
   TLog.NewLog(ltdebug,ClassName,Format('Finalized read Safebox from blocks %d to %d (total %d blocks) in %.2f seconds',

+ 1 - 1
src/core/UBaseTypes.pas

@@ -635,7 +635,7 @@ end;
 procedure TBytesBuffer.SetDefaultIncrement(AValue: Integer);
 begin
   if AValue<=0 then FDefaultIncrement:=1024
-  else if AValue>(1024*1024) then FDefaultIncrement := 1024*1024
+  else if AValue>(100*1024*1024) then FDefaultIncrement := (100*1024*1024)
   else FDefaultIncrement:=AValue;
 end;
 

+ 36 - 5
src/core/UPCAbstractMem.pas

@@ -7,7 +7,7 @@ interface
 {$ENDIF}
 
 uses Classes, SysUtils, SyncObjs,
-  UAbstractMem, UFileMem, UAbstractMemTList,
+  UAbstractMem, UFileMem, UAbstractMemTList, UCacheMem,
   UAbstractBTree, UThread,
   UAVLCache, ULog, UCrypto,
   UPCAbstractMemAccountKeys,
@@ -124,6 +124,10 @@ type
     FZoneAggregatedHashrate : TAMZone;
     FUseCacheOnAbstractMemLists: Boolean;
     FMaxMemUsage: Integer;
+    FSavingNewSafeboxMode: Boolean;
+
+    FSavingOldGridCache : Boolean;
+    FSavingOldDefaultCacheDataBlocksSize : Integer;
 
     function IsChecking : Boolean;
     procedure DoCheck;
@@ -138,6 +142,7 @@ type
     function GetMaxAccountsCache: Integer;
     function GetMaxAccountKeysCache: Integer;
     procedure SetMaxAccountKeysCache(const Value: Integer);
+    procedure SetSavingNewSafeboxMode(const Value: Boolean);
   protected
     procedure UpgradeAbstractMemVersion(const ACurrentHeaderVersion : Integer);
   public
@@ -179,6 +184,7 @@ type
     Property MaxMemUsage : Integer read FMaxMemUsage write SetMaxMemUsage;
     Property MaxAccountsCache : Integer read GetMaxAccountsCache write SetMaxAccountsCache;
     Property MaxAccountKeysCache : Integer read GetMaxAccountKeysCache write SetMaxAccountKeysCache;
+    Property SavingNewSafeboxMode : Boolean read FSavingNewSafeboxMode write SetSavingNewSafeboxMode;
   end;
 
 implementation
@@ -203,7 +209,7 @@ var LZone : TAMZone;
   LCachedSafeboxHash : TBytes;
 begin
   FCachedSafeboxHash := Nil;
-  inherited Create(1000*32);
+  inherited Create(100000*32);
   FAbstractMem := AAbstractMem;
   FSaveBufferPosition:=APosition;
   if (APosition>0) then begin
@@ -539,10 +545,10 @@ begin
   // Free
   FreeAndNil(FBlocks);
   //
-  FBlocks := TPCAbstractMemListBlocks.Create( FAbstractMem, LZoneBlocks, 10000, Self.UseCacheOnAbstractMemLists);
+  FBlocks := TPCAbstractMemListBlocks.Create( FAbstractMem, LZoneBlocks, 20000, Self.UseCacheOnAbstractMemLists);
   FBlocks.FPCAbstractMem := Self;
 
-  FAccounts := TPCAbstractMemListAccounts.Create( FAbstractMem, LZoneAccounts, 50000, Self.UseCacheOnAbstractMemLists);
+  FAccounts := TPCAbstractMemListAccounts.Create( FAbstractMem, LZoneAccounts, 100000, Self.UseCacheOnAbstractMemLists);
   FAccounts.FPCAbstractMem := Self;
 
   FAccountsNames := TPCAbstractMemListAccountNames.Create( FAbstractMem, LZoneAccountsNames, 5000 , False, Self.UseCacheOnAbstractMemLists);
@@ -597,10 +603,11 @@ begin
   FCheckingThread := Nil;
   FLockAbstractMem := TPCCriticalSection.Create(Self.ClassName);
   FAccountCache := TAccountCache.Create(10000,_AccountCache_Comparision);
+  FSavingNewSafeboxMode := False;
 
   FAggregatedHashrate := TBigNum.Create(0);
   FFileName := ASafeboxFileName;
-  if (FFileName<>'') {and (FileExists(ASafeboxFileName))} then begin
+  if (FFileName<>'') then begin
     FAbstractMem := TFileMem.Create( ASafeboxFileName , AReadOnly);
   end else begin
     FAbstractMem := TMem.Create(0,AReadOnly);
@@ -836,6 +843,30 @@ begin
   end;
 end;
 
+procedure TPCAbstractMem.SetSavingNewSafeboxMode(const Value: Boolean);
+var Lcm : TCacheMem;
+begin
+  FSavingNewSafeboxMode := Value;
+  // Will set in optimized state (cache and others) for maximum performance and minimum impact
+  TLog.NewLog(ltinfo,ClassName,Format('Seting AbstractMem is Saving mode:%s',[Value.ToString]));
+  if FAbstractMem is TFileMem then begin
+    Lcm := TFileMem(FAbstractMem).LockCache;
+    try
+      if Value then begin
+        FSavingOldGridCache := Lcm.GridCache;
+        FSavingOldDefaultCacheDataBlocksSize := Lcm.DefaultCacheDataBlocksSize;
+        Lcm.GridCache := False;
+        Lcm.DefaultCacheDataBlocksSize := -1;
+      end else begin
+        Lcm.GridCache := FSavingOldGridCache;
+        Lcm.DefaultCacheDataBlocksSize := FSavingOldDefaultCacheDataBlocksSize;
+      end;
+    finally
+      TFileMem(FAbstractMem).UnlockCache;
+    end;
+  end;
+end;
+
 procedure TPCAbstractMem.SetUseCacheOnAbstractMemLists(const Value: Boolean);
 var Lins : Boolean;
 begin

+ 1 - 1
src/core/upcdaemon.pas

@@ -266,7 +266,7 @@ begin
       FNode := TNode.Node;
       {$IFDEF USE_ABSTRACTMEM}
       LMaxMemMb := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_MAX_CACHE_MB,100);
-      LUseCacheOnMemLists:= FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_USE_CACHE_ON_LISTS,True);
+      LUseCacheOnMemLists:= FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_USE_CACHE_ON_LISTS,False);
       LCacheMaxAccounts := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_CACHE_MAX_ACCOUNTS,10000);
       LCacheMaxPubKeys := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_CACHE_MAX_PUBKEYS,5000);
 

+ 1 - 1
src/pascalcoin_daemon.ini

@@ -55,7 +55,7 @@ DATAFOLDER=
 ;Maximum megabytes in memory as a cache - Default 100
 ABSTRACTMEM_MAX_CACHE_MB=
 ;ABSTRACTMEM_USE_CACHE_ON_LISTS : Boolean
-;Set to true (1) to allow save lists on cache or false (0) - Default TRUE
+;Set to true (1) to allow save lists on cache or false (0) - Default False
 ABSTRACTMEM_USE_CACHE_ON_LISTS=
 ;ABSTRACTMEM_CACHE_MAX_ACCOUNTS : Integer
 ;Max number of accounts to store at cache - Default 10000