Saturday, March 24, 2012

web.config vs. application object

In ASP.NET web application, where is the best place
to store a application scope variable?(read only)
Web.Config file or application object?
Which performance is better while reading the data?Well, you should initially store them in the web.config to make them easier
to change. You can then read them out of there into the Application() object
on Start. Web.Config data is cached in memory after the first
read...Application is probably faster, but if so it's by a very very very
small amount. I'd sick with web.config.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/

"RedHair" <redhair@.u.s.a> wrote in message
news:OgjMBS4TGHA.2156@.tk2msftngp13.phx.gbl...
> In ASP.NET web application, where is the best place
> to store a application scope variable?(read only)
> Web.Config file or application object?
> Which performance is better while reading the data?
Thanks.
Currently, I'm doing the same way as your suggestion, store them in
web.config
but read and store them in app object in app_start event, I just wonder if
this is
a redundant step?

By the way, if both web.config data and app object are cached in memory, how
come reading from app object will be faster?

"Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%23KH8cn4TGHA.5836@.TK2MSFTNGP10.phx.gbl...
> Well, you should initially store them in the web.config to make them
> easier to change. You can then read them out of there into the
> Application() object on Start. Web.Config data is cached in memory after
> the first read...Application is probably faster, but if so it's by a very
> very very small amount. I'd sick with web.config.
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "RedHair" <redhair@.u.s.a> wrote in message
> news:OgjMBS4TGHA.2156@.tk2msftngp13.phx.gbl...
>> In ASP.NET web application, where is the best place
>> to store a application scope variable?(read only)
>> Web.Config file or application object?
>> Which performance is better while reading the data?
>>
I think it's redudant.

I'm only guessing at the speed...web.config might be faster. But I'm
thinking the configuration structure is more complicated than the Hashtable
structure the Application object uses. Maybe it isn't. Maybe AppConfig uses
a NameValueCollection which would likely be even faster. For example,
retrieving an int (which is sitting on the stack) is going to be faster than
getting an dataset...even though they both sit in memory :)

Also, if you are looking to get the most out of your configuration, take a
look at:
http://openmymind.net/index.aspx?documentId=5

Karl
--
http://www.openmymind.net/

"RedHair" <redhair@.u.s.a> wrote in message
news:uxAjAH7TGHA.5836@.TK2MSFTNGP10.phx.gbl...
> Thanks.
> Currently, I'm doing the same way as your suggestion, store them in
> web.config
> but read and store them in app object in app_start event, I just wonder if
> this is
> a redundant step?
> By the way, if both web.config data and app object are cached in memory,
> how
> come reading from app object will be faster?
>
> "Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
> net> wrote in message news:%23KH8cn4TGHA.5836@.TK2MSFTNGP10.phx.gbl...
>> Well, you should initially store them in the web.config to make them
>> easier to change. You can then read them out of there into the
>> Application() object on Start. Web.Config data is cached in memory after
>> the first read...Application is probably faster, but if so it's by a
>> very very very small amount. I'd sick with web.config.
>>
>> Karl
>>
>> --
>> http://www.openmymind.net/
>> http://www.fuelindustries.com/
>>
>>
>> "RedHair" <redhair@.u.s.a> wrote in message
>> news:OgjMBS4TGHA.2156@.tk2msftngp13.phx.gbl...
>>> In ASP.NET web application, where is the best place
>>> to store a application scope variable?(read only)
>>> Web.Config file or application object?
>>> Which performance is better while reading the data?
>>>
>>
>>
Thanks for your reply.
Do you know how to calculate the memory occupied by a app object?
It depends on the data length?

"Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
net> glsD:%23ORPb18TGHA.4772@.TK2MSFTNGP09.phx .gbl...
>I think it's redudant.
> I'm only guessing at the speed...web.config might be faster. But I'm
> thinking the configuration structure is more complicated than the
> Hashtable structure the Application object uses. Maybe it isn't. Maybe
> AppConfig uses a NameValueCollection which would likely be even faster.
> For example, retrieving an int (which is sitting on the stack) is going to
> be faster than getting an dataset...even though they both sit in memory :)
> Also, if you are looking to get the most out of your configuration, take a
> look at:
> http://openmymind.net/index.aspx?documentId=5
> Karl
> --
> http://www.openmymind.net/
>
> "RedHair" <redhair@.u.s.a> wrote in message
> news:uxAjAH7TGHA.5836@.TK2MSFTNGP10.phx.gbl...
>> Thanks.
>> Currently, I'm doing the same way as your suggestion, store them in
>> web.config
>> but read and store them in app object in app_start event, I just wonder
>> if this is
>> a redundant step?
>>
>> By the way, if both web.config data and app object are cached in memory,
>> how
>> come reading from app object will be faster?
>>
>>
>>
>> "Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
>> net> wrote in message news:%23KH8cn4TGHA.5836@.TK2MSFTNGP10.phx.gbl...
>>> Well, you should initially store them in the web.config to make them
>>> easier to change. You can then read them out of there into the
>>> Application() object on Start. Web.Config data is cached in memory after
>>> the first read...Application is probably faster, but if so it's by a
>>> very very very small amount. I'd sick with web.config.
>>>
>>> Karl
>>>
>>> --
>>> http://www.openmymind.net/
>>> http://www.fuelindustries.com/
>>>
>>>
>>> "RedHair" <redhair@.u.s.a> wrote in message
>>> news:OgjMBS4TGHA.2156@.tk2msftngp13.phx.gbl...
>>>> In ASP.NET web application, where is the best place
>>>> to store a application scope variable?(read only)
>>>> Web.Config file or application object?
>>>> Which performance is better while reading the data?
>>>>
>>>
>>>
>>
>>
There's no API to do so. There are ways, such as using a memory profile or a
using pointer arithmetics. You can learn more from:
http://blogs.msdn.com/cbrumme/archi...4/15/51326.aspx

but I doubt you'll find anything meaningful to your needs (it's an
interesting read though!).

Karl

--
http://www.openmymind.net/

"RedHair" <redhair@.ms40.url.com.tw> wrote in message
news:OeN0VXHUGHA.5552@.TK2MSFTNGP14.phx.gbl...
> Thanks for your reply.
> Do you know how to calculate the memory occupied by a app object?
> It depends on the data length?
>
> "Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
> net> glsD:%23ORPb18TGHA.4772@.TK2MSFTNGP09.phx .gbl...
>>I think it's redudant.
>>
>> I'm only guessing at the speed...web.config might be faster. But I'm
>> thinking the configuration structure is more complicated than the
>> Hashtable structure the Application object uses. Maybe it isn't. Maybe
>> AppConfig uses a NameValueCollection which would likely be even faster.
>> For example, retrieving an int (which is sitting on the stack) is going
>> to be faster than getting an dataset...even though they both sit in
>> memory :)
>>
>> Also, if you are looking to get the most out of your configuration, take
>> a look at:
>> http://openmymind.net/index.aspx?documentId=5
>>
>> Karl
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "RedHair" <redhair@.u.s.a> wrote in message
>> news:uxAjAH7TGHA.5836@.TK2MSFTNGP10.phx.gbl...
>>> Thanks.
>>> Currently, I'm doing the same way as your suggestion, store them in
>>> web.config
>>> but read and store them in app object in app_start event, I just wonder
>>> if this is
>>> a redundant step?
>>>
>>> By the way, if both web.config data and app object are cached in memory,
>>> how
>>> come reading from app object will be faster?
>>>
>>>
>>>
>>> "Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
>>> net> wrote in message news:%23KH8cn4TGHA.5836@.TK2MSFTNGP10.phx.gbl...
>>>> Well, you should initially store them in the web.config to make them
>>>> easier to change. You can then read them out of there into the
>>>> Application() object on Start. Web.Config data is cached in memory
>>>> after the first read...Application is probably faster, but if so it's
>>>> by a very very very small amount. I'd sick with web.config.
>>>>
>>>> Karl
>>>>
>>>> --
>>>> http://www.openmymind.net/
>>>> http://www.fuelindustries.com/
>>>>
>>>>
>>>> "RedHair" <redhair@.u.s.a> wrote in message
>>>> news:OgjMBS4TGHA.2156@.tk2msftngp13.phx.gbl...
>>>>> In ASP.NET web application, where is the best place
>>>>> to store a application scope variable?(read only)
>>>>> Web.Config file or application object?
>>>>> Which performance is better while reading the data?
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>

0 comments:

Post a Comment