private static void ProcessOneDatabase ( [NotNull] string inputFileName ) { using (DirectAccess64 accessor = new DirectAccess64(inputFileName, DirectAccessMode.ReadOnly)) { int maxMfn = accessor.GetMaxMfn(); Console.WriteLine("{0}: Max MFN={1}", inputFileName, maxMfn); for (int mfn = 1; mfn < maxMfn; mfn++) { if (mfn % 100 == 1) { Console.Write(" {0} ", mfn - 1); } try { MarcRecord record = accessor.ReadRecord(mfn); if (!ReferenceEquals(record, null)) { ReaderInfo readerInfo = ReaderInfo.Parse(record); string ticket = readerInfo.Ticket; if (string.IsNullOrEmpty(ticket)) { continue; } DepersonalizedReader depersonalized; if (readers.TryGetValue(ticket, out depersonalized)) { depersonalized.AddVisits(readerInfo.Visits); } else { depersonalized = DepersonalizedReader .FromReaderInfo(readerInfo); readers.Add(ticket, depersonalized); } } } catch (Exception exception) { Console.WriteLine(); Console.WriteLine("MFN {0}: {1}", mfn, exception.Message); } } } Console.WriteLine("Total: {0}", readers.Count); Console.WriteLine("Memory: {0}", Process.GetCurrentProcess().WorkingSet64); }
static void Main(string[] args) { if (args.Length != 1) { return; } try { DirectAccess64 irbis = new DirectAccess64(args[0]); int maxMfn = irbis.GetMaxMfn(); Console.WriteLine("Max MFN={0}", maxMfn); Parallel.For(1, maxMfn, mfn => { if (mfn % 1000 == 1) { Console.Write("."); } try { MarcRecord record = irbis.ReadRecord(mfn); if (!ReferenceEquals(record, null)) { ProcessRecord(record); } } catch { // Do nothing } }); irbis.Dispose(); using (StreamWriter writer = File.CreateText("publishers.txt")) { string[] keys = counter1.Keys.OrderBy(_ => _).ToArray(); foreach (string key in keys) { writer.WriteLine("{0}\t{1}\t{2}", key, counter1[key], counter2[key]); } } } catch (Exception e) { Console.WriteLine(e); } }
static void ReadRecord ( int mfn ) { if (mfn % 5000 == 0) { Console.WriteLine("Read: {0}", mfn); } MarcRecord record = accessor.ReadRecord(mfn); if (ReferenceEquals(record, null)) { return; } // processBlock.Post(record); ProcessRecord(record); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: DirectWriterBenchmark <path-to-MST>"); return; } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string masterPath = args[0]; try { DirectUtility.CreateDatabase64(masterPath); using (DirectAccess64 accessor = new DirectAccess64(masterPath)) { for (int i = 0; i < 10000; i++) { if (i % 1000 == 0) { Console.Write("."); } MarcRecord record = new MarcRecord(); record.BeginUpdate(100); for (int tag = 200; tag < 300; tag++) { record.Fields.Add ( new RecordField ( tag, "Это поле номер " + tag ) ); } record.EndUpdate(); accessor.WriteRecord(record); } Console.WriteLine(); for (int approach = 0; approach < 10; approach++) { Console.WriteLine("Approach {0}", approach + 1); for (int mfn = 1; mfn <= 1000; mfn++) { MarcRecord record = accessor.ReadRecord(mfn) .ThrowIfNull("accessor.ReadRecord(mfn)"); record.Fields.Add ( new RecordField ( 300, "Запись отредактирована " + DateTime.Now ) ); accessor.WriteRecord(record); } } } stopwatch.Stop(); Console.WriteLine ( "Elapsed: {0}", stopwatch.Elapsed ); } catch (Exception exception) { Console.WriteLine(exception); } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: DirectReaderBenchmark <path-to-MST>"); return; } string masterPath = args[0]; try { IrbisEncoding.RelaxUtf8(); Console.WriteLine("Open: {0}", masterPath); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); using (DirectAccess64 reader = new DirectAccess64(masterPath)) { int maxMfn = reader.GetMaxMfn(); Console.WriteLine("Max MFN={0}", maxMfn); Parallel.For ( 1, maxMfn, mfn => { try { MarcRecord record = reader.ReadRecord(mfn); //Console.Write('.'); if (!ReferenceEquals(record, null)) { Debug.Assert(record.Mfn == mfn); } } catch (Exception exception) { Console.WriteLine ( "MFN={0}: exception: {1}", mfn, exception ); } } ); } stopwatch.Stop(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Close: {0}", masterPath); Console.WriteLine ( "Elapsed: {0} sec", stopwatch.Elapsed.ToSecondString() ); } catch (Exception exception) { Console.WriteLine(exception); } }