// 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; }
public void DoWork() { stopwatch.Reset(); stopwatch.Start(); long lElapsedMS = 0; ulong ulRequests = 1; // We pin every Nth item. int iNth = Int32.MaxValue; if (iPinningPercent != 0) { iNth = 100 / iPinningPercent; } try { while (true) { bool fPin = false; int iAllocated = 0; iAllocated += AllocateTempHalf(); int iItemToLookUp = r.getRand(DiskItems.GetTotalItems()); if ((ulRequests % (ulong)iNth) == 0) { //Console.WriteLine("pinning on request {0}!", ulRequests); fPin = true; } string strData = cache.GetUserData(iItemToLookUp, fPin); // Simulating using the data from the item. StringBuilder sb = new StringBuilder(strData); sb.Append(ulRequests); iAllocated += AllocateTempQuater(); AllocateRest(iAllocated); ulRequests++; if (ulRequests % 100 == 0) { Console.WriteLine("{0} requests executed, took {1}ms", ulRequests, stopwatch.ElapsedMilliseconds - lElapsedMS); lElapsedMS = stopwatch.ElapsedMilliseconds; } } } catch (Exception ex) { Console.WriteLine("!!!!!!" + ex.ToString()); } Console.WriteLine("----------------Exiting user thread----------------"); }