Exemplo n.º 1
0
 public StatsThread(int iIntervalShowStatsMS, InMemoryCache c)
 {
     iIntervalMS   = iIntervalShowStatsMS;
     cache         = c;
     iReplacedLast = c.GetReplacedItemCount();
 }
Exemplo n.º 2
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("-----------------------------------------------");
        }
Exemplo n.º 3
0
 // percentage is the percentage of items we want to remove from the cache.
 public EvictThread(InMemoryCache c, int percent, int intervalMillSeconds)
 {
     cache            = c;
     iPercentage      = percent;
     iEvictIntervalMS = intervalMillSeconds;
 }