473,803 Members | 4,157 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
14 1797
"Mark S." <ma***@yahoo.co mwrote in message
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.
If you're only getting 5 requests per second, then I suspect you're doing
alot more than reading & writing values to a hashtable.

If that is in fact all you're doing, and you're only getting 5 requests per
second, you need to re-evaluate your algorithm from the ground up, as you
should be getting a number that requires scientific notation to properly
describe.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise , Microsoft C# MVP
http://www.coversant.com/blogs/cmullins
Mar 28 '07 #11
Chris,

You're right, but failed to accurately describe my numbers, below I've
reposted the carination. It clarification runs really fast 400 get requests
a second takes 35% CPU.

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
Mar 29 '07 #12
Bruce,

I think you're on to something good here. Let's see what we can come up
with.
1. What are the keys in the hash table? What do they represent?
3. How are they structured?
The keys are GUID and they represent a collection data. A background process
grabs xml from the database and massages it into a struct of arrays.

So the keys are GUID and the values are a struct.

public static Hashtable myHash = Hashtable.Synch ronized(new Hashtable());

public struct myStruct
{
public string html;
}

public static String myLogic(String targetID) {
if (myHash.Contain s(targetID))
{
lock (myHash.SyncRoo t)
{
struct myStruct = (struct)myHash[targetID];
// read data, make decisions based on data, update struct with
results
// struct of arrays greatly simplifed for sake of this
conversation
return myStruct.html;
}
}
}

2. How many keys can there be?
Currently 208, but that will grow to 500 in a couple months and in six
months up to 1000.

4. How (and when) can new keys be created?
Whenever data entry admins change data in the database the hashTable is
updated. This happens a couple hundred times a day. A background process
reads the live hash table, corrilates it's data with the incoming data,
contructs a new seperate hashTable, and once complete, locks the live
hashTable and does a quick swap.


Mar 29 '07 #13
Hi Mark,

would it be a problem, if between the reads and the writes of one request
there are writes of other request?
If so, you should not lock on the Hashtable, while processing the data, but
only the writes and the reads.
Otherwise, you should try to limit the data locked, f.e. only lock the key
while processing. Not easy to do, if the key is of a value type. So, an
alternative would be, to use a class as data and lock on that instance.

If serializing only the reading and writing of the data gives you this
problem, then I suppose, you have to redesign your datastructure.

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 29 '07 #14
On Mar 28, 11:48 pm, "Christof Nordiek" <c...@nospam.de wrote:
Hi Mark,

would it be a problem, if between the reads and the writes of one request
there are writes of other request?
If so, you should not lock on the Hashtable, while processing the data, but
only the writes and the reads.
Otherwise, you should try to limit the data locked, f.e. only lock the key
while processing. Not easy to do, if the key is of a value type. So, an
alternative would be, to use a class as data and lock on that instance.
OK... that beats my idea hands down.

Christof is right: you have two locking scenarios here:

1. Adding a new key to the hash table: need to lock the whole table.

2. Manipulating the data structure that is under one key: make it a
class and lock the instance in the hash table.

The very fact that you want to manipulate the data that's already in
the hash table, rather than just writing it once and possibly deleting
it later, says that you want these to be classes, not structs. Plus,
by making them classes, you get the added benefit that you can lock on
them.

So now you can have one thread updating one instance and another
thread updating another instance and they won't collide.

The only time you need to lock the whole thing is when you add a new
key and when you're fetching instances to update. If even this
contention is too much for you, then you can move to the solution I
proposed: roll your own hash table structure, and allow for locking on
individual hash buckets. If you do this, then the pseudo-code would
be: calculate hash value for GUID, calculate bucket index from hash
value, lock bucket, fetch data instance, lock data instance, unlock
bucket, update data instance, unlock data instance. This improves
concurrency because a thread that is manipulating / searching the hash
chain at bucket #15 isn't in contention for a lock with another thread
that is manipulating / searching the hash chain at bucket #3, and even
if threads are updating class instances in the same chain, they need
to lock the bucket only long enough to find the item they want to
update.

If you allow for deletions from the hash table, then the thread doing
the deletion has to lock both the table (or the bucket) _and_ the item
to be deleted, to ensure that nobody else is updating the item while
it's being deleted.

Mar 29 '07 #15

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

Similar topics

31
2540
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
8357
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
5063
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
1514
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
26255
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
1986
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
2995
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
9703
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
10548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
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
10295
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
10069
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...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
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...
2
3798
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.