views:

107

answers:

3

Hi i got a question about my server performance ... i got a classic asp cms hosting ~250 websites, for each website we build a Classic ASP dictionary using

set dict = CreateObject("Scripting.Dictionary") 
dict.add "test1","Value Test1"
dict.add "test2","Value Test2"
dict.add "test3","Value Test3"

that dictionary is then loaded on every page for every user ...

lets say we got about ~150 000 users visiting those websites monthly loading those dictionary of about ~100k each every load ...

should i use application variable as dictionary instead of loading my dictionary every time?

and is it really gonna improve my server performance?

+1  A: 

I'd absolutely suggest loading the dictionary only the one time, as the Dictionary object is heavy in terms of memory, slow in terms of lookup and the big one: isn't always destroyed in memory when you think it should be. Thus even after a user has left the page this object can still linger in memory waiting to be disposed of (even if you explicitly "destroy" it). Now multiply that times number of page hits per visit per user...

An alternative and more memory-light method would be to use an array -- one-dimensional if you can maintain track of the index somewhere (best), or two-dimensional with a lookup function if you need to (certainly if others are maintaining the code now or in the future).

Cirieno
good point unfortunately i think an array would be slower to pick infos in when it grows bigger since the dictionary is indexed anyway i will be trying to load it one time in the application variable and see what happen thx for your time
Lil'Monkey
"isn't always destroyed in memory when you think it should be" where did you get this information from??
AnthonyWJones
LM: The array would be faster as you would call it directly using the index (from 0 to n) instead of having to do a lookup on the key as you do with a Dictionary object (assuming that's why you have the "test1/2/3" keys.As an aside: remember that your server (machine or IIS) can be restarted at any time and when it does any application vars will no longer exist, so ensure your mechanism checks for the object first and if it's not there then creates and repopulates it automatically.
Cirieno
AWJ: Discussions with a developer who has wide experience in more languages than I can remember and who has in the past run his own tests on VB memory management. There are all sorts of annoying caveats that means the contents of variables and objects can linger long after you might expect VB to have dropped them. I know I've been tripped up by un-obvious memory leaks before.
Cirieno
the array would be faster if i call it directly unfortunately since its a CMS im not the one making the calls so the keys need to be strings so the ppk making their website can use keyworkd like "Total_Price" as label keys. as for the server reboot i allreatdy tought about that i added an application variable called needRebuild if needRebuild is different than "no" i rebuild my whole dictionary in the application variables. anyway our server is rarely rebuilded so it should not impact performances
Lil'Monkey
rebooted* (sorry cant type)
Lil'Monkey
+1  A: 

I'm pretty sure that instantiating a single scripting.dictionary on each page shouldn't be a problem on any website. If performance is an issue I suggest profiling youre page first to see where the problem is. Big chance there is an unoptimised query somewhere taking 100+ ms to finish.

We run a classic ASP site that handles 200k pageviews a day and use scriping.dictionary extensively on every page (25+ instances). We use it as a base for all kinds of things. Do you have any example script to show that the dict's aren't always destroyed by the garbagecollector? Or that it's lookups are slow compared to any alternative? The only inconvenience we encountered is the lack of a 'clone' method.

Joost Moesker
the issue was not performance itself but im always looking to improve my code and give a break to the server. i jsut had that crazy idea of using application variable instead of rebuilding my dctionary on every page view and was looking for some input (if it was a good idea or not)
Lil'Monkey
I suppose, as Jeff Atwood has commented on his blog before, these days servers are so powerful (and cheap to add more processing power) that code optimisation is no longer needed as much as when I learned to code...
Cirieno
might not be needed as much dosent mean its not important ;)
Lil'Monkey
+2  A: 

Certainly loading a dictionary for every ASP request is definitely a bad idea and will be hurting not only your performance but also fragmenting your Virtual Memory.

Using an array instead still has much the same problem, each request would need to allocate all the memory needed to hold it and it still needs populating on each request.

The simple answer would be yes use the application object as the dictionary. This will cost you much less in memory and CPU. The downside is does it collide with existing application object usage? You may need to prefix your keys in order to avoid this problem.

AnthonyWJones
Lil'Monkey