private static long ReadInternal(IEnumerable <uint> ids, PerfTracker perfTracker, SQLiteConnection connection) { var buffer = new byte[4096]; using (var tx = connection.BeginTransaction()) { long v = 0; var sw = Stopwatch.StartNew(); foreach (var id in ids) { using (var command = new SQLiteCommand("SELECT Value FROM Items WHERE ID = " + id, connection)) using (var reader = command.ExecuteReader()) { while (reader.Read()) { long bytesRead; long fieldOffset = 0; while ((bytesRead = reader.GetBytes(0, fieldOffset, buffer, 0, buffer.Length)) > 0) { fieldOffset += bytesRead; v += bytesRead; } } } } perfTracker.Record(sw.ElapsedMilliseconds); return(v); } }
private long ReadInternal(IEnumerable <uint> ids, PerfTracker perfTracker, Instance instance) { Table table; JET_COLUMNID primaryColumnId; JET_COLUMNID secondaryColumnId; using (var session = OpenSession(instance, out table, out primaryColumnId, out secondaryColumnId)) { var sw = Stopwatch.StartNew(); Api.JetSetCurrentIndex(session, table, "by_key"); long v = 0; foreach (var id in ids) { Api.MoveBeforeFirst(session, table); Api.MakeKey(session, table, id, MakeKeyGrbit.NewKey); Api.JetSeek(session, table, SeekGrbit.SeekEQ); var value = Api.RetrieveColumn(session, table, secondaryColumnId); v += value.Length; Debug.Assert(value != null); } perfTracker.Record(sw.ElapsedMilliseconds); return(v); } }
private List <PerformanceRecord> WriteInternal( string operation, IEnumerator <TestData> enumerator, long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, Instance instance) { byte[] valueToWrite = null; var records = new List <PerformanceRecord>(); var sw = new Stopwatch(); Table table; JET_COLUMNID primaryColumnId; JET_COLUMNID secondaryColumnId; using (var session = OpenSession(instance, out table, out primaryColumnId, out secondaryColumnId)) { for (var transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); long v = 0; using (var tx = new Transaction(session)) { for (var i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); var testData = enumerator.Current; valueToWrite = GetValueToWrite(valueToWrite, testData.ValueSize); v += valueToWrite.Length; Api.JetPrepareUpdate(session, table, JET_prep.Insert); Api.SetColumn(session, table, primaryColumnId, testData.Id); Api.SetColumn(session, table, secondaryColumnId, valueToWrite); Api.JetUpdate(session, table); } tx.Commit(CommitTransactionGrbit.None); } sw.Stop(); perfTracker.Record(sw.ElapsedMilliseconds); records.Add( new PerformanceRecord { Bytes = v, Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction, }); } sw.Stop(); } return(records); }
private List <PerformanceRecord> WriteInternal( string operation, IEnumerator <TestData> enumerator, long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, rndseq Rflag, LightningEnvironment env, LightningDatabase db) { byte[] valueToWrite = null; var records = new List <PerformanceRecord>(); var sw = new Stopwatch(); LightningDB.PutOptions putflags = LightningDB.PutOptions.None; if (Rflag == rndseq.SEQ) { putflags = LightningDB.PutOptions.AppendData; } for (var transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); using (var tx = env.BeginTransaction()) { for (var i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); tx.Put(db, Encoding.UTF8.GetBytes(enumerator.Current.Id.ToString("0000000000000000")), valueToWrite, putflags); } tx.Commit(); } sw.Stop(); perfTracker.Record(sw.ElapsedMilliseconds); records.Add(new PerformanceRecord { Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction }); } sw.Stop(); return(records); }
private List <PerformanceRecord> WriteInternal(string operation, IEnumerator <TestData> enumerator, long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker) { var sw = new Stopwatch(); byte[] valueToWrite = null; var records = new List <PerformanceRecord>(); using (var connection = new SqlConnection(connectionString)) { connection.Open(); sw.Restart(); for (var transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); using (var tx = connection.BeginTransaction()) { for (var i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); using (var command = new SqlCommand("INSERT INTO Items (Id, Value) VALUES (@id, @value)", connection)) { command.Transaction = tx; command.Parameters.Add("@id", SqlDbType.Int, 4).Value = enumerator.Current.Id; command.Parameters.Add("@value", SqlDbType.Binary, valueToWrite.Length).Value = valueToWrite; var affectedRows = command.ExecuteNonQuery(); Debug.Assert(affectedRows == 1); } } tx.Commit(); perfTracker.Record(sw.ElapsedMilliseconds); } sw.Stop(); records.Add(new PerformanceRecord { Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction }); } sw.Stop(); } return(records); }
private async Task <List <PerformanceRecord> > WriteInternalAsync(string operation, IEnumerator <TestData> enumerator, long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, FdbDatabase db) { var sw = new Stopwatch(); byte[] valueToWrite = null; var records = new List <PerformanceRecord>(); var location = db.GlobalSpace; sw.Restart(); for (int transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); using (IFdbTransaction tx = db.BeginTransaction()) { for (int i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); tx.Set(location.Pack(enumerator.Current.Id), Slice.Create(valueToWrite)); } await tx.CommitAsync(); perfTracker.Record(sw.ElapsedMilliseconds); } sw.Stop(); records.Add(new PerformanceRecord { Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction }); } sw.Stop(); return(records); }
private List <PerformanceRecord> WriteInternalBatch( string operation, IEnumerator <TestData> enumerator, long itemsPerBatch, long numberOfBatches, PerfTracker perfTracker, StorageEnvironment env) { var sw = new Stopwatch(); byte[] valueToWrite = null; var records = new List <PerformanceRecord>(); for (var b = 0; b < numberOfBatches; b++) { sw.Restart(); long v = 0; using (var batch = new WriteBatch()) { for (var i = 0; i < itemsPerBatch; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); v += valueToWrite.Length; batch.Add(enumerator.Current.Id.ToString("0000000000000000"), new MemoryStream(valueToWrite), "Root"); } env.Writer.Write(batch); } sw.Stop(); perfTracker.Record(sw.ElapsedMilliseconds); records.Add(new PerformanceRecord { Bytes = v, Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerBatch }); } return(records); }
private List <PerformanceRecord> WriteInternal( string operation, int itemsPerTransaction, int numberOfTransactions, PerfTracker perfTracker, StorageEnvironment env, IEnumerator <TestData> enumerator) { var sw = new Stopwatch(); byte[] valueToWrite = null; var records = new List <PerformanceRecord>(); for (var transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); using (var tx = env.NewTransaction(TransactionFlags.ReadWrite)) { for (var i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); tx.State.Root.Add(enumerator.Current.Id.ToString("0000000000000000"), new MemoryStream(valueToWrite)); } tx.Commit(); perfTracker.Record(sw.ElapsedMilliseconds); } sw.Stop(); records.Add(new PerformanceRecord { Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction }); } return(records); }
private static async Task <long> ReadInternalAsync(IEnumerable <uint> ids, PerfTracker perfTracker, FdbDatabase db) { const int BATCH_SIZE = 1000; var list = new List <int>(BATCH_SIZE); var location = db.GlobalSpace; Stopwatch sw = Stopwatch.StartNew(); long v = 0; foreach (int id in ids) { list.Add(id); if (list.Count >= BATCH_SIZE) { using (var tx = db.BeginReadOnlyTransaction()) { var slices = await tx.GetValuesAsync(location.PackRange(list)); v += slices.Sum(x => x.Count); } list.Clear(); } } if (list.Count > 0) { using (var tx = db.BeginReadOnlyTransaction()) { var slices = await tx.GetValuesAsync(location.PackRange(list)); v += slices.Sum(x => x.Count); } } perfTracker.Record(sw.ElapsedMilliseconds); return(v); }
private static long ReadInternal(IEnumerable <uint> ids, PerfTracker perfTracker, StorageEnvironment env) { var ms = new byte[4096]; using (var tx = env.NewTransaction(TransactionFlags.Read)) { var sw = Stopwatch.StartNew(); long v = 0; foreach (var id in ids) { var key = id.ToString("0000000000000000"); var readResult = tx.State.Root.Read(key); int reads = 0; while ((reads = readResult.Reader.Read(ms, 0, ms.Length)) > 0) { v += reads; } } perfTracker.Record(sw.ElapsedMilliseconds); return(v); } }
private static long ReadInternal(IEnumerable<uint> ids, PerfTracker perfTracker, StorageEnvironment env) { var ms = new byte[4096]; using (var tx = env.NewTransaction(TransactionFlags.Read)) { var sw = Stopwatch.StartNew(); long v = 0; foreach (var id in ids) { var key = id.ToString("0000000000000000"); var readResult = tx.State.Root.Read(tx, key); int reads = 0; while ((reads = readResult.Reader.Read(ms, 0, ms.Length)) > 0) { v += reads; } } perfTracker.Record(sw.ElapsedMilliseconds); return v; } }
private List<PerformanceRecord> WriteInternal( string operation, int itemsPerTransaction, int numberOfTransactions, PerfTracker perfTracker, StorageEnvironment env, IEnumerator<TestData> enumerator) { var sw = new Stopwatch(); byte[] valueToWrite = null; var records = new List<PerformanceRecord>(); for (var transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); using (var tx = env.NewTransaction(TransactionFlags.ReadWrite)) { for (var i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); tx.State.Root.Add(tx, enumerator.Current.Id.ToString("0000000000000000"), new MemoryStream(valueToWrite)); } tx.Commit(); perfTracker.Record(sw.ElapsedMilliseconds); } sw.Stop(); records.Add(new PerformanceRecord { Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction }); } return records; }
private List<PerformanceRecord> WriteInternalBatch( string operation, IEnumerator<TestData> enumerator, long itemsPerBatch, long numberOfBatches, PerfTracker perfTracker, StorageEnvironment env) { var sw = new Stopwatch(); byte[] valueToWrite = null; var records = new List<PerformanceRecord>(); for (var b = 0; b < numberOfBatches; b++) { sw.Restart(); long v = 0; using (var batch = new WriteBatch()) { for (var i = 0; i < itemsPerBatch; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); v += valueToWrite.Length; batch.Add(enumerator.Current.Id.ToString("0000000000000000"), new MemoryStream(valueToWrite), "Root"); } env.Writer.Write(batch); } sw.Stop(); perfTracker.Record(sw.ElapsedMilliseconds); records.Add(new PerformanceRecord { Bytes = v, Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerBatch }); } return records; }
private static async Task<long> ReadInternalAsync(IEnumerable<uint> ids, PerfTracker perfTracker, FdbDatabase db) { const int BATCH_SIZE = 1000; var list = new List<int>(BATCH_SIZE); var location = db.GlobalSpace; Stopwatch sw = Stopwatch.StartNew(); long v = 0; foreach (int id in ids) { list.Add(id); if (list.Count >= BATCH_SIZE) { using (var tx = db.BeginReadOnlyTransaction()) { var slices = await tx.GetValuesAsync(location.PackRange(list)); v += slices.Sum(x=>x.Count); } list.Clear(); } } if (list.Count > 0) { using (var tx = db.BeginReadOnlyTransaction()) { var slices = await tx.GetValuesAsync(location.PackRange(list)); v += slices.Sum(x => x.Count); } } perfTracker.Record(sw.ElapsedMilliseconds); return v; }
private async Task<List<PerformanceRecord>> WriteInternalAsync(string operation, IEnumerator<TestData> enumerator, long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, FdbDatabase db) { var sw = new Stopwatch(); byte[] valueToWrite = null; var records = new List<PerformanceRecord>(); var location = db.GlobalSpace; sw.Restart(); for (int transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); using (IFdbTransaction tx = db.BeginTransaction()) { for (int i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); tx.Set(location.Pack(enumerator.Current.Id), Slice.Create(valueToWrite)); } await tx.CommitAsync(); perfTracker.Record(sw.ElapsedMilliseconds); } sw.Stop(); records.Add(new PerformanceRecord { Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction }); } sw.Stop(); return records; }
private List<PerformanceRecord> WriteInternal( string operation, IEnumerator<TestData> enumerator, long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, Instance instance) { byte[] valueToWrite = null; var records = new List<PerformanceRecord>(); var sw = new Stopwatch(); Table table; JET_COLUMNID primaryColumnId; JET_COLUMNID secondaryColumnId; using (var session = OpenSession(instance, out table, out primaryColumnId, out secondaryColumnId)) { for (var transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); long v = 0; using (var tx = new Transaction(session)) { for (var i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); var testData = enumerator.Current; valueToWrite = GetValueToWrite(valueToWrite, testData.ValueSize); v += valueToWrite.Length; Api.JetPrepareUpdate(session, table, JET_prep.Insert); Api.SetColumn(session, table, primaryColumnId, testData.Id); Api.SetColumn(session, table, secondaryColumnId, valueToWrite); Api.JetUpdate(session, table); } tx.Commit(CommitTransactionGrbit.None); } sw.Stop(); perfTracker.Record(sw.ElapsedMilliseconds); records.Add( new PerformanceRecord { Bytes = v, Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction, }); } sw.Stop(); } return records; }
private List<PerformanceRecord> WriteInternal( string operation, IEnumerator<TestData> enumerator, long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, rndseq Rflag, LightningEnvironment env, LightningDatabase db) { byte[] valueToWrite = null; var records = new List<PerformanceRecord>(); var sw = new Stopwatch(); LightningDB.PutOptions putflags = LightningDB.PutOptions.None; if (Rflag == rndseq.SEQ) putflags = LightningDB.PutOptions.AppendData; for (var transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); using (var tx = env.BeginTransaction()) { for (var i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); tx.Put(db, Encoding.UTF8.GetBytes(enumerator.Current.Id.ToString("0000000000000000")), valueToWrite, putflags); } tx.Commit(); } sw.Stop(); perfTracker.Record(sw.ElapsedMilliseconds); records.Add(new PerformanceRecord { Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction }); } sw.Stop(); return records; }
private long ReadInternal(IEnumerable<uint> ids, PerfTracker perfTracker, Instance instance) { Table table; JET_COLUMNID primaryColumnId; JET_COLUMNID secondaryColumnId; using (var session = OpenSession(instance, out table, out primaryColumnId, out secondaryColumnId)) { var sw = Stopwatch.StartNew(); Api.JetSetCurrentIndex(session, table, "by_key"); long v = 0; foreach (var id in ids) { Api.MoveBeforeFirst(session, table); Api.MakeKey(session, table, id, MakeKeyGrbit.NewKey); Api.JetSeek(session, table, SeekGrbit.SeekEQ); var value = Api.RetrieveColumn(session, table, secondaryColumnId); v += value.Length; Debug.Assert(value != null); } perfTracker.Record(sw.ElapsedMilliseconds); return v; } }
private List<PerformanceRecord> WriteInternal(string operation, IEnumerator<TestData> enumerator, long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker) { var sw = new Stopwatch(); byte[] valueToWrite = null; var records = new List<PerformanceRecord>(); using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); sw.Restart(); for (var transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); using (var tx = connection.BeginTransaction()) { for (var i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); using (var command = new SQLiteCommand("INSERT INTO Items (Id, Value) VALUES (@id, @value)", connection)) { command.Parameters.Add("@id", DbType.Int32, 4).Value = enumerator.Current.Id; command.Parameters.Add("@value", DbType.Binary, valueToWrite.Length).Value = valueToWrite; var affectedRows = command.ExecuteNonQuery(); Debug.Assert(affectedRows == 1); } } tx.Commit(); } sw.Stop(); perfTracker.Record(sw.ElapsedMilliseconds); records.Add(new PerformanceRecord { Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction }); } sw.Stop(); } return records; }
private static long ReadInternal(IEnumerable<uint> ids, PerfTracker perfTracker, SQLiteConnection connection) { var buffer = new byte[4096]; using (var tx = connection.BeginTransaction()) { long v = 0; var sw = Stopwatch.StartNew(); foreach (var id in ids) { using (var command = new SQLiteCommand("SELECT Value FROM Items WHERE ID = " + id, connection)) using (var reader = command.ExecuteReader()) { while (reader.Read()) { long bytesRead; long fieldOffset = 0; while ((bytesRead = reader.GetBytes(0, fieldOffset, buffer, 0, buffer.Length)) > 0) { fieldOffset += bytesRead; v += bytesRead; } } } } perfTracker.Record(sw.ElapsedMilliseconds); return v; } }