Пример #1
0
 public UserThread(InMemoryCache c, OnDiskData diskData, int iTempBytes, int iPPercent)
 {
     DiskItems       = diskData;
     cache           = c;
     iTemporaryBytes = iTempBytes;
     iPinningPercent = iPPercent;
 }
Пример #2
0
        // I am not recording the access time when prepopulating the cache.
        public void InitCache(OnDiskData diskData, int iPercent)
        {
            DiskItems = diskData;
            int iDiskItemsCount   = diskData.GetTotalItems();
            int iCachedItemsCount = iDiskItemsCount * iPercent / 100;

            CachedItems    = new CachedItem[iCachedItemsCount];
            iReplacedItems = 0;

            int iAdded = 0;

            while (iAdded < iCachedItemsCount)
            {
                OnDiskItem temp = diskData.GetItem(r.getRand(iDiskItemsCount));
                CachedItem item = new CachedItem(temp);
                CachedItems[iAdded] = item;
                iAdded++;
            }

            Console.WriteLine("Cached initialized: {0} entries, heap size is {1} bytes",
                              iCachedItemsCount, GC.GetTotalMemory(true));

            iCachedCount = iCachedItemsCount;
        }
Пример #3
0
        public static void Main2(string[] args)
        {
            int iArgIndex = 0;

            while (iArgIndex < (args.Length - 1))
            {
                string strOption = args[iArgIndex].Trim();
                if (strOption.StartsWith("-cp"))
                {
                    iCachedPercent = int.Parse(args[++iArgIndex].Trim());
                }
                else if (strOption.StartsWith("-ds"))
                {
                    iOnDishSize = int.Parse(args[++iArgIndex].Trim());
                }
                else if (strOption.StartsWith("-ut"))
                {
                    iUserThreads = int.Parse(args[++iArgIndex].Trim());
                }
                else if (strOption.StartsWith("-tb"))
                {
                    iTemporaryBytes = int.Parse(args[++iArgIndex].Trim());
                }
                else if (strOption.StartsWith("-pp"))
                {
                    iPinningPercent = int.Parse(args[++iArgIndex].Trim());
                }
                else if (strOption.StartsWith("-ep"))
                {
                    iEvictPercent = int.Parse(args[++iArgIndex].Trim());
                }
                else if (strOption.StartsWith("-ei"))
                {
                    iEvictIntervalMS = int.Parse(args[++iArgIndex].Trim());
                }
                else if (strOption.StartsWith("-st"))
                {
                    iIntervalShowStatsMS = int.Parse(args[++iArgIndex].Trim());
                }

                iArgIndex++;
            }

            Console.WriteLine("---------Options for running this test---------");
            Console.WriteLine("OnDisk size is {0}, Caching {1}%", iOnDishSize, iCachedPercent);
            // Instead of actually loading data from the disk we just create
            // it in memory - this way we can eliminate the variability
            // created with the APIs that do the loading.
            OnDiskData diskData = new OnDiskData();

            diskData.CreateOnDiskData(iOnDishSize);

            // The cache is prepopulated by randomly adding some percentage
            // of the on disk data, but in the format that's actually
            // represented in the cache (which is bigger than the on disk
            // format since usually people store in a more compact form).
            // By default we add 80% of the on disk data to cache.
            InMemoryCache cache = new InMemoryCache();

            cache.InitCache(diskData, iCachedPercent);

            Console.WriteLine("{0} user threads, each iteration allocates {1} bytes temporary memory, pinning {2}% entries",
                              iUserThreads, iTemporaryBytes, iPinningPercent);

            UserThread  threadUser;
            ThreadStart ts;

            Thread[] threadsUser = new Thread[iUserThreads];

            for (int i = 0; i < iUserThreads; i++)
            {
                threadUser     = new UserThread(cache, diskData, iTemporaryBytes, iPinningPercent);
                ts             = new ThreadStart(threadUser.DoWork);
                threadsUser[i] = new Thread(ts);
                threadsUser[i].Start();
            }

            Console.WriteLine("Eviction thread evicts {0}% every {1}ms", iEvictPercent, iEvictIntervalMS);
            EvictThread threadEvict = new EvictThread(cache, iEvictPercent, iEvictIntervalMS);
            ThreadStart tsEvict     = new ThreadStart(threadEvict.Evict);
            Thread      tEvict      = new Thread(tsEvict);

            tEvict.Start();

            Console.WriteLine("Stats thread shows stats {0}ms", iIntervalShowStatsMS);
            StatsThread threadStats = new StatsThread(iIntervalShowStatsMS, cache);
            ThreadStart tsStats     = new ThreadStart(threadStats.ShowStats);
            Thread      tStats      = new Thread(tsStats);

            tStats.Start();

            Console.WriteLine("-----------------------------------------------");
        }