473,395 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

concurrency/lock problem?

I have the following code which is running in every Page_Load of my ASP.Net
app.
It basically will add rows to a table upto MAX_CACHED_ITEMS and then will
flush all the cached items to the database.

Do you foresee any concurrency problem? or any performance problem?

private object lockObject = new object();
private static DataTable myTable; //typed table
private const int MAX_CACHED_ITEMS = 50;

lock(lockObject)
{
if( myTable == null )
{
myTable = MyDal.CreateDataTable();
}
myTable.AddxxxxRow( param1, param2, param3 );
if( myTable.Rows.Count >= MAX_CACHED_ITEMS )
{
try
{
MyDal.MyTable.Update( myTable ); // update the db
MAX_CACHED_ITEMS rows
myTable.Rows.Clear();
}
catch( Exception ex )
{
//handle
}
}
}
Thanks,
Matias
Nov 17 '05 #1
6 1630

"Matias Woloski" <wo*****@NOSPAMsion.com> wrote in message
news:Ov**************@TK2MSFTNGP15.phx.gbl...
I have the following code which is running in every Page_Load of my ASP.Net
app.
It basically will add rows to a table upto MAX_CACHED_ITEMS and then will
flush all the cached items to the database.

Do you foresee any concurrency problem? or any performance problem?

private object lockObject = new object();
private static DataTable myTable; //typed table
private const int MAX_CACHED_ITEMS = 50;

lock(lockObject)
{
if( myTable == null )
{
myTable = MyDal.CreateDataTable();
}
myTable.AddxxxxRow( param1, param2, param3 );
if( myTable.Rows.Count >= MAX_CACHED_ITEMS )
{
try
{
MyDal.MyTable.Update( myTable ); // update the db
MAX_CACHED_ITEMS rows
myTable.Rows.Clear();
}
catch( Exception ex )
{
//handle
}
}
}
Thanks,
Matias

Statics are the worse enemy of performance/scalability in web applications.
So why do you make your myTable static, make it an instance member and
remove the lock.

Willy.

Nov 17 '05 #2
Matias Woloski <wo*****@NOSPAMsion.com> wrote:
I have the following code which is running in every Page_Load of my ASP.Net
app.
It basically will add rows to a table upto MAX_CACHED_ITEMS and then will
flush all the cached items to the database.

Do you foresee any concurrency problem? or any performance problem?


Yes - your lock is effectively doing nothing, as you'll have a new
instance of the page for every request.

You need to lock on something shared.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
sorry, I mistyped the code.

The lock object is static.

private static object lockObject = new object();

Now?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Matias Woloski <wo*****@NOSPAMsion.com> wrote:
I have the following code which is running in every Page_Load of my
ASP.Net
app.
It basically will add rows to a table upto MAX_CACHED_ITEMS and then will
flush all the cached items to the database.

Do you foresee any concurrency problem? or any performance problem?


Yes - your lock is effectively doing nothing, as you'll have a new
instance of the page for every request.

You need to lock on something shared.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4

"Matias Woloski" <wo*****@NOSPAMsion.com> wrote in message
news:eG****************@tk2msftngp13.phx.gbl...
sorry, I mistyped the code.

The lock object is static.

private static object lockObject = new object();

Now?


The question is why do you share the table, I don't see any, but you might
have good reasons to do so, in that case there is nothing else you can do
than synchronize access to it.

Willy.
Nov 17 '05 #5

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:O2****************@TK2MSFTNGP09.phx.gbl...
The question is why do you share the table, I don't see any, but you might
have good reasons to do so, in that case there is nothing else you can do
than synchronize access to it.


I could create an instance and save it to the cache.
Now, the difference between having static or cache is just that the cache
will manage expiration, right?

Btw, I need to have a global scoped table because I'm storing Page-View
records in this table, so I want to add rows to that table for any user that
enter in my app. When I reach MAXITEMS I will flush the table to the
database

That make sense?

Thanks,
Matias


Nov 17 '05 #6

"Matias Woloski" <wo*****@NOSPAMsion.com> wrote in message
news:ub****************@TK2MSFTNGP15.phx.gbl...

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:O2****************@TK2MSFTNGP09.phx.gbl...

The question is why do you share the table, I don't see any, but you
might have good reasons to do so, in that case there is nothing else you
can do than synchronize access to it.


I could create an instance and save it to the cache.
Now, the difference between having static or cache is just that the cache
will manage expiration, right?

Btw, I need to have a global scoped table because I'm storing Page-View
records in this table, so I want to add rows to that table for any user
that enter in my app. When I reach MAXITEMS I will flush the table to the
database

That make sense?

Thanks,
Matias


I would add the record to the cache after having updated the Database (note
that you can always use a private cache for the table data if you wan't to
update in batches). That way you reduce the time you are holding a lock to
the time it takes to update the cache.

Willy.


Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul Rubin | last post by:
I'm wondering if folks here have favorite lightweight ways of dealing with concurrency in cgi's. Take a simple case: You want to write a cgi that implements a simple counter. The first time...
16
by: aurora | last post by:
Hello! Just gone though an article via Slashdot titled "The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software" http://www.gotw.ca/publications/concurrency-ddj.htm]. It argues...
4
by: Robin Tucker | last post by:
Hi, I'm currently implementing a database with a tree structure in a table. The nodes in the tree are stored as records with a column called "Parent". The root of the tree has a "NULL" parent....
7
by: chessplayer | last post by:
Greetings Folks, I am trying to understand how DB2 locks data and can't believe my eyes. Have read the literature about the difference isolation levels and have a general understanding about...
4
by: Yoram Biberman | last post by:
I have a few questions concerning concurrency control. I shall thank whoever can help me. Question #1 ========= Assume the following (concurrent) schedule, in which both transactions run in a...
10
by: e_matthes | last post by:
Hello everyone, I have read many threads about concurrency issues, and I think I understand some of the pieces, but not the whole picture. I believe I am like many people using php: ...
9
by: Anthony Paul | last post by:
Hello everyone! I've been reading a great book on SOA called "Enterprise SOA" and found that it answered many questions. However, there's one particular scenario (involving business-rules)...
9
by: Scott Gifford | last post by:
I have a question about concurrency and delegates. Say I have a class roughly like this: public class Class1 { public delegate void MyEventHandler(); private event MyEventHandler onMyEvent;...
8
by: Roger.Noreply | last post by:
Hi, Sql-Server 2000, 2005. A report fetches a lot of rows using the "WITH (ROWLOCK)" syntax (the sql is generated on the fly by a tool and not easily changeable). SELECT col1, col2 FROM mytab...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.