473,789 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What Impact Do Static HashTables and Classes have on the CPU?

Hello,

I've written a high performance web app with C# and it completely relies on
static hash tables (using sync) and classes. Under real world stress this
app is handling 5 get requests per CPU per second.

I've gone from a single-core/single-proc, to a dual-core/single-proc to a
dual-core/dual-proc and as I suspected the number of requests per second per
CPU does not increase it remains at 5 per CPU.

My reading of IIS threading suggests that 10-12 per requests per second can
be expected from a non-static class based app. If this assumption is
correct, do you have any suggestions on how I might be able to increase the
number of requests per second?

TIA

Mar 28 '07 #1
14 1795
Hi,

I think that your problem may be that you need to sync the access to the
static elements, in this escenario only one thread can access a given
resource. of course this is a BIG constrains. Adding more processors solve
nothing and may even make the things worse as more thread can be potentally
be waiting for the resource.

why you need to use static resourcers?

"Mark S." <ma***@yahoo.co mwrote in message
news:uv******** ******@TK2MSFTN GP03.phx.gbl...
Hello,

I've written a high performance web app with C# and it completely relies
on static hash tables (using sync) and classes. Under real world stress
this app is handling 5 get requests per CPU per second.

I've gone from a single-core/single-proc, to a dual-core/single-proc to a
dual-core/dual-proc and as I suspected the number of requests per second
per CPU does not increase it remains at 5 per CPU.

My reading of IIS threading suggests that 10-12 per requests per second
can be expected from a non-static class based app. If this assumption is
correct, do you have any suggestions on how I might be able to increase
the number of requests per second?

TIA

Mar 28 '07 #2
"Mark S." <ma***@yahoo.co mwrote in message
news:uv******** ******@TK2MSFTN GP03.phx.gbl...
I've written a high performance web app with C# and it completely relies
on static hash tables (using sync) [...] any suggestions on how I might be
able to increase the number of requests per second?
If you are using System.Collecti ons.Hashtable objects and mostly reading
them, you can make use of the characteristic of the Hashtable of being
thread-safe for multiple readers or only one writer. Instead of using sync,
use a ReaderWrtiterLo ck, which will give you better concurrency.

Mar 28 '07 #3
Hi Mark,

since you are tolking about static hashtables, I suppose you are using
shared data that is shared by all requests.
Surely, you have to synchronize the access to this data, but you should try
to minimize the time, during wich each request is locked. All codeparts wich
are locked against the same lock-object will be executed, as if they were on
one thread. So fore this part of your code the dual-core/dual-proc will have
absolutly no advantage.

HTH
Christof

"Mark S." <ma***@yahoo.co mschrieb im Newsbeitrag
news:uv******** ******@TK2MSFTN GP03.phx.gbl...
Hello,

I've written a high performance web app with C# and it completely relies
on static hash tables (using sync) and classes. Under real world stress
this app is handling 5 get requests per CPU per second.

I've gone from a single-core/single-proc, to a dual-core/single-proc to a
dual-core/dual-proc and as I suspected the number of requests per second
per CPU does not increase it remains at 5 per CPU.

My reading of IIS threading suggests that 10-12 per requests per second
can be expected from a non-static class based app. If this assumption is
correct, do you have any suggestions on how I might be able to increase
the number of requests per second?

TIA

Mar 28 '07 #4
Allow me to clarification my numbers just a bit.

Using the performance monitor:
(Number of get request per second to asp.net app 2.0) / (CPU %) = N request
per second per 1% CPU.

Single single-core: 8 per
Single dual-core: 6 per
Dual dual-core: 5 per

Alberto,
If you are using System.Collecti ons.Hashtable objects and mostly
reading them, you can make use of the characteristic of the Hashtable of
being thread-safe for multiple readers or only one writer. Instead of
using sync, use a ReaderWrtiterLo ck, which will give you better
concurrency.
Unfortunately each request writes.

Ignacio,
>why you need to use static resourcers?
Every request makes decisions based on what the other request had written to
the static hashTable and then writes what it decided to do back. This
sequential decision makes is required by the code's business logic. If you
or anyone else has a better way to achieve this logic, I'm open to
suggestions.

THX

Mar 28 '07 #5
"Mark S." <ma***@yahoo.co mwrote in message news:uv******** ******@TK2MSFTN GP03.phx.gbl...
Hello,

I've written a high performance web app with C# and it completely relies on static hash
tables (using sync) and classes. Under real world stress this app is handling 5 get
requests per CPU per second.

I've gone from a single-core/single-proc, to a dual-core/single-proc to a
dual-core/dual-proc and as I suspected the number of requests per second per CPU does not
increase it remains at 5 per CPU.

My reading of IIS threading suggests that 10-12 per requests per second can be expected
from a non-static class based app. If this assumption is correct, do you have any
suggestions on how I might be able to increase the number of requests per second?

TIA
Just curious how you are stress testing this.
What's the OS the server (IIS) runs on?
What kind (OS and application) and how many clients (PC's) do you have to access the server?
What's the round-trip time for a single get request?

Willy.


Mar 28 '07 #6
Just curious how you are stress testing this.

In the beginning I used Web Application Stress Tool but to be honest I don't
remember the exact numbers, but it was in the ballpark.
http://www.microsoft.com/downloads/d...displaylang=en

The application is live, so the numbers I mentioned previously are real
world numbers.

What's the OS the server (IIS) runs on?
Windows 2003 SP 2 IIS 6.0 ASP.NET 2.0
What kind (OS and application) and how many clients (PC's) do you have to
access the server?
Dedicated web servers running nothing else. Application servers only aspx
pages which returns HTML and Javascript, no images are being served. All
data is stored in varioius flavors of hashTables. A timer process collects
the data and sends it to the database, the incoming requests never read or
write to the db directly. This is makes all the difference.

1.4 million unique visitors a day. 4.5 million get requests an hour during
business hours.
What's the round-trip time for a single get request?
As you know being a web app the time will depend on the network, but to give
you a baseline, removing the most the network latency. Here's how long it
takes from the dev server to the live web farm:

6K file gziped (iis) to 2.3K: 0.041 seconds (half the time there's 0.100
second additional delay)
7byte file: 0.009 seconds
3K file gziped (iis) to 1.3K: 0.028 seconds (half the time there's 0.100
second additional delay)

HTH
Mar 28 '07 #7
Alberto Poblacion <ea************ *************** ***@poblacion.o rg>
wrote:
"Mark S." <ma***@yahoo.co mwrote in message
news:uv******** ******@TK2MSFTN GP03.phx.gbl...
I've written a high performance web app with C# and it completely relies
on static hash tables (using sync) [...] any suggestions on how I might be
able to increase the number of requests per second?

If you are using System.Collecti ons.Hashtable objects and mostly reading
them, you can make use of the characteristic of the Hashtable of being
thread-safe for multiple readers or only one writer. Instead of using sync,
use a ReaderWrtiterLo ck, which will give you better concurrency.
ReaderWriterLoc ks have fairly hefty overheads - unless the work you do
within the lock is significant, the overhead could well be more than
the gain due to more concurrency.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 28 '07 #8
On Mar 28, 8:17 am, "Mark S." <m...@yahoo.com wrote:
Every request makes decisions based on what the other request had written to
the static hashTable and then writes what it decided to do back. This
sequential decision makes is required by the code's business logic. If you
or anyone else has a better way to achieve this logic, I'm open to
suggestions.
OK... I'll take a crack at it.

First, though:

1. What are the keys in the hash table? What do they represent?
2. How many keys can there be?
3. How are they structured?
4. How (and when) can new keys be created?

Once I know the answers to these questions, perhaps I can suggest a
better structure.

A preview... what I'm thinking now.

The problem with a hashtable is that the correspondence between a key
and the corresponding hash bucket and its chain of keys is arbitrary.
This means that two threads writing to the same hashtable practically
have to lock the whole structure and therefore run serially.

If, however, you could create a different structure that understands
the structure of your keys, you might be able to selectively lock only
parts of the structure. Viz: one thread writing to the structure under
key A might be able to run in parallel with another thread writing
under key B if the two keys have nothing in common within the data
structure. If you were, for example, to roll your own hash table, you
could attach a different lock object to each hash bucket, and lock the
buckets individually rather than taking out a lock on the entire
table.

Of course, whether this gives you improvements in concurrency entirely
depends upon the nature of your problem. If it is highly likely that
all threads will be working on the same key at the same time then it
doesn't buy you much. If, on the other hand, multiple threads are
likely working on different keys at the same time, and the keys can be
structured so that they are unlikely to land in the same part of the
collection structure, then it's highly likely that threads will run
without any locking contention whatsoever.

As usual, the answer is, "It depends." It depends upon the answers to
those questions, above.

Mar 28 '07 #9
"Mark S." <ma***@yahoo.co mwrote in message news:Oi******** ******@TK2MSFTN GP06.phx.gbl...
>Just curious how you are stress testing this.

In the beginning I used Web Application Stress Tool but to be honest I don't remember the
exact numbers, but it was in the ballpark.
I see, that means that (IMO) the shared hashtable lockings aren't the real bottleneck, isn't
it?, if they were, you would have topped at approx. the same figures you are seeing now.
I would suggest you to profile your application on a staging server, in order to pin-point
the bottleneck. Another option is to take regular snap-shot dumps of the running application
using adplus.vbs and investigate the dump off-line using Windbg.exe and sos.dll.

Willy.

Mar 28 '07 #10

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

Similar topics

31
2535
by: N.Davis | last post by:
I am very new to Python, but have done plenty of development in C++ and Java. One thing I find weird about python is the idea of a module. Why is this needed when there are already the ideas of class, file, and package? To my mind, although one CAN put many classes in a file, it is better to put one class per file, for readability and maintainability. One can then create packages and libraries, using groups of files, one
5
1871
by: shablool | last post by:
Hi all, Could someone please explain what is wrong with this code (the compiler complains about "'int_type' is not a member of 'B'"): struct B; template <typename DerivedT> struct A {
4
8355
by: Anders Borum | last post by:
Hello! I have a list of singleton classes (model managers) that store objects internally using hashtables. Each of these classes use a single hashtable to store e.g. users, pages, elements and so on (I have complete control of the objects stored). I am currently using a set of abstract cache classes that my model managers subclass. The hashtable in a model managers could, potentially, store more than 25.000 objects (let's imagine...
3
1622
by: Greg Oetker via .NET 247 | last post by:
I have an issue where I have some structs and do to the slowsearching for a match of a unsorted Array I need to useHashtables. The issue comes into play when I want to modify thecontents of the struct once a Hashtable has been created. Sample Code: ============ struct SomethingElse { public string Test; public string ItsBroke;
13
5060
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
1
1513
by: Curtis | last post by:
Does anyone know the proper method to save information to embedded hashtables. I am trying to save parent/child information to hashtables but I am not getting the correct results I have made a very simplified example of problem with the following code: Dim cust As New Hashtable Dim invoice As New Hashtable Dim invoiceLines As New Hashtable
669
26234
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
18
1984
by: cj | last post by:
members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. I'm under the impression before you can use a class you have to make an instance of it. So how can a class be threadsafe by itself but an instance of it not be? I guess I don't get what exactly being threadsafe means. Multiple theads can use the same instance of a class?
4
2994
by: DBC User | last post by:
I have a class with bunch of static methods. I could regourp all the static methods into seperate 3 or 4 classes. I was thinking about using Singlton pattern for all these 4 classes so that it behaves like static still class. But my concern is, when going from static to singlton, I need to add one more line to make sure the class is instantiated. Am I going in right direction? Thanks for the help.
0
9666
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9511
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
10200
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
10139
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
5418
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
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
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.