public void SteadyState() { Console.WriteLine(_index + ": replacing old every " + _old_time + "; med every " + _med_time + ";creating young " + _young_time + "times (" + "(size " + _mean_young_alloc_size + ")"); Console.WriteLine("iterating {0} times", _iter_count); int iter_interval = _iter_count / 10; Stopwatch stopwatch = new Stopwatch(); stopwatch.Reset(); stopwatch.Start(); //int lastGen2Count = 0; int lastGen1Count = 0; int checkInterval = _old.Length / 10; int lastChecked = 0; int iCheckedEnd = 0; int timeoutInterval = 5; double pinRatio = 0.1; bool fIsPinned = false; int iPinInterval = (int)((double)1 / pinRatio); Console.WriteLine("Pinning every {0} object", iPinInterval); int iNextPin = _rand.getRand(iPinInterval * 4) + 1; int iPinnedObject = 0; int iPinnedMidSize = _mean_old_alloc_size * 2; int countObjects = 0; int countObjectsGen1 = 0; int[] countWithGen = new int[3]; MiddlePin[] steadyPinningArray = new MiddlePin[100]; GCHandle[] steadyPinningHandles = new GCHandle[100]; int steadyPinningIndex = 0; for (steadyPinningIndex = 0; steadyPinningIndex < steadyPinningArray.Length; steadyPinningIndex++) { steadyPinningArray[steadyPinningIndex] = new MiddlePin(); steadyPinningHandles[steadyPinningIndex] = new GCHandle(); } for (int j = 0; j < _iter_count; j++) { if (steadyPinningIndex >= steadyPinningArray.Length) { steadyPinningIndex = 0; // Console.WriteLine("steady array wrapped, press enter to continue"); // Console.ReadLine(); } byte[] tempObj = new byte[1]; steadyPinningArray[steadyPinningIndex].smallNonePinned = new byte[8]; steadyPinningArray[steadyPinningIndex].pinnedObj = new byte[8]; steadyPinningArray[steadyPinningIndex].nonePinned = new byte[24]; steadyPinningHandles[steadyPinningIndex] = GCHandle.Alloc(steadyPinningArray[steadyPinningIndex].pinnedObj, GCHandleType.Pinned); steadyPinningArray[steadyPinningIndex].smallNonePinned[3] = 0x31; steadyPinningArray[steadyPinningIndex].smallNonePinned[5] = 0x51; steadyPinningArray[steadyPinningIndex].smallNonePinned[7] = 0x71; steadyPinningArray[steadyPinningIndex].pinnedObj[3] = 0x21; steadyPinningArray[steadyPinningIndex].pinnedObj[5] = 0x41; steadyPinningArray[steadyPinningIndex].pinnedObj[7] = 0x61; tempObj = new byte[256]; steadyPinningIndex++; countObjects = 0; countObjectsGen1 = 0; iCheckedEnd = lastChecked + checkInterval; if (iCheckedEnd > _old.Length) { iCheckedEnd = _old.Length; } //Console.WriteLine("timing out item {0} to {1}", lastChecked, iCheckedEnd); // time out requests in this range. // for the range we are looking at time out requests (ie, end them and replace them with new ones). // we go from the beginning of the range to the end, time out every Nth one; then time out everyone // after that, and so on. for (int iIter = 0; iIter < timeoutInterval; iIter++) { for (int iCheckIndex = 0; iCheckIndex < ((iCheckedEnd - lastChecked) / timeoutInterval); iCheckIndex++) { int iItemIndex = (lastChecked + iCheckIndex * timeoutInterval + iIter) % _old.Length; // Console.WriteLine("replacing item {0}", iItemIndex); _old[iItemIndex].Free(); countObjects++; if ((countObjects % 10) == 0) { byte[] temp = new byte[_mean_med_alloc_size * 3]; temp[0] = (byte)27; // 0x1b } else if ((countObjects % 4) == 0) { byte[] temp = new byte[1]; temp[0] = (byte)27; // 0x1b } if (countObjects == iNextPin) { fIsPinned = true; iNextPin += _rand.getRand(iPinInterval * 4) + 1; } else { fIsPinned = false; } iPinnedMidSize = _mean_old_alloc_size * 2; if (fIsPinned) { iPinnedObject++; if ((iPinnedObject % 10) == 0) { iPinnedMidSize = _mean_old_alloc_size * 10; } } //Console.WriteLine("perm {0}, mid {1}, {2}", mean_old_alloc_size, iPinnedMidSize, (fIsPinned ? "pinned" : "not pinned")); _old[iItemIndex] = new MyRequest(_mean_old_alloc_size, iPinnedMidSize, fIsPinned); } } for (int i = 0; i < 3; i++) { countWithGen[i] = 0; } // Console.WriteLine("Checking {0} to {1}", lastChecked, iCheckedEnd); for (int iItemIndex = lastChecked; iItemIndex < iCheckedEnd; iItemIndex++) { //int iGen = GC.GetGeneration(old[iItemIndex].mObj); int iGen = _rand.getRand(3); countWithGen[iGen]++; if (iGen == 1) { //Console.WriteLine("item {0} is in gen1, getting rid of it", iItemIndex); if ((countObjectsGen1 % 5) == 0) { _old[iItemIndex].mObj = null; } countObjectsGen1++; } } // Console.WriteLine("{0} in gen0, {1} in gen1, {2} in gen2", // countWithGen[0], // countWithGen[1], // countWithGen[2]); // // Console.WriteLine("{0} objects out of {1} are in gen1", countObjectsGen1, (iCheckedEnd - lastChecked)); if (iCheckedEnd == _old.Length) { lastChecked = 0; } else { lastChecked += checkInterval; } int currentGen1Count = GC.CollectionCount(1); if ((currentGen1Count - lastGen1Count) > 30) { GC.Collect(2, GCCollectionMode.Forced, false); Console.WriteLine("{0}: iter {1}, heap size: {2}", _index, j, GC.GetTotalMemory(false)); lastGen1Count = currentGen1Count; } } for (steadyPinningIndex = 0; steadyPinningIndex < steadyPinningArray.Length; steadyPinningIndex++) { if (steadyPinningHandles[steadyPinningIndex].IsAllocated) { steadyPinningHandles[steadyPinningIndex].Free(); } } stopwatch.Stop(); Console.WriteLine("{0}: steady: {1:d} seconds({2:d} ms. Heap size {3})", _index, (int)stopwatch.Elapsed.TotalSeconds, (int)stopwatch.Elapsed.TotalMilliseconds, GC.GetTotalMemory(false)); }
public void SteadyState() { Console.WriteLine(_index + ": replacing old every " + _old_time + "; med every " + _med_time + ";creating young " + _young_time + "times (" + "(size " + _mean_young_alloc_size + ")"); Console.WriteLine("iterating {0} times", _iter_count); int iter_interval = _iter_count / 10; Stopwatch stopwatch = new Stopwatch(); stopwatch.Reset(); stopwatch.Start(); //int lastGen2Count = 0; int lastGen1Count = 0; int checkInterval = _old.Length / 10; int lastChecked = 0; int iCheckedEnd = 0; int timeoutInterval = 5; double pinRatio = 0.1; bool fIsPinned = false; int iPinInterval = (int)((double)1 / pinRatio); Console.WriteLine("Pinning every {0} object", iPinInterval); int iNextPin = _rand.getRand(iPinInterval * 4) + 1; int iPinnedObject = 0; int iPinnedMidSize = _mean_old_alloc_size * 2; int countObjects = 0; int countObjectsGen1 = 0; int[] countWithGen = new int[3]; MiddlePin[] steadyPinningArray = new MiddlePin[100]; GCHandle[] steadyPinningHandles = new GCHandle[100]; int steadyPinningIndex = 0; for (steadyPinningIndex = 0; steadyPinningIndex < steadyPinningArray.Length; steadyPinningIndex++) { steadyPinningArray[steadyPinningIndex] = new MiddlePin(); steadyPinningHandles[steadyPinningIndex] = new GCHandle(); } for (int j = 0; j < _iter_count; j++) { if (steadyPinningIndex >= steadyPinningArray.Length) { steadyPinningIndex = 0; // Console.WriteLine("steady array wrapped, press enter to continue"); // Console.ReadLine(); } byte[] tempObj = new byte[1]; steadyPinningArray[steadyPinningIndex].smallNonePinned = new byte[8]; steadyPinningArray[steadyPinningIndex].pinnedObj = new byte[8]; steadyPinningArray[steadyPinningIndex].nonePinned = new byte[24]; steadyPinningHandles[steadyPinningIndex] = GCHandle.Alloc(steadyPinningArray[steadyPinningIndex].pinnedObj, GCHandleType.Pinned); steadyPinningArray[steadyPinningIndex].smallNonePinned[3] = 0x31; steadyPinningArray[steadyPinningIndex].smallNonePinned[5] = 0x51; steadyPinningArray[steadyPinningIndex].smallNonePinned[7] = 0x71; steadyPinningArray[steadyPinningIndex].pinnedObj[3] = 0x21; steadyPinningArray[steadyPinningIndex].pinnedObj[5] = 0x41; steadyPinningArray[steadyPinningIndex].pinnedObj[7] = 0x61; tempObj = new byte[256]; steadyPinningIndex++; countObjects = 0; countObjectsGen1 = 0; iCheckedEnd = lastChecked + checkInterval; if (iCheckedEnd > _old.Length) { iCheckedEnd = _old.Length; } //Console.WriteLine("timing out item {0} to {1}", lastChecked, iCheckedEnd); // time out requests in this range. // for the range we are looking at time out requests (ie, end them and replace them with new ones). // we go from the beginning of the range to the end, time out every Nth one; then time out everyone // after that, and so on. for (int iIter = 0; iIter < timeoutInterval; iIter++) { for (int iCheckIndex = 0; iCheckIndex < ((iCheckedEnd - lastChecked) / timeoutInterval); iCheckIndex++) { int iItemIndex = (lastChecked + iCheckIndex * timeoutInterval + iIter) % _old.Length; // Console.WriteLine("replacing item {0}", iItemIndex); _old[iItemIndex].Free(); countObjects++; if ((countObjects % 10) == 0) { byte[] temp = new byte[_mean_med_alloc_size * 3]; temp[0] = (byte)27; // 0x1b } else if ((countObjects % 4) == 0) { byte[] temp = new byte[1]; temp[0] = (byte)27; // 0x1b } if (countObjects == iNextPin) { fIsPinned = true; iNextPin += _rand.getRand(iPinInterval * 4) + 1; } else { fIsPinned = false; } iPinnedMidSize = _mean_old_alloc_size * 2; if (fIsPinned) { iPinnedObject++; if ((iPinnedObject % 10) == 0) { iPinnedMidSize = _mean_old_alloc_size * 10; } } //Console.WriteLine("perm {0}, mid {1}, {2}", mean_old_alloc_size, iPinnedMidSize, (fIsPinned ? "pinned" : "not pinned")); _old[iItemIndex] = new MyRequest(_mean_old_alloc_size, iPinnedMidSize, fIsPinned); } } for (int i = 0; i < 3; i++) { countWithGen[i] = 0; } // Console.WriteLine("Checking {0} to {1}", lastChecked, iCheckedEnd); for (int iItemIndex = lastChecked; iItemIndex < iCheckedEnd; iItemIndex++) { //int iGen = GC.GetGeneration(old[iItemIndex].mObj); int iGen = _rand.getRand(3); countWithGen[iGen]++; if (iGen == 1) { //Console.WriteLine("item {0} is in gen1, getting rid of it", iItemIndex); if ((countObjectsGen1 % 5) == 0) _old[iItemIndex].mObj = null; countObjectsGen1++; } } // Console.WriteLine("{0} in gen0, {1} in gen1, {2} in gen2", // countWithGen[0], // countWithGen[1], // countWithGen[2]); // // Console.WriteLine("{0} objects out of {1} are in gen1", countObjectsGen1, (iCheckedEnd - lastChecked)); if (iCheckedEnd == _old.Length) { lastChecked = 0; } else { lastChecked += checkInterval; } int currentGen1Count = GC.CollectionCount(1); if ((currentGen1Count - lastGen1Count) > 30) { GC.Collect(2, GCCollectionMode.Forced, false); Console.WriteLine("{0}: iter {1}, heap size: {2}", _index, j, GC.GetTotalMemory(false)); lastGen1Count = currentGen1Count; } } for (steadyPinningIndex = 0; steadyPinningIndex < steadyPinningArray.Length; steadyPinningIndex++) { if (steadyPinningHandles[steadyPinningIndex].IsAllocated) steadyPinningHandles[steadyPinningIndex].Free(); } stopwatch.Stop(); Console.WriteLine("{0}: steady: {1:d} seconds({2:d} ms. Heap size {3})", _index, (int)stopwatch.Elapsed.TotalSeconds, (int)stopwatch.Elapsed.TotalMilliseconds, GC.GetTotalMemory(false)); }