Beispiel #1
0
        private static async Task CheckGetKeysSingleThread(string dbFolder)
        {
            using var blockStore = new Core.Storage.Blocks.CachePrototype.ProtoSharded(2_560);
            await using var db   = new TrimDatabase(() => new SkipList32(new NativeAllocator32(4096 * 1024, 25)), blockStore, 5, dbFolder, 0);

            await db.LoadAsync(startWithoutMerges : true);

            var numberOfThreads = Environment.ProcessorCount;
            var seed            = 7722;

            var generator = new KeyValueGenerator(numberOfThreads, seed);

            var key   = new byte[10];
            var value = new byte[100];

            for (var t = 0; t < numberOfThreads; t++)
            {
                for (var i = 0; i < _keysPerThread; i++)
                {
                    //if (i == 7) Debugger.Break();
                    generator.GetKeyValue(key, value, (short)t, i);
                    Console.WriteLine($"Thread Id {t} iteration {i}");
                    await db.GetAsync(key);
                }
            }
        }
Beispiel #2
0
        private static async Task CheckGetKeysSingleThread(string dbFolder)
        {
            var dbOptions = new TrimDatabaseOptions()
            {
                DatabaseFolder = dbFolder, OpenReadOnly = true
            };

            await using var db = new TrimDatabase(dbOptions);
            await db.LoadAsync();

            var numberOfThreads = Environment.ProcessorCount;
            var seed            = 7722;

            var generator = new KeyValueGenerator(numberOfThreads, seed);

            var key   = new byte[10];
            var value = new byte[100];

            for (var t = 0; t < numberOfThreads; t++)
            {
                for (var i = 0; i < _keysPerThread; i++)
                {
                    //if (i == 7) Debugger.Break();
                    generator.GetKeyValue(key, value, (short)t, i);
                    Console.WriteLine($"Thread Id {t} iteration {i}");
                    await db.GetAsync(key);
                }
            }
        }
Beispiel #3
0
        public async Task TestSkipListOverflow()
        {
            var loadedWords = CommonData.Words;
            var folder      = "D:\\Database";

            foreach (var f in System.IO.Directory.GetFiles(folder))
            {
                System.IO.File.Delete(f);
            }

            using var blocks = new MMapBlockCache();
            var dbOptions = new TrimDatabaseOptions()
            {
                DatabaseFolder = folder
            };
            var db = new TrimDatabase(dbOptions);

            await db.LoadAsync();

            foreach (var word in loadedWords)
            {
                var utf8  = Encoding.UTF8.GetBytes(word);
                var value = Encoding.UTF8.GetBytes($"VALUE={word}");
                await db.PutAsync(utf8, value);
            }

            var key           = Encoding.UTF8.GetBytes(loadedWords[0]);
            var expectedValue = Encoding.UTF8.GetBytes($"VALUE={loadedWords[0]}");

            var result = await db.GetAsync(key);

            Assert.Equal(expectedValue.ToArray(), result.ToArray());

            key           = Encoding.UTF8.GetBytes(loadedWords[loadedWords.Length / 2]);
            expectedValue = Encoding.UTF8.GetBytes($"VALUE={loadedWords[loadedWords.Length / 2]}");
            result        = await db.GetAsync(key);

            Assert.Equal(expectedValue.ToArray(), result.ToArray());

            key           = Encoding.UTF8.GetBytes(loadedWords[^ 1]);
Beispiel #4
0
        private static async Task ReadFromDB(short threadId, KeyValueGenerator generator, int numberOfIterations, TrimDatabase trimDB)
        {
            await Task.Yield();

            var keyMemory   = new byte[_keySize];
            var valueMemory = new byte[_valueSize];

            for (var i = 0; i < numberOfIterations; i++)
            {
                generator.GetKeyValue(keyMemory.AsSpan(), valueMemory.AsSpan(), threadId, numberOfIterations);
                var result = await trimDB.GetAsync(keyMemory);

                if (result.IsEmpty)
                {
                    Interlocked.Increment(ref _numberOfMisses);
                }
                //if ((i + 1) % 10 == 0) Console.WriteLine($"Thread {threadId} has read {i + 1} keys");
                //if (threadId == 3 && i > 228) Debugger.Break(); // Console.WriteLine($"ERROR Thread {threadId} has read {i + 1} keys");
            }
        }