473,890 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: ASP requests and locking

Hi Anthony --

Anthony Jones wrote:
>- ASP.NET uses one thread per HTTP request, correct?

Yes. (Although code responding to thread may spin up some of its own)
OK, figured as much. I'm not forking any threads myself.
If you've placed hashtable into the cache you will need to lock an object
(which can be the hashtable) before reading or modifying. (BTW, what
framework version are you targeting?)
2.0, currently. Why? Is there a difference/advantage? I can probably go
to 3.x if there's a good reason for it.
>- To follow the above, I assume I do have to lock anything that might be
accessed at the same time from two or more concurrent requests?

Typically you would cache immutable content. There is no need to lock such
content.
By immutable content do you mean a string (as in the example below)?
>- When accessing properties of a class that contains only static
property accessors, do I need to lock?

Again it depends on whether the underlying fields may be modified. If so
then yes, the set of fields available to static properties and methods are
common across the app domain so changes to them need to be synchronised.
OK, but wait. Does that mean that if the fields are not being modified
then there's no risk of a collision between two different request threads?
Yes you need locking. However you need to consider whether the such
operation is expensive enough or called often enough to be a real concern
form a concurrency POV.
Well, I'm not sure about it. That's the problem. In a situation where
I'm serving just a few requests per second, a sub-millisecond lock is
probably not a big deal. But what's the impact for an app pool that's
serving lots of concurrent requests?
How do you know you can't afford to lock?
I don't, that's why we're having this conversation =)
Strings are immutable in .NET. 'Copying' a string is a matter of copying a
pointer to a string. How large the string is has no impact on how long that
takes.
OK, that's clear enough.

Thanks a million for your response!
Aug 26 '08 #1
1 1458
"polastine" <no***@example. comwrote in message
news:ej******** ******@TK2MSFTN GP06.phx.gbl...
Hi Anthony --

Anthony Jones wrote:
- ASP.NET uses one thread per HTTP request, correct?
Yes. (Although code responding to thread may spin up some of its own)

OK, figured as much. I'm not forking any threads myself.
If you've placed hashtable into the cache you will need to lock an
object
(which can be the hashtable) before reading or modifying. (BTW, what
framework version are you targeting?)

2.0, currently. Why? Is there a difference/advantage? I can probably go
to 3.x if there's a good reason for it.
Hashtable is old hat (.NET 1.1). Unless you've got some really good reason
use collection types from System.Collecti ons.Generic instead of
System.Collecti ons. If you are able to goto 3.5 then you should.
- To follow the above, I assume I do have to lock anything that might
be
accessed at the same time from two or more concurrent requests?
Typically you would cache immutable content. There is no need to lock
such
content.

By immutable content do you mean a string (as in the example below)?
The purpose of the cache to store values that a costly to re-construct (such
as data created from querying a DB).
The stored values are not expected to change. It may be that they expire or
are invalidated and are therefore droped. Storing a hashtable the contents
of which is to be modified over time would not be in keeping with the cache
purpose. On top of which you would not want it to be dropped from the cache
so you would want to add it to the cache with the NotRemovable priorty, in
which case you may as well use a static field to hold the hashtable and not
bother with the cache at all.

- When accessing properties of a class that contains only static
property accessors, do I need to lock?
Again it depends on whether the underlying fields may be modified. If
so
then yes, the set of fields available to static properties and methods
are
common across the app domain so changes to them need to be synchronised.

OK, but wait. Does that mean that if the fields are not being modified
then there's no risk of a collision between two different request threads?
Yes, nothing will break if all you are doing is reading content that never
changes.

Yes you need locking. However you need to consider whether the such
operation is expensive enough or called often enough to be a real
concern
form a concurrency POV.

Well, I'm not sure about it. That's the problem. In a situation where
I'm serving just a few requests per second, a sub-millisecond lock is
probably not a big deal. But what's the impact for an app pool that's
serving lots of concurrent requests?
Define lots? How many properties will you reading per request and will they
each need to be individually locked?
Are you sure the lock is only sub-millisecond may not in be sub-microsecond?

To a large degree what you actually need to do comes down to the detail of
you design. For example could a bunch of properties be stored together in
structure (a value type) once aquired (under lock) the values in the
structure an be used without a lock.
How do you know you can't afford to lock?

I don't, that's why we're having this conversation =)
Unfortunately there isn't a known rule of thumb that can help, it really
does depend on a many factors such as how much code needs to run under a
lock.

There are two things you can do: design out the mutable shared values and
keep the amount of code running under a lock as small as possible. Usually
the latter can be just the assignment to the shared store that needs a lock.
I doubt you will need to do anything super clever because of contention
problems.

If you goto 3.5 you can use the generic SynchronizedKey edCollection if you
remain with 2.0 then I would say you need to create a synchronising wrapper
for the generic Dictionary. Don't bother with the Cache and hold this
object statically.

OTH if what you are really doing is holding HTML fragments the perhaps you
should be using the cache directly (not storing a collection in the cache
but storing stings containing HTML). Learn how to set up expiration and/or
dependancies so that stale or defunct entries are dropped.

--
Anthony Jones - MVP ASP/ASP.NET
Aug 26 '08 #2

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

Similar topics

3
2573
by: Bruce W.1 | last post by:
With ASP.NET I've found that request are processed sequentially, one at a time, at least on a server with one CPU. If one request blocks for some reason, maybe on a long database query, then all users must wait until it completes, for their request to process. This leaves me wondering about PHP running on IIS and Window. Does this hold true for PHP also? What about PHP on Unix? Does this allow true simultaneous processing of all...
10
2442
by: Eric S. Johansson | last post by:
I have an application where I need a very simple database, effectively a very large dictionary. The very large dictionary must be accessed from multiple processes simultaneously. I need to be able to lock records within the very large dictionary when records are written to. Estimated number of records will be in the ballpark of 50,000 to 100,000 in his early phase and 10 times that in the future. Each record will run about 100 to 150...
16
8947
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
4
32171
by: Phil | last post by:
I'm monitoring one of our servers, and on the whole it is performing well. However, I'm puzzled by the number of LockRequests/sec that Perfmon is recording. We frequently see values exceeding 50,000 and the current peak is 533,616 (the average, as I type this, is 35,102). There are only 40 users on the system. sp_lock shows nothing like this number of locks; it shows something of the order of 30 locks maximum for each execution,...
10
11923
by: McFly Racing | last post by:
Thread Locking In Static Methods I have the need for a Log Manger class that has static methods. Normally I would use the lock statement or a Monitor statement both of which take a reference to (this). In the case of these static methods I am not able to do that.
1
1596
by: peterlan | last post by:
Hello, I have an issue with a long-running import process in our asp.net app (1.1). After the user initiates an import, we're trying to make periodic xmlhttp requests to update a progress bar. In development (running the webserver on localhost) this works fine. When we move the code to our build environment, the webserver won't respond to the xmlhttp request until the import is done. I've tracked the problem down to the session ID cookie...
0
1327
by: xpding | last post by:
Hello, I have a class MyEmbededList contains a generic dictionary, the value field is actually the MyEmbededList type as well. There is another class need to access and manipulate a list of MyEmbededList (please refer to the MyTestClass below). I am not sure whether I implements the right locking mechanism here and hope someone can give me some advices. I have provided some codes for these two classes below. My questions are: 1. Am I...
14
9340
by: Sergei Shelukhin | last post by:
Hi. I have a session started in php and two browser windows (IE)/tabs (FF) open. In one window, I execute a very slow report, immediately after that, I execute a fast simple page in another. I have set up a timer that records time into global variable at the start of the request, it outputs three time values in seconds - right before session_start, right after session_start, and at the very end of the request. here's what it shows
0
4105
by: Cindy Huyser | last post by:
I have an Access 2000 database behind a threaded Java application that that can have have concurrent access to the same table (but not the same record). The database is set up for shared access with "No locks" as the default, so that optimistic record locking should take place, and "Open databases using record-level locking" is selected. Each Java thread gets a new connection to the database, then updates its record. One of my users has...
0
9976
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9815
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10908
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10451
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6035
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4665
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4259
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.