Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Performance / March 2005

Tip: Looking for answers? Try searching our database.

4 qns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
t bsa - 24 Mar 2005 05:19 GMT
Can you please help me with these questions.
1. I have a static method in a class. This method may
be simultaneously called by 2 or more classes. What
will happen?
2. Two users are trying update a record in database.
First user has updated the database. The second user
does not know it. He is also trying to change the
record data.What should be the ideal solution in this
case and how to handle it.
3. I have a huge data that is cached. Now another
application changes the data in the database. How do I
update my Cache. Who is going to trigger action to
update the data on the cache?
4. How do I share my session data when my application
is running on a webfarm?

I tried my best to know answers for these qns. But I
was unable to find suitable answers.

Thanks,
Sean Hederman - 24 Mar 2005 08:41 GMT
> Can you please help me with these questions.
> 1. I have a static method in a class. This method may
> be simultaneously called by 2 or more classes. What
> will happen?

It depends on what the static method does. If it merely accesses variables
and resources local to the static method, then there is no problem. However,
if it accesses external resources (such as static fields) then there could
be problems if the operations are not atomic. In this case it is recommended
that you use some kind of synchronisation on these resources. This could be
as simple as Interlocked, or could be more complex. An important point is
that these resources must be synchronised everywhere they are used, not just
in the static method.

> 2. Two users are trying update a record in database.
> First user has updated the database. The second user
> does not know it. He is also trying to change the
> record data.What should be the ideal solution in this
> case and how to handle it.

This again is dependent on your requirements. There are whole books
dedicated to handling this sort of condition. One approach is to simply say
that the last update succeeds always. You could also use a Timestamp field
on the record, and fail the second transaction if the data has changed.
Another is to lock the record while it is "in use" (pessimistic
concurrency), however this harms overall throughput. It all depends on what
you want to happen in this case. There are many more approaches to this
scenario. Have a look at the Optimistic Concurrency article at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conoptimisticconcurrency.asp

for more details.

> 3. I have a huge data that is cached. Now another
> application changes the data in the database. How do I
> update my Cache. Who is going to trigger action to
> update the data on the cache?

Assuming you can't modify the other application, you could write a trigger
on the requisite tables that will notify your caching system that the data
needs to be refreshed. You might tell it to refresh all the data, or merely
the affected rows (better but more difficult to implement).

> 4. How do I share my session data when my application
> is running on a webfarm?

You can get ASP.NET to store session data in a SQL Server database.
Unfortunately I'm not sure how you go about this, but I'm sure others will
be able to assist.

> I tried my best to know answers for these qns. But I
> was unable to find suitable answers.
[quoted text clipped - 8 lines]
>
> <Id>k71474KXqkyWHsXft7rJAg==</Id>
Fred Hirschfeld - 24 Mar 2005 15:54 GMT
for number 2: I tend to like using a VERSION column on the tables so that
when you do an update you can either read (with lock) the record from the DB
and check the version from your data to that of the DB, if they are the same
then do the update. Alternatively (and less DB calls) would be to add the
VERSION = XX to your WHERE clause on an update so that if your call returns
with 0 records updated then you know there was an update since you last read
the data. This also requires that you increment the VERSION number with each
update.

#3: where is the Cache? Is this an ASP.NET Cache that you are using? I am
not sure you could simply use a trigger in the database without having
permission to call out to a COM component to perform the refresh. It may be
necessary to create a polling process that checks the data in the database
on your application that maintains the cache. You could simply check for the
latest modification date (assuming that is on the table) and compare it to
the latest (You would have to track this) when you last loaded the cache.
Then you could simply lock the cache, load those records that have been
modified since last load and refresh the cache with only those records.

Fred

> > Can you please help me with these questions.
> > 1. I have a static method in a class. This method may
[quoted text clipped - 24 lines]
> you want to happen in this case. There are many more approaches to this
> scenario. Have a look at the Optimistic Concurrency article at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conoptimisticconcurrency.asp

> for more details.
>
[quoted text clipped - 27 lines]
> >
> > <Id>k71474KXqkyWHsXft7rJAg==</Id>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.