internal KVSequencePortion(DataNode dn, object[] p) : this(dn, (long)p[0], (long)p[1], (long)p[2], (long)p[3], (long)p[4], PType.FromPObject(p[5])) { }
public static void Main8() { Random rnd = new Random(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); Console.WriteLine("Start demo key-value DataNode + SequencePortion"); DataNode dn = new DataNode(dbpath); PType tp_person = new PTypeRecord( new NamedType("name", new PType(PTypeEnumeration.sstring)), new NamedType("age", new PType(PTypeEnumeration.real))); //PType tp_configuration = // new PTypeSequence(new PTypeRecord( // new NamedType("tab_name", new PType(PTypeEnumeration.sstring)), // new NamedType("key_type", PType.TType), // new NamedType("value_type", PType.TType), // new NamedType("key_grades", new PTypeSequence(new PTypeRecord( // new NamedType("portion_resource", new PType(PTypeEnumeration.integer)) // ))) // )); if (dn.NPortions == 0) { object commondata = new object[] { // конфигуратор new object[] { // Первая таблица new object[] { "persons", new PType(PTypeEnumeration.integer).ToPObject(1), tp_person.ToPObject(3), Enumerable.Repeat <object[]>(new object[1], 16).ToArray() } } }; dn.ConfigNode(commondata); } dn.fob.DeactivateCache(); //KVSequencePortion portion = dn.Portion(0); int nelements = 1000000; bool toload = true; // Загружать или нет новую базу данных if (toload) { dn.fob.DeactivateCache(); for (int i = 0; i < dn.NPortions; i++) { dn.Portion(i).Clear(); } bool tododynamicindex = false; sw.Restart(); // Для загрузки нам понадобятся: поток данных, массив ключей и массив офсетов (это всего лишь демонстрация!) IEnumerable <object[]> flow = Enumerable.Range(0, nelements) .Select(iv => { int id = nelements - iv; string name = "=" + id.ToString() + "="; double age = rnd.NextDouble() * 100.0; return(new object[] { id, new object[] { name, age } }); }); long cnt = 1; foreach (object[] pair in flow) { //int ke = (int)pair[0]; //long offset = dn.Portion(ke % 4).AppendPair(pair, tododynamicindex); dn.Append(0, pair, tododynamicindex); //if (cnt % 100000 == 0) Console.Write($"{cnt} "); cnt++; } //Console.WriteLine(); for (int i = 0; i < dn.NPortions; i++) { dn.Portion(i).Flush(); } sw.Stop(); if (tododynamicindex) { Console.WriteLine($"CalculateStaticIndex {sw.ElapsedMilliseconds}"); } else { Console.WriteLine($"load {sw.ElapsedMilliseconds}"); sw.Restart(); for (int i = 0; i < dn.NPortions; i++) { dn.Portion(i).CalculateStaticIndex(); } sw.Stop(); Console.WriteLine($"CalculateStaticIndex {sw.ElapsedMilliseconds}"); } dn.Flush(); } else { Console.WriteLine($"NOload {sw.ElapsedMilliseconds}"); } sw.Restart(); for (int i = 0; i < dn.NPortions; i++) { dn.Portion(i).Activate(); } sw.Stop(); Console.WriteLine($"activate array {sw.ElapsedMilliseconds}"); sw.Restart(); //dn.fob.ActivateCache(); //dn.fob.LoadCache(); sw.Stop(); Console.WriteLine($"load cache {sw.ElapsedMilliseconds}"); int key = nelements * 2 / 3; object[] testvalue = (object[])dn.Get(0, key); //(object[])dn.Portion(key % 4).Get(key); if (testvalue == null) { Console.WriteLine($"NULL searching {key}"); } else { Console.WriteLine($"{key} {testvalue[0]} {testvalue[1]}"); } int nte = 10000; sw.Restart(); for (int i = 0; i < nte; i++) { int k = rnd.Next(nelements) + 1; object[] val = (object[])dn.Get(0, k); //(object[])dn.Portion(key % 4).Get(k); if (val == null) { Console.WriteLine($"Found NULL key={k}"); } //object[] val = (object[])dn.Portion(k % 4).Get(k); } sw.Stop(); Console.WriteLine("get requests {0} for {1}", sw.ElapsedMilliseconds, nte); }