コード例 #1
0
        private static async Task BenchMergeSortAsync(IFdbDatabase db, int N, int K, int B, CancellationToken ct)
        {
            Console.WriteLine($"=== BenchMergeSort(N={N:N0}, K={K:N0}, B={B:N0}) ===");

            // create multiple lists
            var location = db.GlobalSpace.Partition.ByKey("MergeSort");
            await db.ClearRangeAsync(location, ct);

            var sources = Enumerable.Range(0, K).Select(i => 'A' + i).ToArray();
            var rnd     = new Random();

            // insert a number of random number lists
            Console.Write($"> Inserting {(K * N):N0} items... ");
            foreach (var source in sources)
            {
                using (var tr = db.BeginTransaction(ct))
                {
                    var list = location.Partition.ByKey(source);
                    for (int i = 0; i < N; i++)
                    {
                        tr.Set(list.Keys.Encode(rnd.Next()), Slice.FromInt32(i));
                    }
                    await tr.CommitAsync();
                }
            }
            Console.WriteLine("Done");

            // merge/sort them to get only one (hopefully sorted) list

            using (var tr = db.BeginTransaction(ct))
            {
                var mergesort = tr
                                .MergeSort(
                    sources.Select(source => KeySelectorPair.StartsWith(location.Keys.Encode(source))),
                    (kvp) => location.Keys.DecodeLast <int>(kvp.Key)
                    )
                                .Take(B)
                                .Select(kvp => location.Keys.Unpack(kvp.Key));

                Console.Write($"> MergeSort with limit {B:N0}... ");
                var sw      = Stopwatch.StartNew();
                var results = await mergesort.ToListAsync();

                sw.Stop();
                Console.WriteLine("Done");

                Console.WriteLine($"Took {FormatTimeMilli(sw.Elapsed.TotalMilliseconds)} to merge sort {results.Count:N0} results from {K} lists of {N} items each");

                //foreach (var result in results)
                //{
                //	Console.WriteLine(result.Get<int>(-1));
                //}
            }
            Console.WriteLine();
        }
コード例 #2
0
        private static async Task BenchMergeSortAsync(IFdbDatabase db, int N, int K, int B, CancellationToken ct)
        {
            // create multiple lists
            var location = db.Partition("MergeSort");
            await db.ClearRangeAsync(location, ct);

            var sources = Enumerable.Range(0, K).Select(i => 'A' + i).ToArray();
            var rnd     = new Random();

            // insert a number of random number lists
            Console.Write("> Inserting " + (K * N).ToString("N0", CultureInfo.InvariantCulture) + " items... ");
            foreach (var source in sources)
            {
                using (var tr = db.BeginTransaction(ct))
                {
                    var list = location.Partition(source);
                    for (int i = 0; i < N; i++)
                    {
                        tr.Set(list.Pack(rnd.Next()), Slice.FromInt32(i));
                    }
                    await tr.CommitAsync();
                }
            }
            Console.WriteLine("Done");

            // merge/sort them to get only one (hopefully sorted) list

            using (var tr = db.BeginTransaction(ct))
            {
                var mergesort = tr
                                .MergeSort(
                    sources.Select(source => FdbKeySelectorPair.StartsWith(location.Pack(source))),
                    (kvp) => location.UnpackLast <int>(kvp.Key)
                    )
                                .Take(B)
                                .Select(kvp => location.Unpack(kvp.Key));

                Console.Write("> MergeSort with limit " + B + "... ");
                var sw      = Stopwatch.StartNew();
                var results = await mergesort.ToListAsync();

                sw.Stop();
                Console.WriteLine("Done");

                Console.WriteLine("Took " + FormatTimeMilli(sw.Elapsed.TotalMilliseconds) + " to merge sort " + results.Count + " results from " + K + " lists of " + N + " items each");

                //foreach (var result in results)
                //{
                //	Console.WriteLine(result.Get<int>(-1));
                //}
            }
        }
コード例 #3
0
        /// <summary>
        /// Setup the initial state of the database
        /// </summary>
        public async Task Init(IFdbDatabase db, CancellationToken ct)
        {
            // open the folder where we will store everything
            this.Subspace = await db.Directory.CreateOrOpenAsync(new [] { "Benchmarks", "LeakTest" }, cancellationToken : ct);

            // clear all previous values
            await db.ClearRangeAsync(this.Subspace, ct);

            // insert all the classes
            await db.WriteAsync((tr) =>
            {
                tr.Set(this.Subspace.Key + FdbKey.MinValue, Slice.FromString("BEGIN"));
                tr.Set(this.Subspace.Key + FdbKey.MaxValue, Slice.FromString("END"));
            }, ct);
        }
コード例 #4
0
		/// <summary>
		/// Setup the initial state of the database
		/// </summary>
		public async Task Init(IFdbDatabase db, CancellationToken ct)
		{
			// open the folder where we will store everything
			this.Subspace = await db.Directory.CreateOrOpenAsync(new [] { "Benchmarks", "LeakTest" }, cancellationToken: ct);

			// clear all previous values
			await db.ClearRangeAsync(this.Subspace, ct);

			// insert all the classes
			await db.WriteAsync((tr) =>
			{
				tr.Set(this.Subspace.Concat(FdbKey.MinValue), Slice.FromString("BEGIN"));
				tr.Set(this.Subspace.Concat(FdbKey.MaxValue), Slice.FromString("END"));
			}, ct);
		}
コード例 #5
0
        /// <summary>
        /// Setup the initial state of the database
        /// </summary>
        public async Task Init(IFdbDatabase db, CancellationToken ct)
        {
            // open the folder where we will store everything
            this.Subspace = await db.Directory.CreateOrOpenAsync(new [] { "Tutorials", "ClassScheduling" }, ct : ct);

            // clear all previous values
            await db.ClearRangeAsync(this.Subspace, ct);

            // insert all the classes
            await db.WriteAsync((tr) =>
            {
                foreach (var c in this.ClassNames)
                {
                    tr.Set(ClassKey(c), Slice.FromStringAscii("100"));
                }
            }, ct);
        }
コード例 #6
0
        /// <summary>
        /// Setup the initial state of the database
        /// </summary>
        public async Task Init(IFdbDatabase db, CancellationToken ct)
        {
            this.Subspace = await db.ReadWriteAsync(async tr =>
            {
                // open the folder where we will store everything
                var subspace = await db.Root["Benchmarks"]["LeakTest"].CreateOrOpenAsync(tr);

                // clear all previous values
                await db.ClearRangeAsync(subspace, ct);

                // insert all the classes
                tr.Set(subspace.GetPrefix() + FdbKey.MinValue, Slice.FromString("BEGIN"));
                tr.Set(subspace.GetPrefix() + FdbKey.MaxValue, Slice.FromString("END"));

                return(subspace);
            }, ct);
        }
コード例 #7
0
		/// <summary>
		/// Setup the initial state of the database
		/// </summary>
		public async Task Init(IFdbDatabase db, CancellationToken ct)
		{
			// open the folder where we will store everything
			this.Subspace = await db.Directory.CreateOrOpenAsync(new [] { "Tutorials", "ClassScheduling" }, cancellationToken: ct);

			// clear all previous values
			await db.ClearRangeAsync(this.Subspace, ct);
			// insert all the classes
			await db.WriteAsync((tr) =>
			{
				foreach (var c in this.ClassNames)
				{
					tr.Set(ClassKey(c), Slice.FromAscii("100"));
				}
			}, ct);


		}
コード例 #8
0
		public async Task RunClear(IFdbDatabase db, CancellationToken ct)
		{
			// clear everything
			await db.ClearRangeAsync(this.WorkerPool.Subspace, ct);
		}
コード例 #9
0
		private static async Task BenchMergeSortAsync(IFdbDatabase db, int N, int K, int B, CancellationToken ct)
		{
			// create multiple lists
			var location = db.Partition.ByKey("MergeSort");
			await db.ClearRangeAsync(location, ct);

			var sources = Enumerable.Range(0, K).Select(i => 'A' + i).ToArray();
			var rnd = new Random();

			// insert a number of random number lists
			Console.Write("> Inserting " + (K * N).ToString("N0", CultureInfo.InvariantCulture) + " items... ");
			foreach (var source in sources)
			{
				using (var tr = db.BeginTransaction(ct))
				{
					var list = location.Partition.ByKey(source);
					for (int i = 0; i < N; i++)
					{
						tr.Set(list.Keys.Encode(rnd.Next()), Slice.FromInt32(i));
					}
					await tr.CommitAsync();
				}
			}
			Console.WriteLine("Done");

			// merge/sort them to get only one (hopefully sorted) list

			using (var tr = db.BeginTransaction(ct))
			{
				var mergesort = tr
					.MergeSort(
						sources.Select(source => FdbKeySelectorPair.StartsWith(location.Keys.Encode(source))),
						(kvp) => location.Keys.DecodeLast<int>(kvp.Key)
					)
					.Take(B)
					.Select(kvp => location.Keys.Unpack(kvp.Key));

				Console.Write("> MergeSort with limit " + B + "... ");
				var sw = Stopwatch.StartNew();
				var results = await mergesort.ToListAsync();
				sw.Stop();
				Console.WriteLine("Done");

				Console.WriteLine("Took " + FormatTimeMilli(sw.Elapsed.TotalMilliseconds) + " to merge sort " + results.Count + " results from " + K + " lists of " + N + " items each");

				//foreach (var result in results)
				//{
				//	Console.WriteLine(result.Get<int>(-1));
				//}
			}
		}
コード例 #10
0
 public async Task RunClear(IFdbDatabase db, CancellationToken ct)
 {
     // clear everything
     await db.ClearRangeAsync(this.WorkerPool.Subspace, ct);
 }