Recent

Author Topic: ParalellVarFiler version 1.17  (Read 27428 times)

aminer

  • Hero Member
  • *****
  • Posts: 956
ParalellVarFiler version 1.17
« on: October 19, 2013, 05:26:42 pm »


Hello,

ParallelVarFiler was updated to version 1.17, from now on you don't need to call the LoadData().

Authors: Amine Moulay Ramdane and Peter Johansson

Parallel Variable filer and streamer for Delphi and Freepascal that can be used also as a parallel hashtable and that uses ParallelHashList (Parallel Hashtable) with O(1) best case and O(log(n)) worst case access that uses lock striping and lightweight MREWs(multiple-readers-exclusive-writer) , this allows multiple threads to write and read concurently. also ParallelHashList maintains an independant counter , that counts the number of entries , for each segment of the hashtable and uses a lock for each counter, this is also for better scalability.

Description:

Collect different types of variables and save them into one file or stream. TParallelVarFiler reads and writes on files, streams and Strings. You can collect Strings, Integers and Dates, in fact everything that can be stored in a variant. In addition you can collect Streams.

You can use also ParallelVarFiler to send parameters over network. It can be used for example to share data by any IPC mechanism.

And please look at test.pas and test1.pas a parallel variable filer examples - compile and execute them...

Now you can use ParallelVarFiler as a small to medium database, i have added a Clean() and DeletedItems() methods and i have changed the constructor, now you can pass a file name to the constructor where the data will be wrote and updated and deleted... if you pass and empty file name the data will be updated and wrote and deleted only in memory. When you use a file name in the constructor, many readers and one writer can proceed concurrently. But when you pass an empty file name to the constructor, many writers and many readers can proceed concurrently in memory. and when you read a data item it only use the parallel hashtable in memory, hardisk is not used.

And when you pass a file name to the constructor and delete or update the items, those items will be marked deleted from the file, and you can use DeletedItems() to see how many data items are marked deleted in the file, and use after that the Clean() method to delete completly those data items from the file.

How can you store mutiple data inside a database row and map it to a key ?

You can simply use Parallel Variable Filer for that and stream your mutiple data variants and map them to a key...

As you know ParallelVarFiler is using ParallelHashList (a parallel hashtable that scales on multicores), so when you are using the GetKeys() method , and you want to get the data of those keys don't forget to test if the variant is not empty by using the VarIsEmpty() function, and when you are using GetStream() you can test if the data exists by testing the return boolean value from GetStream().

ParallelVarFiler is easy to learn, i have documented all the methods , and please read inside ParallelVarFiler.pas about
them.

Now ParallelVarFiler is Fault tolerant to power failures etc. i have done a simulation of power failures and data file damages and ParallelVarFiller is recovering from power failure and damages of the data file ... And when there is a power failure or the program has crached and you want to recover from a damage to your data file you have only to call the LoadData() method.

As you know ParallelVarFiler is using ParallelHashList (a parallel hashtable), but as you know ParallelHashList is cache unfriendly since it's using a hash mechanism etc. and as you know ParallelVarFiler and ParallelHashlist  are memory bound, so since ParallelHashList is cache unfriendly and  it's memory bound so i don't think ParallelVarFiler or ParallelHahsList will scale very well, to avoid this problem you have to use something like replication across computers using TCP/IP and using your database in each computer and load balance between computers, but even if you are using replication and load balancing this can make the memory and hardisk truly parallel but this will not avoid the problem with the network bandwidth limitation. But ParallelVarFiler and ParallelHashlist are scaling to a certain point and they are fast and they are still usefull.

Please see the test.pas example inside the zip file to see how i am using it...

But please read the following:

This software is provided on an "as-is" basis, with no warranties, express or implied. The entire risk and liability of using it is yours. Any damages resulting from the use or misuse of this software will be the responsibility of the user.

please look at the test.pas and test1.pas example inside the zip file to see how to use ParallelVarFiler...


You can download ParallelVarFiler from:

http://pages.videotron.com/aminer/

Here is the methods that have been implemented:

PUBLIC METHODS:

constructor Create(file1:string,size,mrews:integer;casesensitive:boolean);

- Creates a new VarFiler ready to use, with size and with mrews number of mrewa and casesensitive

for case sensitive keys,the number of MREWS(multiple-readers-exclusive-writer) must be less or

equal to the Hashtable size and file1 is the the file to write to, if file1 is an empty string

the data will be wrote only to memory and use SaveToFile() to write to a file.

destructor Destroy;

- Destroys the ParallelVarFiler object and cleans up.

procedure Clear;

- Deletes all contents.

function Clean:boolean

- Cleans the deleted items from the file.

function DeletedItems:integer

- Returns the number of items marked deleted.

function LoadData:boolean

- Loads the data from the file passed to the constructor.

function Delete(Name : String):boolean;

- Deletes the variable with Name.

function Exists(Name : String) : Boolean;

- Returns True if a variable with Name exists

procedure GetKeys(Strings : TstringList);

- Fills up a TStringList descendant with all the keys.

function Count : Integer;

- Returns the number of variables

function Add(Name : String; Value : Variant ):boolean;

- Adds a new variable , given the Name

function AddStream( Name : String;Stream : TStream ):boolean;

- Adds a new Stream, given the Name

function Update(Name : String; Value : Variant):boolean;

- Updates the new variable , given the Name

function UpdateStream(Name : String; Stream : TStream ):boolean;

- Updates a new Stream , given the Name

function GetStream(Name : String;Stream : TStream):boolean;

- Fills up the stream with data

procedure SaveToStream(Stream : TStream);

- Saves all variables, streams and Graphics to a stream.

procedure SaveToFile(FileName : String);

- Saves all variables, streams and Graphics to a file.

procedure SaveToString(out S : String);

- Saves all variables, streams and Graphics to a string.

function LoadFromStream(Stream : TStream):boolean;

- Loads all variables, streams and Graphics from a stream.

function LoadFromFile(FileName : String):boolean;

- Loads all variables, streams and Graphics from a File.

function LoadFromString(S : String):boolean;

- Loads all variables, streams and Graphics from a string.

function Stream2String(Stream1: TStream;var Mystring:string): boolean;

procedure String2Stream(var String2BeSaved:string; Stream1: TStream);

procedure Variant2Stream(var VR:variant; Stream1: TStream);

function Stream2Variant(Stream1: TStream;var VR:variant): boolean;


PUBLIC PROPERTIES:

Items : Variant

- Gets the value (indexed).


Language: FPC Pascal v2.2.0+ and Lazarus / Delphi 7 to 2007: http://www.freepascal.org/

Operating Systems: Win , Linux and Mac (x86).

Required FPC switches: -O3 -Sd -dFPC -dWin32 -dFreePascal

-Sd for delphi mode....

Required Delphi switches: -DMSWINDOWS -$H+

For Delphi use -DDelphi


Thank you,
Amine Moulay Ramdane.


aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #1 on: October 19, 2013, 05:36:40 pm »

Hello,

You have to understand ParallelVarFiller ,
it's a Parallel HashTable that can be saved automaticly
or manually to a file or to a stream or to a string and it's
fault tolerant to power failure etc.


Hope you have understood the idea.



Thank you,
Amine Moulay Ramdane.




aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #2 on: October 19, 2013, 05:39:46 pm »


I will add..

You have to understand ParallelVarFiller ,
it's a Parallel HashTable that can be saved automaticly or manually to a file or to a stream or to a string and it can be restored from
a file or from a stream or from a string back to the Hashtable in memory, and it's
fault tolerant to power failure etc.


Hope you have understood the idea.



Thank you,
Amine Moulay Ramdane.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ParalellVarFiler version 1.17
« Reply #3 on: October 20, 2013, 12:30:06 pm »
Had a quick look at the "ParallelVarFiller". The code is as clear as your posts and full of errors.

Just for starters:

function TParallelVarFiler.GetRow(Name : String) : TParallelVarFiler;
You create vf:=TParallelVarFiler.create('',20,20,false) and if you can't find name, you don't free it. Nice memory leak.

function TParallelVarFiler.Clean:boolean;
you enter a critical section and leave the critical section without any try finally. A single error in the fileoperations at the end and your critical section is locked forever.
BTW, I don't get all your crap about fast parallel processing and all your fancy techniques when you do a copy of a complete file inside a critical section. That is just bad programming.

function TParallelVarFiler.DeletedItems:integer;
Same problem with critsec and no try finally

function TParallelVarFiler.Delete(Name : String):boolean;
Same problem with critsec and no try finally. Here again, for a fast algorithm this is the most crappy thing I have seen. You are doing a locate in the filestream and set the deleted bit  :o Where does your claim come from that this is failproof? That is a complete mystery. Clearly you don't understand anything about filestreams and file systems.

function TParallelVarFiler.Add(Name : String;Value : Variant):boolean;
Same problem with critsec and no try finally. I think you are little by little getting the point.  Here also, just writing to a filestream inside a critical section. Why all this fuzz about scalability, parallel hashtable, ... when everything is written to disk in a critical section? And here also, no sign of fault tolerance, nu flushing to harddisk, nothing.

function TParallelVarFiler.LoadFromString(S : String):boolean;
Does a Stream.Write(Pointer(S)^, Length(S)) without checking if S is not null. SIGSEGV ahoi.

You are writing in a critsect to the filestream but you don't use the critsect in LoadFromStream. That is going to give some very nice results when you start writing while a LoadFromStream is done in another thread.

procedure TParallelVarFiler.SaveToStream(Stream : TStream);
You get a list of all objects from the hashtable and write them to a filestream. What happens if  objects get deleted or changed in another thread in the mean time? Right, you got it.

Your test program is not using threads. What parallelism are you testing in a single thread? Obviously you wouldn't encounter any of the above problems with such a simple test.

You took the TScwVarFiler code from Peter Johansson and added your hash stuff on top of  it and call it ParallelVarFiller. Is Peter Johansson aware that he is marked as co-author of this monstruous code?

Hope you have understood the idea. A shame to release something like that.
« Last Edit: October 20, 2013, 12:36:23 pm by ludob »

aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #4 on: October 20, 2013, 06:42:30 pm »

ludob wrote:
>function TParallelVarFiler.Clean:boolean;
>you enter a critical section and leave >the critical section without any try >finally. A single error in the >fileoperations at the end and your >critical section is locked forever.
>BTW, I don't get all your crap about >fast parallel processing and all your >fancy techniques when you do a copy >of a complete file inside a critical >section. That is just bad programming.


I am using a Try Except , so if there is a memory or disk problem it will generate an exception i think, and i am catching the exception...same for the others..

>procedure >TParallelVarFiler.SaveToStream(Stream : TStream);
>You get a list of all objects from the >hashtable and write them to a >filestream. What happens if  objects >get deleted or changed in another >thread in the mean time? Right, you got it.

You have to use it in a single thread.

>function >TParallelVarFiler.LoadFromString(S : >String):boolean;
>Does a Stream.Write(Pointer(S)^, >Length(S)) without checking if S is not >null. SIGSEGV ahoi.


I have corrected this bug.


Thank you,
Amine Moulay Ramdane.

aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #5 on: October 20, 2013, 06:53:17 pm »

ludob wrote:
>function TParallelVarFiler.GetRow(Name : >String) : TParallelVarFiler;
>You create >vf:=TParallelVarFiler.create('',20,20,false) >and if you can't find name, you don't free >it. Nice memory leak.

when you pass an empty string name , it's an in-memory TParallelVarfiler, there is no bug.


Thank you,
Amine Moulay Ramdane.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ParalellVarFiler version 1.17
« Reply #6 on: October 20, 2013, 07:17:37 pm »
I am using a Try Except , so if there is a memory or disk problem it will generate an exception i think, and i am catching the exception...same for the others..
This is your code:
Code: [Select]
function TParallelVarFiler.Clean:boolean;
....
Begin

if usedisk
then
begin
critsec.enter;
Try
....
  Except
    setlength(str,0);
    VR^.s:='';
    dispose(VR);
    fstream2.free;
    deletefile(ffile+'.new');
    result:=false;
    exit;
  End;
fstream2.free;
fstream1.free;
deletefile(ffile);
renamefile(ffile+'.new',ffile);

If FileExists(ffile)
    then
    Begin
     fstream1:=TFileStream.create(ffile,fmOpenReadWrite );
    End
   else
    fstream1:=TFileStream.create(ffile,fmcreate);

dispose(VR);

result:=true;
critsec.leave;
end;
END;
There is alot going on outside the try except and even inside the except that can cause a new exception and that results in critsec.leave never being called. None of that is caught.
In TParallelVarFiler.DeletedItems and TParallelVarFiler.Delete you do the critsec.leave just before the except meaning that in a case of an exception you never leave the critsec. These are basic programming skills.

>procedure >TParallelVarFiler.SaveToStream(Stream : TStream);
>You get a list of all objects from the >hashtable and write them to a >filestream. What happens if  objects >get deleted or changed in another >thread in the mean time? Right, you got it.

You have to use it in a single thread.

Very useful for a parallel library  :D
And I don't see that anywhere mentioned in your documentation.


ludob wrote:
>function TParallelVarFiler.GetRow(Name : >String) : TParallelVarFiler;
>You create >vf:=TParallelVarFiler.create('',20,20,false) >and if you can't find name, you don't free >it. Nice memory leak.

when you pass an empty string name , it's an in-memory TParallelVarfiler, there is no bug.
Ah, and in memory TParallelVarfiler doesn't have to be freed  :o
Code: [Select]
function TParallelVarFiler.GetRow(Name : String) : TParallelVarFiler;
var
  I : Integer;
  VR : PScwVarRecord;
  obj:pointer;
  mrew1:TOmniMREW;
  vf:TParallelVarFiler;
Begin
Try
 vf:=TParallelVarFiler.create('',20,20,false);
  if hash1.find1(name,pointer(obj),mrew1)
    then
     begin
     VR :=PScwVarRecord(obj);
      If VR^.T > rtVariant Then // <= rtVariant is reserved for variants
        Result :=nil // Bad choice This Name dont represent a Variant
      Else Begin
        vf.loadfromstring(VR^.S);
      result:=vf;
      End;
      mrew1.ExitReadLock;
      Exit; // Done - Name was found and prosessed
    End;
mrew1.ExitReadLock;
  Result :=nil; // Name is NOT found

Except
Result :=nil;
mrew1.ExitReadLock;
End;
End;
When Name is not found, you return nil and the instantiated vf is going out of scope. That is a memory leak.

aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #7 on: October 20, 2013, 08:00:47 pm »

ludob wrote:
>There is alot going on outside the try >except and even inside the except that >can cause a new exception and that >results in critsec.leave never being >called. None of that is caught.
>In TParallelVarFiler.DeletedItems and >TParallelVarFiler.Delete you do the >critsec.leave just before the except >meaning that in a case of an exception >you never leave the critsec. These are >basic programming skills.

I haave corrected this  before you have mention it, you can download the new version from my website.

Ludob wrote:
>function TParallelVarFiler.GetRow(Name : >String) : TParallelVarFiler;
>You create >vf:=TParallelVarFiler.create('',20,20,false) >and if you can't find name, you don't free >it. Nice memory leak.

And i responded:

>when you pass an empty string name , >it's an in-memory TParallelVarfiler, there >is no bug.

And ludob reponded:

>Ah, and in memory TParallelVarfiler >doesn't have to be freed


The in-memory TParallelVarFiler is returned to the user
and it's the reponsablity of the user to free it, see how i am doing it inside the test.pas demo inside the zipfile.

ludob wrote:
> In function TParallelVarFiler.GetRow
>When Name is not found, you return nil >and the instantiated vf is going out of >scope. That is a memory leak.

I will correct this.

And about SaveToStream
>procedure >TParallelVarFiler.SaveToStream(Stream : TStream);
>You get a list of all objects from the >hashtable and write them to a >filestream. What happens if  objects >get deleted or changed in another >thread in the mean time? Right, you got it.
Other than than


SaveToStream is threadsafe cause hash1.getlist(list) is threadsafe , you can use
it saftly from mutiple threads.


Thank you,
Amine Moulay Ramdane.


aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #8 on: October 20, 2013, 08:09:55 pm »

Hello all,


ParallelVarFiler was updated to version 1.20,
i have corrected some bugs and i think it's more stable
now.

You can download ParallelVarFiler from:

http://pages.videotron.com/aminer/



Thank you,
Amine Moulay Ramdane.


aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #9 on: October 20, 2013, 08:12:47 pm »

Hello,


Thank you for your feedback Ludob, i have corrected the GetRow() memory leak etc. it's this way that we will make ParallelVarFiler more stable.


Thank you,
Amine Moulay Ramdane.


aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #10 on: October 20, 2013, 08:15:58 pm »
Hello,

As i have told you the SaveToStream() and SaveToString()
are threadsafe cause i am using hash1.getlist(list) that is threadsafe inside
SaveToStream(), so you can use those methods them safetly from mutiple threads.

You can download ParallelVarFiler from:

http://pages.videotron.com/aminer/



Thank you,
Amine Moulay Ramdane.

aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #11 on: October 20, 2013, 08:34:00 pm »

Hello,

Ludob have talked about  the following
TScwVarFiler v.1 program:

http://www.torry.net/quicksearchd.php?String=varfiler&Title=Yes

this program is not as powerful as my ParallelVarFiler , cause my
ParallelVarFiler is using a Parallel HashTable but TScwVarFiler is using a TList, other than that my ParalleVarFiler
saves automaticly your datas to a file etc. so it's more powerful. Hope you will enjoy my ParallelVarFiler, and of course i have not forgot to add the name of
Peter Johansson near my name in the authors list.

You can download the new version 1.20 of ParallelVarFiler from:


http://pages.videotron.com/aminer/


Thank you,
Amine Moulay Ramdane.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: ParalellVarFiler version 1.17
« Reply #12 on: October 21, 2013, 09:38:16 am »
As i have told you the SaveToStream() and SaveToString()
are threadsafe cause i am using hash1.getlist(list) that is threadsafe inside
SaveToStream(), so you can use those methods them safetly from mutiple threads.
You have to be smart to understand.

In TParallelVarFiler.SaveToStream you use hash1.getlist(list); to get the list of objects. That part is not the problem. What happens later is the problem. You loop over the list and do a
Code: [Select]
VR :=PScwVarRecord(List.Objects[I]);What happens if another thread deletes an object in the mean time? Yes, you are using an object that has been disposed of and anything can happen. Do you call that threadsafe?

this program is not as powerful as my ParallelVarFiler , cause my
ParallelVarFiler is using a Parallel HashTable but TScwVarFiler is using a TList, other than that my ParalleVarFiler
saves automaticly your datas to a file etc. so it's more powerful.
The automatic file saving is really a bad idea. You throw your Parallel HashTable in to speed up the program and then write everything you do to a file. That is putting a rocket engine on your boat and throwing the anchor out in the same time.
and of course i have not forgot to add the name of
Peter Johansson near my name in the authors list.
You only put somebodies name next to yours in the author list when all authors have colaborated on the result. In your case you have to credit Peter Johansson as being the author of TScwVarFiler which is the basis of your errorprone code, full stop. Here you suggest he has collaborated on ParallelVarFiler which is probably not the case. BTW the licence for TScwVarFiler mentions
Quote

***********************************************************
                     IMPORTANT NOTE:
 This software is provided 'as-is', without any express or
 implied warranty. In no event will the author be held
 liable for any damages arising from the use of this
 software.
 Permission is granted to anyone to use this software for
 any purpose, including commercial applications, and to
 alter it and redistribute it freely, subject to the
 following restrictions:
 1. The origin of this software must not be misrepresented,
    you must not claim that you wrote the original software.
    If you use this software in a product, an acknowledgment
    in the product documentation would be appreciated but is
    not required.
 2. Altered source versions must be plainly marked as such,
    and must not be misrepresented as being the original
    software.
 3. This notice may not be removed or altered from any
    source distribution.
***********************************************************
You are just violating all the licence terms of TScwVarFiler. Misrepresentation, altered source not marked as such and removing of the licence notice. Well done. Only 3 restrictions, all 3 violated.

@Moderators when are going to stop this guy spamming the forum? Error-ridden  code, violating licence terms of software, lacking any form of netiquette and ignoring any request to walk inside the lines. Are you waiting for any of the original authors to attack you?

aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #13 on: October 21, 2013, 02:57:04 pm »

Ludob wrote:
>You have to be smart to understand.

>In TParallelVarFiler.SaveToStream you use >hash1.getlist(list); to get the list of >objects. That part is not the problem. >What happens later is the problem. You >loop over the list and do a


So you have to stop your threads first and call SaveToStream() and after that start them again, or use this method in Single Thread.

>You only put somebodies name next to >yours in the author list when all >authors have colaborated on the >result. In your case you have to credit >Peter Johansson as being the author of >TScwVarFiler which is the basis of your >errorprone code, full stop. Here you >suggest he has collaborated on >ParallelVarFiler which is probably not >the case. BTW the licence for >TScwVarFiler mentions



Thank you for the reminder, i have put the scwvafil.txt inside the zipfile with a
notice that ParallelVarFiler was derived from TScwVarFiler and enhanced, and that's enough i think, so this was solved.


Thank you,
Amine Moulay Ramdane.



aminer

  • Hero Member
  • *****
  • Posts: 956
Re: ParalellVarFiler version 1.17
« Reply #14 on: October 21, 2013, 03:18:35 pm »

Ludob wrote:
>In TParallelVarFiler.SaveToStream you use >hash1.getlist(list); to get the list of >objects. That part is not the problem. >What happens later is the problem. You >loop over the list and do a

I have solved this by using a critical section, but you have have to pass a
file name to the constructor before using
SaveToStream() or SaveToString()...


You can download the new ParallelVarFiler version 1.21 from:

http://pages.videotron.com/aminer/


Thank you,
Amine Moulay Ramdane.

 

TinyPortal © 2005-2018