+2  A: 

Well, you have to remember that the DataSet is going to be in memory, and to search over the DataSet, it's going to take a lot of CPU cycles to find the records you are looking for.

Add to that the fact that since this is a web application, you are going to get a lot of hits, so you are going to end up calling this routine very, very often.

My recommendation would be to store the hit counts in a database server and then update and query the server to see if the hit count is exceeded. It will be able to handle the load, as well as handle the size of the data set that you are going to query.

casperOne
A: 

Thanks for the quick response casperOne. I was considering that method as well. I might install a local version of SQL server, so that I am not using the network for these lookups. In doing so, will I increase disk IOs? Or since the life of the individual rows is only 5 minutes, will the table stay in memory and never actually be written to disk?

This is kind of a seperate question, so I will move this to a new thread if you think I should.

Thanks again for the help.

C

regex
+1  A: 

There are a couple things that I'd try:

  • The first thing I see is that you're calling the "DeleteOldEntries" sub every time this code is run, which causes it to do a scan through the entire DataTable on every pass. Is there another way you could limit this to only run at certain times? If not a timer that runs it every 15 seconds, then maybe a second variable in the state (like "ExecCount") that increments every time "CheckHitCount" is run, so that you only purge every 10th or 20th time through? This way, you can avoid this potentially expensive section of the code on every run.
  • Another option is adding an index to your DataTable. I'm not sure how .NET handles lookups in DataTables, but perhaps this would be of interest to you: MSDN Article

Can you use something like ANTS Profiler to see where the most time is spent during execution? Since I imagine this page is being called many, many times/second, any way you can lower the impact even a little would make a big difference.

If you get some results but still aren't happy, make sure you modify your question to add the new info so we can keep working towards a solution that you're happy with.

rwmnau