Dictionary/Client VS Application Variables
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?
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.
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).
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.
精彩评论