I was able to improve web application performance 10% faster than before. At the same time, I noticed that the memory usage doubled !!!
Test application: calling a web service, performing a complex business action * [number of users] * [number of times]
I check my change code, but nothing suspicious is to use more memory .. (all I did was delete the lines of code that serialize the DataSet to byte [] and saved it in cache) I checked again and again in multi-threaded test:
- As I missed more and more code ( performance improved - memory rose )
- How I repeated bad code in a loop (performance was bad - memory went low)
Can anyone explain why ????
Code below:
To: (Cycle time: 100% Memory 100%)
outStream = new MemoryStream(); new BinaryFormatter().Serialize(outStream, stateData); outStream.Close(); SessionSettings.StateData_Set(stateId, outStream.ToArray()); outStream.Dispose();
After selecting 1: (Cycle time: 200% Memory 50%)
for (int i = 0; i < 20; i++) { outStream = new MemoryStream(); new BinaryFormatter().Serialize(outStream, stateData); } outStream.Close(); SessionSettings.StateData_Set(stateId, outStream.ToArray()); outStream.Dispose();
After selecting 2: (Cycle time: 90% Memory 200%)
//outStream = new MemoryStream(); //new BinaryFormatter().Serialize(outStream, stateData); //outStream.Close(); SessionSettings.StateData_Set(stateId, null); //outStream.Dispose();
SessionSettings.StateData_Set places an object in
dictionary<string,dictionary<string, object>>
which means
<Sessions<DataKey,DataObject>>
at the end of each cycle, the internal dictionary deletes the entry, and at the end of each user session, the entire internal dictionary is deleted from the external dictionary.