private void Run(Action <BenchmarkIteration, ObjectDB <IFlatbufferObject>, IFlatbufferObject> action, int dataIndex, int dataSize) { var data = InputData[dataIndex]; var factories = new List <Func <ByteBuffer, IFlatbufferObject> > { (bb) => Data_8b.GetRootAsData_8b(bb), (bb) => Data_128b.GetRootAsData_128b(bb), (bb) => Data_1KB.GetRootAsData_1KB(bb), (bb) => Data_1MB.GetRootAsData_1MB(bb), }; var nRecords = dataSize; var buffer = 100_000; using (var db = new ObjectDB <IFlatbufferObject>(FileStorageEngineFactory.Create("benchmark", SIZE_15GB, nRecords + buffer), new FlatBufferSerializer(factories))) { // set up data for (int i = 0; i < nRecords; i++) { db.Insert(data); if (i % 10000 == 0 && i > 0) { Console.WriteLine(i); } } // run benchmark foreach (BenchmarkIteration iter in Benchmark.Iterations) { action(iter, db, data); } } }
static void Main(string[] args) { Guid guid; // create a database var pathToDataDir = "db-data"; var fileStorageEngine = FileStorageEngineFactory.Create(pathToDataDir, SIZE_1G, MAX_ENTRIES); using (var db = new ObjectDB <object>(fileStorageEngine, new BinaryFormatterSerializer())) { // create var data = new MyData(1, "hello world"); Console.WriteLine("inserting object: " + data); guid = db.Insert(data); Console.WriteLine("GUID of inserted object={0}", guid); // read data = db.Read <MyData>(guid); Console.WriteLine("read object: {0}", data); // update data.Text = "very interesting text"; Console.WriteLine("updating object: {0}", data); db.Update(guid, data); } // re-open existing databse using (var db = new ObjectDB <object>(FileStorageEngineFactory.Open(pathToDataDir), new BinaryFormatterSerializer())) { // read after re-opening the db var data = db.Read <MyData>(guid); Console.WriteLine("object after re-opening the DB: {0}", data); // delete Console.WriteLine("deleting object"); db.Delete(guid); // RecordNotFoundException after deletion try { db.Read <MyData>(guid); } catch (RecordNotFoundException) { Console.WriteLine("object was deleted"); } } }
private ObjectDB <object> OpenDB(string name) { return(new ObjectDB <object>(FileStorageEngineFactory.Open("dbs/" + name), new BinaryFormatterSerializer())); }
private ObjectDB <object> NewDB(string name) { return(new ObjectDB <object>(FileStorageEngineFactory.Create("dbs/" + name, SIZE_1G, 64), new BinaryFormatterSerializer())); }