Hi, I am developing an application which will be served to more than hundred of users in one second. Of course, this is a roughly way of telling my case in an example like this.
Because the system will be served many users it has to be use any database queries as seldom as possible. So, I found a simple solution for this: I will save my frequently used data in an object hierarchy for accessing to it easily and in an oop way, then I will load it on each hour. Any update to the data from the web-pages will be saved when hourly schedule comes into the place. Actually webpages had to be in touch with the database for their updating progress, but in my solution, they will be in touch with the cached data. And update will be occured as I stated earlier, when the hourly schedule comes. Because this is the case, I somehow should be ensure about synchronizing the data. When the hourly schedule gets in I will have to be lock up the entire object hierarchy. But this can be problematic when it is think in the way of the time it would take. But I found another simple solution for this: I will load the data from the database and save it into my new object hierarchy. When it has loaded, I will lock the shared object hierarchy and exchange the new object hierarchy with the old one. Then all the request will be used the newly object hierarchy while the older one is waiting the garbage collector. I made some tests about the locking behaviour in web pages those were written with asp.net. I put a "static" dummy locker object into the global.asax.cs for sharing the lock over the entire application domain (I know this may not be necessary but it has came to me as the clearest possible solution at that time). In those tests, I realized that, even whether I acquire the lock or not, pages are synchronize their actions somehow. I realized that by looking the results those were generated from my code. A one page has took the lock when my shared dummy integer varible was 0 and released it when it was 5000. Another has took the lock when the var was 5000 (the state where the first one acquired the lock), and released it when it was 10000 and another one has took when it was 10000.....and so.... The sample code about this can be found at the end of the message. I will store my objects in the cache object that was presented by asp.net framework. As I know, the cache enters the critical region automatically when it has manipulating (like updating or removing the data from the cache) by some code. Because of this reason the lock for the cache may be even unnecessary. And the last question of mine is that, if I ever be need to use a locking schema, which one the superior "for this situation". I am thinking to use ReaderWriterLock locking technique because the 'writing' operations occure least than 'reading' operations. What do you think?.. So guys, I will be very appreciated if I can hear your comments about the case. Best regards, thank you. Inanc Gumus ------------ in some page: ------------ // I know this locking scheme is not efficient one // but this code only for this small testing and actually // who cares.. #define ACQUIRE_LOCK private void Page_Load(object sender, System.EventArgs e) { Response.Write(String.Format("I have started at {0}<br />", DateTime.Now.ToString()); Response.Write(String.Format("My executer thread code is {0}<br />", System.Threading.Thread.CurrentThread.GetHashCode().ToString()); ulong last = 0; Response.Write(String.Format("I got it when it was {0}<br />", Global.DummyVar.ToString()); for (ulong i = 0; i < 500000000; i++) { #if ACQUIRE_LOCK lock (Global.DummyLock) { #endif last = Global.Incr(); #if ACQUIRE_LOCK } #endif } Response.Write("And now its value is "+ last.ToString() +"<br />"); Response.Write("I have finished at "+ DateTime.Now +"<br />"); } ------------ in global.asax.cs: ------------ private static object dummyLock = new object[0]; private static ulong dummyVariable = 0; public static object DummyLock { get { return dummyLock; } } public static ulong DummyVar { get { return dummyVariable; } } public static ulong Incr() { return ++dummyVariable; } =================================== This list is hosted by DevelopMentorŪ http://www.develop.com NEW! ASP.NET courses you may be interested in: 2 Days of ASP.NET, 29 Sept 2003, in Redmond http://www.develop.com/courses/2daspdotnet Guerrilla ASP.NET, 13 Oct 2003, in Boston http://www.develop.com/courses/gaspdotnet View archives and manage your subscription(s) at http://discuss.develop.com