views:

219

answers:

3

I am currently designing a website in C#, which uses some very complex code to generate a search list, which I am currently designing as a Tree-like structure.

The main reason I am using a tree is the fact that this website is high-traffic and has a very complex search filter, which means scalability is very important, however I am worried that the memory requirements of the tree may outweigh the effective processing requirements of simply recalculating values every time.

Does anyone know of a reliable way to measure the size of a dictionary in C#? The Marshal.SizeOf() method will not allow this as the code is not unmanaged.

Cheers, Ed

A: 

One way to do it ... initialize your tree with an arbitrary number of elements, measure the memory size consumed by the process, add 1000 new elements, measure the memory size again, subtract and divide.

Alexandru Nedelcu
I think that's a little too inaccuarate for my boss, although it's a feasible option
Ed Woodcock
+2  A: 

best bet is to run load on the site under different models and check the relevant performance counters.

As a simplification you could extract just the code that creates and stores data structures, and embed that into a console application. Run a simulated load and check the perf counters there. You can vary things and measure the impact on memory consumption and garbage collection. Doing this would isolate the effects you want to measure.

If you're thinking, "gee, that sounds like a lot of work," then you are better off just buying more memory.

Cheeso
That does sound like a lot of work, but I'm not sure that buying more memory is going to work, given that there can easily be a few hundred thousand objects in the dictionary!
Ed Woodcock
Not really too much work. Write the code that simulates different scenarios and strategies. Run each strategy through multiple sessions, each session for 5-10 minutes or more, and query the important perf counters every 15 or 20 seconds. At the end of the run, automatically produce excel sheets and charts with the output for each cycle. When you have all this set up, Push the start button. Go to lunch... Come back 3 hours later.
Cheeso
That sounds like a good plan, I'll give myself a day to do it later in the build!
Ed Woodcock
A: 

You could be to create a small app with a single Dictionary, and then analyze it in several scenarios using WinDbg or ClrProfiler.

I don't think there is a way to get the total size of the object in run-time (apart from raversing internal fields using reflection?)

Groo