示例#1
0
 public LargeValue(long content, int size)
 {
     value = new byte[size];
     for (int i = 0; i < size; i += sizeof(long))
     {
         Array.Copy(LargeValue.longToByte(content), 0, value, i, sizeof(long));
     }
 }
示例#2
0
        public static void Main(string[] args)
        {
            device = new NullDevice();

            store = new FasterKV <Key, LargeValue, Input, LargeOutput, Empty, LargeFunctions>(kMaxKey / 2,
                                                                                              new LargeFunctions(), new LogSettings {
                LogDevice = device, MemorySizeBits = 32
            },
                                                                                              new CheckpointSettings {
                CheckpointDir = null, CheckPointType = CheckpointType.Snapshot
            },
                                                                                              new SerializerSettings <Key, LargeValue> {
                keySerializer = () => new KeySerializer(), valueSerializer = () => new LargeValueSerializer()
            });

            Console.WriteLine("BigObject total: " + kMaxKey + ":" + kPerRoundKey + "*" + kRound + " thread: " + kThread);
            for (long r = 0; r < 1; r++)
            {
                Stopwatch      stopwatch = new Stopwatch(); stopwatch.Start();
                Key[][]        keys      = new Key[kRound][];
                LargeValue[][] values    = new LargeValue[kRound][];
                for (long i = 0; i < kRound; i++)
                {
                    keys[i]   = new Key[kPerRoundKey];
                    values[i] = new LargeValue[kPerRoundKey];
                }
                for (long i = 0; i < kMaxKey; i++)
                {
                    if (updateOnly)
                    {
                        keys[i / kPerRoundKey][i % kPerRoundKey] = new Key {
                            key = (int)i
                        };
                    }
                    else
                    {
                        keys[i / kPerRoundKey][i % kPerRoundKey] = new Key {
                            key = (int)(r * kMaxKey + i)
                        };
                    }
                    values[i / kPerRoundKey][i % kPerRoundKey] = new LargeValue(r * kMaxKey + i, objectWideth);
                }
                stopwatch.Stop();
                Console.WriteLine("Round generate" + r + "<->" + total_count + "(-)" + store.EntryCount + "{-}" + store.IndexSize + "$-$" + stopwatch.ElapsedMilliseconds);
                stopwatch.Restart();
                Thread[] threads = new Thread[kThread];
                for (int tid = 0; tid < kThread; tid++)
                {
                    int threadId = tid;
                    threads[tid] = new Thread(() => upsertWorker(threadId, keys, values));
                }
                for (int tid = 0; tid < kThread; tid++)
                {
                    threads[tid].Start();
                }
                for (int tid = 0; tid < kThread; tid++)
                {
                    threads[tid].Join();
                }
                stopwatch.Stop();
                Console.WriteLine("Round update" + r + "<->" + total_count + "(-)" + store.EntryCount + "{-}" + store.IndexSize + "$-$" + stopwatch.ElapsedMilliseconds);

                total_count = 0;
                stopwatch.Restart();
                threads = new Thread[kThread];
                for (int tid = 0; tid < kThread; tid++)
                {
                    int threadId = tid;
                    threads[tid] = new Thread(() => readWorker(threadId, keys));
                }
                for (int tid = 0; tid < kThread; tid++)
                {
                    threads[tid].Start();
                }
                for (int tid = 0; tid < kThread; tid++)
                {
                    threads[tid].Join();
                }
                stopwatch.Stop();
                Console.WriteLine("Round read" + r + "<->" + total_count + "(-)" + store.EntryCount + "{-}" + store.IndexSize + "$-$" + stopwatch.ElapsedMilliseconds);

                var sesstion = store.NewSession();
                sesstion.Refresh();
                sesstion.CompletePending(true);
                //Console.Out.WriteLine("\t\t<--" + store.Log.TailAddress);
                Console.Out.WriteLine("\tHeadAddress:" + store.Log.HeadAddress);
                Console.Out.WriteLine("\tBeginAddress:" + store.Log.BeginAddress);
                Console.Out.WriteLine("\tReadOnlyAddress:" + store.Log.ReadOnlyAddress);
                Console.Out.WriteLine("\tSafeReadOnlyAddress:" + store.Log.SafeReadOnlyAddress);
                Console.Out.WriteLine("\tTailAddress:" + store.Log.TailAddress);
                sesstion.CompletePending();
                //store.Log.Compact(store.Log.BeginAddress);
                //store.CompleteCheckpoint();
                sesstion.Dispose();
                for (long i = 0; i < kRound; i++)
                {
                    keys   = null;
                    values = null;
                }
                keys   = null;
                values = null;
            }
        }