📜 ⬆️ ⬇️

Perst - High Performance OOBD

Perst - An open source, object-oriented embedded database


McObject high-performance object-oriented embedded database.

Supported Platforms

Main features

License


Dual: either GNU General Public License version 2, or if you are not comfortable with the GNU GPL v2 is commercial.

Speed ​​performance


The official site posted tests from two companies PolePosition and TestIndex. PolePosition compares Perst with db4o, which was mentioned more than once on Habré. The result, as you probably guessed, is Perst faster. The same result is reported to us by TestIndex, which tested on an Android emulator and a T-Mobile G1 smartphone comparing Perst to SQLite. Pdfs with charts can be downloaded from the official site .
')

C # example


Everything is really simple here - all objects (classes) that need to be stored in the Perst database are inherited from the Persistent class . Create a class simple data class:
/// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
  1. /// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
  2. /// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
  3. /// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
  4. /// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
  5. /// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
  6. /// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
  7. /// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
  8. /// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
/// <summary> /// . /// </summary> class MyData : Persistent { public int intKey; public string strData; } * This source code was highlighted with Source Code Highlighter .
Now we need to create a class that will create the indices we need, as well as being the root element of the database.
  1. /// <summary>
  2. /// The root element of the database.
  3. /// </ summary>
  4. class MyRoot: Persistent
  5. {
  6. /// <summary>
  7. /// Index across the intKey field in the MyData class.
  8. /// </ summary>
  9. public FieldIndex < int , MyData> intKeyIndex;
  10. public MyRoot (Storage db)
  11. : base (db)
  12. {
  13. intKeyIndex = db.CreateFieldIndex < int , MyData> ( "intKey" , false ); // False indicates non-unique key.
  14. }
  15. public MyRoot ()
  16. {
  17. }
  18. }
* This source code was highlighted with Source Code Highlighter .
Well, now it remains only to connect to the database and work with it. At the same time we will test the speed.
  1. class program
  2. {
  3. static void Main ( string [] args)
  4. {
  5. DateTime t1;
  6. DateTime t2;
  7. Storage db = StorageFactory.Instance.CreateStorage ();
  8. MyRoot Root;
  9. MyData Obj;
  10. MyData [] ObjList;
  11. // Select Perst 10MB of RAM for working with the database, which would slightly reduce the load on the disk and
  12. // increase speed.
  13. db.Open ( "MyDB.pdb" , 10 * 1024 * 1024, "My_SecreT_k3y" );
  14. // If the database does not have a root element yet, create it.
  15. if (db.Root == null )
  16. {
  17. db.Root = new MyRoot (db);
  18. }
  19. Root = (MyRoot) db.Root;
  20. // Add the MyData object to the database.
  21. t1 = DateTime .Now;
  22. for ( int i = 0; i <100000; i ++)
  23. {
  24. Obj = new MyData ();
  25. Obj.intKey = i;
  26. Obj.strData = "Hello world !!!" ;
  27. Root.intKeyIndex.Put (Obj);
  28. }
  29. t2 = DateTime .Now;
  30. Console .WriteLine ((t2 - t1) .TotalMilliseconds.ToString () + "ms" );
  31. // Now try to get it.
  32. //T.k. we created an index with a non-unique key, then we use the overloaded function Get (from, till).
  33. ObjList = Root.intKeyIndex.Get (1000, 1000);
  34. foreach (MyData Obj1 in ObjList)
  35. {
  36. Console .WriteLine (Obj1.strData);
  37. }
  38. db.Close ();
  39. }
  40. }
* This source code was highlighted with Source Code Highlighter .
On my laptop, the creation of 100,000 objects is performed in 2.4 seconds, i.e. ~ 42k records per second

Conclusion


Perst is really fast and compact OODB, which is suitable not only for your PC application, but also for mobile devices.
But can it be applied on sites you ask? The answer will be as follows: the tutorial claims support for a multi-client application using ThreadTransaction and the database property perst.multiclient.support, but I was not able to achieve high performance (10 threads create 10 records of 21 seconds each). Most likely I do something wrong? In any case, I will post the source code that you were able to correct me and test it yourself.

Links

  1. Official site
  2. Download Page
  3. Sources of examples on VB.NET
  4. Sample C # Sources

Source: https://habr.com/ru/post/89150/


All Articles