473,624 Members | 2,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

aspnet_state.ex e Internals Info Needed

I noticed when storing large amounts of information in the StateServer
Service that this does not increase in size, the worker process itself seems
to grow.

I set up a test case to try and prove this, I placed a button on a web form
that ran the foloowing code.
string temp = "index";

for(int i = 0; i < 1000000; i++)
{
string index = temp + i.ToString();
Session[index] = "This is a Test";
}

I notices that the aspnet_state.ex e's Mem Usage and VM Size barely grew yet
my W3WP process grew to the point that I had to stop my app (yes my own
fault iterating 1M times).

I thought the State Server actually stored the session data itself, it would
seem from my example that this is not the case and that the memory space
used is that of the W3WP.

Does the State Server only act as a marchalling services pointing requests
for Session info to the correct memory location? If this is the case how
does it persist when an ASP.NET app is recycled.

Is that portion of memory allocated to storing the Session held back while
the ASP.NET app is recycled?

I've been trying to find information on how the State Server works
internally but as yet have found nothing.

TIA

MattC


Nov 19 '05 #1
6 3638
Matt:
Thanks for asking, I learnt a lot by trying to find the answer. I strongly
suspected that objects didn't immediatly stream to the state server when
added - but instead were held in memory and only streamed to the state
servrer at a certain point. After doing some digging, I found out this is
what's happening. Here's a breakdown:

-Session state is managed by an HttpModule called SessionStateMod ule
-Items are only truly added to their stores during the ReleaseRequestS tate
event, which as per msdn "Occurs after ASP.NET finishes executing all
request handlers. This event causes state modules to save the current state
data"
-Depending on which type of storage you use, different things happen. In
the case of state server, the session information is serilized into memory
(asp.net) and then some stuff taht confused me happened (presumably the
actual storage to the state server)
So, basically all those objects are stored in memory than serialized (in
memory) and sent to state server. As you can see, a lot is happening in the
asp.net memory (w3wp.exe). However, you'd think that after the page is done
loading that memory consumption would go back down. But it probably
doesn't. This is because the garbage collector hasn't passed yet.
Remember, memory won't be reclaimed until its needed. So if you lower your
loop so that it can finish, you'll see the memory go up and stay up. The
memory goes up because initially all the items are help in-memory, it stays
up because the GC hasn't passed yet.

If you change ur code to:
for (int i = 0; i < 800000; i++)
{
string index = "index" + i.ToString();
Session[index] = "This is a Test";
}
GC.Collect();
GC.WaitForPendi ngFinalizers();
GC.Collect();
GC.WaitForPendi ngFinalizers();
GC.Collect();
GC.WaitForPendi ngFinalizers();

you'll hopefully see better results (but even then it isn't
guaranteed)...d on't do anything for a minute or so and you should see it go
back down :)

Also, don't use task manager..instea d load up perfmon and go to .Net
Memory, select "# of bytes in heap" and select the w3wp.exe process...will
give you a much better idea :)

Hope that helped,
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"MattC" <m@m.com> wrote in message
news:ux******** ******@TK2MSFTN GP10.phx.gbl...
I noticed when storing large amounts of information in the StateServer
Service that this does not increase in size, the worker process itself seems to grow.

I set up a test case to try and prove this, I placed a button on a web form that ran the foloowing code.
string temp = "index";

for(int i = 0; i < 1000000; i++)
{
string index = temp + i.ToString();
Session[index] = "This is a Test";
}

I notices that the aspnet_state.ex e's Mem Usage and VM Size barely grew yet my W3WP process grew to the point that I had to stop my app (yes my own
fault iterating 1M times).

I thought the State Server actually stored the session data itself, it would seem from my example that this is not the case and that the memory space
used is that of the W3WP.

Does the State Server only act as a marchalling services pointing requests
for Session info to the correct memory location? If this is the case how
does it persist when an ASP.NET app is recycled.

Is that portion of memory allocated to storing the Session held back while
the ASP.NET app is recycled?

I've been trying to find information on how the State Server works
internally but as yet have found nothing.

TIA

MattC

Nov 19 '05 #2
Karl,

Excellent, thanks for your response.

1.) Could you post some of the links for the articles you found.

2.) I am having to persist my viewstate into the session, overloading the
SavePageStateTo PersistenceMedi um and
LoadPageStateTo PersistenceMedi um methods. Even after many many requests the
W3WP process doesnt seem to go down and similarly my aspnet_state.ex e doesnt
seem to rise.

Is there any way I can call to have a particular session insertion
serialized immediately?

I suspect that as my CPU is now working to its maximum due to the fact that
it is having to do HTTP compression and serialize/deserialize plus search
for session data it is having trouble finding the time to a.) Serialize to
the state server, b.) Garbage collect the temporary memory allocated in the
worker process.

My server is an old PIII 730 w/256MB Ram, W2K3 Server, IIS6.

Would this fit your theory?

Finally, can I created a method that is wired to the requesthandlers
complete event?

TIA

MattC
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OY******** *****@TK2MSFTNG P15.phx.gbl...
Matt:
Thanks for asking, I learnt a lot by trying to find the answer. I
strongly
suspected that objects didn't immediatly stream to the state server when
added - but instead were held in memory and only streamed to the state
servrer at a certain point. After doing some digging, I found out this is
what's happening. Here's a breakdown:

-Session state is managed by an HttpModule called SessionStateMod ule
-Items are only truly added to their stores during the ReleaseRequestS tate
event, which as per msdn "Occurs after ASP.NET finishes executing all
request handlers. This event causes state modules to save the current
state
data"
-Depending on which type of storage you use, different things happen. In
the case of state server, the session information is serilized into memory
(asp.net) and then some stuff taht confused me happened (presumably the
actual storage to the state server)
So, basically all those objects are stored in memory than serialized (in
memory) and sent to state server. As you can see, a lot is happening in
the
asp.net memory (w3wp.exe). However, you'd think that after the page is
done
loading that memory consumption would go back down. But it probably
doesn't. This is because the garbage collector hasn't passed yet.
Remember, memory won't be reclaimed until its needed. So if you lower
your
loop so that it can finish, you'll see the memory go up and stay up. The
memory goes up because initially all the items are help in-memory, it
stays
up because the GC hasn't passed yet.

If you change ur code to:
for (int i = 0; i < 800000; i++)
{
string index = "index" + i.ToString();
Session[index] = "This is a Test";
}
GC.Collect();
GC.WaitForPendi ngFinalizers();
GC.Collect();
GC.WaitForPendi ngFinalizers();
GC.Collect();
GC.WaitForPendi ngFinalizers();

you'll hopefully see better results (but even then it isn't
guaranteed)...d on't do anything for a minute or so and you should see it
go
back down :)

Also, don't use task manager..instea d load up perfmon and go to .Net
Memory, select "# of bytes in heap" and select the w3wp.exe process...will
give you a much better idea :)

Hope that helped,
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"MattC" <m@m.com> wrote in message
news:ux******** ******@TK2MSFTN GP10.phx.gbl...
I noticed when storing large amounts of information in the StateServer
Service that this does not increase in size, the worker process itself

seems
to grow.

I set up a test case to try and prove this, I placed a button on a web

form
that ran the foloowing code.
string temp = "index";

for(int i = 0; i < 1000000; i++)
{
string index = temp + i.ToString();
Session[index] = "This is a Test";
}

I notices that the aspnet_state.ex e's Mem Usage and VM Size barely grew

yet
my W3WP process grew to the point that I had to stop my app (yes my own
fault iterating 1M times).

I thought the State Server actually stored the session data itself, it

would
seem from my example that this is not the case and that the memory space
used is that of the W3WP.

Does the State Server only act as a marchalling services pointing
requests
for Session info to the correct memory location? If this is the case how
does it persist when an ASP.NET app is recycled.

Is that portion of memory allocated to storing the Session held back
while
the ASP.NET app is recycled?

I've been trying to find information on how the State Server works
internally but as yet have found nothing.

TIA

MattC


Nov 19 '05 #3
Hey Matt,
Check out http://www.thecodeproject.com/aspnet...nInternals.asp
it's just a starter...and there's no "part 2" as the author promises. Most
of my research came from digging into the .net code with Reflector and
getting an understanding of the internals.

My initial suspicion is still that the GC simply isn't running, but it's
possible that you do ahve a memory leak (managed or not)...you can check out
http://blogs.msdn.com/akhune/archive...11/153734.aspx as a starting
point for this.

Also, I wouldn't/couldn't say that those are the reasons your CPU is maxing
out (certainly if you are looping 1million times per page hit, that might be
worth investigating too ;) ). I've certainly seen HTTP Compression take a
chunk out of CPU cycles...so simply try turning it off and see if it's any
better? Similarly, simply try to turn off the server-side viewstate and
observe the effect. Your box certainly is old and I would simply suspect
that it'll be able to handle a certain load and no more...if you are trying
to run an application where you feel the need to simulate 1million session
entries, you likely need more hardware...

If the basic stuff doen't work (although I'm hoping turning off
HttpCompression for testing will ease the cpu a lot), get a profiler and
take a spin in your code. Ant's profiler is my prefered tool, and comes
with a full 14 day trial:
http://www.red-gate.com/code_profiling.htm

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"MattC" <m@m.com> wrote in message
news:O8******** ******@TK2MSFTN GP15.phx.gbl...
Karl,

Excellent, thanks for your response.

1.) Could you post some of the links for the articles you found.

2.) I am having to persist my viewstate into the session, overloading the
SavePageStateTo PersistenceMedi um and
LoadPageStateTo PersistenceMedi um methods. Even after many many requests the W3WP process doesnt seem to go down and similarly my aspnet_state.ex e doesnt seem to rise.

Is there any way I can call to have a particular session insertion
serialized immediately?

I suspect that as my CPU is now working to its maximum due to the fact that it is having to do HTTP compression and serialize/deserialize plus search
for session data it is having trouble finding the time to a.) Serialize to
the state server, b.) Garbage collect the temporary memory allocated in the worker process.

My server is an old PIII 730 w/256MB Ram, W2K3 Server, IIS6.

Would this fit your theory?

Finally, can I created a method that is wired to the requesthandlers
complete event?

TIA

MattC
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OY******** *****@TK2MSFTNG P15.phx.gbl...
Matt:
Thanks for asking, I learnt a lot by trying to find the answer. I
strongly
suspected that objects didn't immediatly stream to the state server when
added - but instead were held in memory and only streamed to the state
servrer at a certain point. After doing some digging, I found out this is what's happening. Here's a breakdown:

-Session state is managed by an HttpModule called SessionStateMod ule
-Items are only truly added to their stores during the ReleaseRequestS tate event, which as per msdn "Occurs after ASP.NET finishes executing all
request handlers. This event causes state modules to save the current
state
data"
-Depending on which type of storage you use, different things happen. In the case of state server, the session information is serilized into memory (asp.net) and then some stuff taht confused me happened (presumably the
actual storage to the state server)
So, basically all those objects are stored in memory than serialized (in
memory) and sent to state server. As you can see, a lot is happening in
the
asp.net memory (w3wp.exe). However, you'd think that after the page is
done
loading that memory consumption would go back down. But it probably
doesn't. This is because the garbage collector hasn't passed yet.
Remember, memory won't be reclaimed until its needed. So if you lower
your
loop so that it can finish, you'll see the memory go up and stay up. The memory goes up because initially all the items are help in-memory, it
stays
up because the GC hasn't passed yet.

If you change ur code to:
for (int i = 0; i < 800000; i++)
{
string index = "index" + i.ToString();
Session[index] = "This is a Test";
}
GC.Collect();
GC.WaitForPendi ngFinalizers();
GC.Collect();
GC.WaitForPendi ngFinalizers();
GC.Collect();
GC.WaitForPendi ngFinalizers();

you'll hopefully see better results (but even then it isn't
guaranteed)...d on't do anything for a minute or so and you should see it
go
back down :)

Also, don't use task manager..instea d load up perfmon and go to .Net
Memory, select "# of bytes in heap" and select the w3wp.exe process...will give you a much better idea :)

Hope that helped,
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"MattC" <m@m.com> wrote in message
news:ux******** ******@TK2MSFTN GP10.phx.gbl...
I noticed when storing large amounts of information in the StateServer
Service that this does not increase in size, the worker process itself

seems
to grow.

I set up a test case to try and prove this, I placed a button on a web

form
that ran the foloowing code.
string temp = "index";

for(int i = 0; i < 1000000; i++)
{
string index = temp + i.ToString();
Session[index] = "This is a Test";
}

I notices that the aspnet_state.ex e's Mem Usage and VM Size barely grew

yet
my W3WP process grew to the point that I had to stop my app (yes my own
fault iterating 1M times).

I thought the State Server actually stored the session data itself, it

would
seem from my example that this is not the case and that the memory space used is that of the W3WP.

Does the State Server only act as a marchalling services pointing
requests
for Session info to the correct memory location? If this is the case how does it persist when an ASP.NET app is recycled.

Is that portion of memory allocated to storing the Session held back
while
the ASP.NET app is recycled?

I've been trying to find information on how the State Server works
internally but as yet have found nothing.

TIA

MattC



Nov 19 '05 #4
Matt:
I can't say I can see anything. Is the LosFormatter really necessary? Your
storing the viewstate in the session i wouldn't expect it to need to be
serlialized...u nless the state server can't automatically serialize it
itself...even if it doesn't, not sure LosFormatter is the quickest (though
it very well could be, I'd check both issues).

I noticed that you aren't properly disposing of your StringWriter... but I
doubt that's your problem...

Anyways, atleast I gave you a couple more things to look at :) sorry I
coudlnt' be more help.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"MattC" <m@m.com> wrote in message
news:OH******** ******@TK2MSFTN GP14.phx.gbl...
Karl,

Last night I tried runing with server side viewstate off, indeed the server was fine, the processor was much less under pressure, and the memory usage
was constant. Which means there must be a leak in my viewstate persistance code (below).
My problem is that I have a timesheet data entry page for the application.
Users can make entries for each day, selecting an activity, each activity
requires a different set of boxes, this requires a postback. So they may
have 50/60 postbacks per session. All being persisted to the session.

private string NewViewState
{
get{ return "VIEWSTATE_ "; }
}

private string ViewStateKey
{
get{ return "__VIEWSTATE_KE Y"; }
}

private string UniqueViewState Key
{
get{ return NewViewState + Request.UserHos tAddress + "_" +
Guid.NewGuid(). ToString(); }
}

protected override void SavePageStateTo PersistenceMedi um(object viewState) {
try
{
if(Conquest.Con figurationData. ViewStateStorag e ==
ViewStateStorag e.Session)//if we are implementing our on server viewstate
{
string str = this.UniqueView StateKey;
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.S erialize(oStrin gWriter, viewState);//serialize viewstate into string writer
oLosFormatter = null;

Session[str] = oStringWriter.T oString(); //store in state server
oStringWriter = null;

RegisterHiddenF ield(ViewStateK ey, str);
RegisterHiddenF ield("__VIEWSTA TE", String.Empty);
}
else
{
base.SavePageSt ateToPersistenc eMedium(viewSta te);
}
}
catch(Exception e)
{
throw new
ConquestExcepti on("Performance Page.SavePageSt ateToPersistenc eMedium Failed", null, e);
}
}

protected override object LoadPageStateFr omPersistenceMe dium()
{
try
{
if(Conquest.Con figurationData. ViewStateStorag e ==
ViewStateStorag e.Session)//if we are implementing our on server viewstate
{
object viewstate = null;//return viewstate
string str = Request.Form[ViewStateKey];
LosFormatter oLosFormatter = new LosFormatter();

if (!str.StartsWit h(NewViewState) ) //check the viewstate exists
{
Conquest.Events .WriteToLog("Fa iled to locate VIEWSTATE KEY: '" + str
+"'");
ViewStatePersis tanceFailure(st r);//failure
}
else//view state does exist
{
try
{
string tmp = Session[str].ToString();//get the serialize viewstate
from session
viewstate = oLosFormatter.D eserialize(tmp) ;//deserialize into object oLosFormatter = null;
}
catch(Exception e)//catch all and handle gracefully
{
Conquest.Events .WriteToLog("Fa iled to Load ViewState from " +
Conquest.Config urationData.Vie wStateStorage.T oString() +
" " +
ConquestExcepti on.HandleConque stException(e), System.Diagnost ics.EventLogEnt r
yType.Informati on);
ViewStatePersis tanceFailure(st r);//Response.Redire ct to homepage
}
}
//return what we got from deserialized viewstate
return viewstate;
}
else //use standard viewstate
{
return base.LoadPageSt ateFromPersiste nceMedium();
}
}
catch(Exception e)
{
throw new
ConquestExcepti on("Performance Page.LoadPageSt ateFromPersiste nceMedium
failed", null, e);
}
}
TIA

MattC
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hey Matt,
Check out http://www.thecodeproject.com/aspnet...nInternals.asp it's just a starter...and there's no "part 2" as the author promises.
Most
of my research came from digging into the .net code with Reflector and
getting an understanding of the internals.

My initial suspicion is still that the GC simply isn't running, but it's
possible that you do ahve a memory leak (managed or not)...you can check
out
http://blogs.msdn.com/akhune/archive...11/153734.aspx as a starting point for this.

Also, I wouldn't/couldn't say that those are the reasons your CPU is
maxing
out (certainly if you are looping 1million times per page hit, that might be
worth investigating too ;) ). I've certainly seen HTTP Compression take a
chunk out of CPU cycles...so simply try turning it off and see if it's any better? Similarly, simply try to turn off the server-side viewstate and
observe the effect. Your box certainly is old and I would simply suspect that it'll be able to handle a certain load and no more...if you are
trying
to run an application where you feel the need to simulate 1million session entries, you likely need more hardware...

If the basic stuff doen't work (although I'm hoping turning off
HttpCompression for testing will ease the cpu a lot), get a profiler and
take a spin in your code. Ant's profiler is my prefered tool, and comes
with a full 14 day trial:
http://www.red-gate.com/code_profiling.htm

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"MattC" <m@m.com> wrote in message
news:O8******** ******@TK2MSFTN GP15.phx.gbl...
Karl,

Excellent, thanks for your response.

1.) Could you post some of the links for the articles you found.

2.) I am having to persist my viewstate into the session, overloading the SavePageStateTo PersistenceMedi um and
LoadPageStateTo PersistenceMedi um methods. Even after many many requests
the
W3WP process doesnt seem to go down and similarly my aspnet_state.ex e

doesnt
seem to rise.

Is there any way I can call to have a particular session insertion
serialized immediately?

I suspect that as my CPU is now working to its maximum due to the fact

that
it is having to do HTTP compression and serialize/deserialize plus
search for session data it is having trouble finding the time to a.) Serialize
to
the state server, b.) Garbage collect the temporary memory allocated in

the
worker process.

My server is an old PIII 730 w/256MB Ram, W2K3 Server, IIS6.

Would this fit your theory?

Finally, can I created a method that is wired to the requesthandlers
complete event?

TIA

MattC
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OY******** *****@TK2MSFTNG P15.phx.gbl...
> Matt:
> Thanks for asking, I learnt a lot by trying to find the answer. I
> strongly
> suspected that objects didn't immediatly stream to the state server
> when
> added - but instead were held in memory and only streamed to the state > servrer at a certain point. After doing some digging, I found out this is
> what's happening. Here's a breakdown:
>
> -Session state is managed by an HttpModule called SessionStateMod ule
> -Items are only truly added to their stores during the

ReleaseRequestS tate
> event, which as per msdn "Occurs after ASP.NET finishes executing all
> request handlers. This event causes state modules to save the current
> state
> data"
> -Depending on which type of storage you use, different things happen.

In
> the case of state server, the session information is serilized into

memory
> (asp.net) and then some stuff taht confused me happened (presumably
the > actual storage to the state server)
>
>
> So, basically all those objects are stored in memory than serialized
> (in
> memory) and sent to state server. As you can see, a lot is happening
> in
> the
> asp.net memory (w3wp.exe). However, you'd think that after the page is > done
> loading that memory consumption would go back down. But it probably
> doesn't. This is because the garbage collector hasn't passed yet.
> Remember, memory won't be reclaimed until its needed. So if you lower > your
> loop so that it can finish, you'll see the memory go up and stay up.

The
> memory goes up because initially all the items are help in-memory, it
> stays
> up because the GC hasn't passed yet.
>
> If you change ur code to:
> for (int i = 0; i < 800000; i++)
> {
> string index = "index" + i.ToString();
> Session[index] = "This is a Test";
> }
> GC.Collect();
> GC.WaitForPendi ngFinalizers();
> GC.Collect();
> GC.WaitForPendi ngFinalizers();
> GC.Collect();
> GC.WaitForPendi ngFinalizers();
>
> you'll hopefully see better results (but even then it isn't
> guaranteed)...d on't do anything for a minute or so and you should see
> it
> go
> back down :)
>
> Also, don't use task manager..instea d load up perfmon and go to .Net
> Memory, select "# of bytes in heap" and select the w3wp.exe

process...will
> give you a much better idea :)
>
> Hope that helped,
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "MattC" <m@m.com> wrote in message
> news:ux******** ******@TK2MSFTN GP10.phx.gbl...
>> I noticed when storing large amounts of information in the StateServer >> Service that this does not increase in size, the worker process itself > seems
>> to grow.
>>
>> I set up a test case to try and prove this, I placed a button on a web > form
>> that ran the foloowing code.
>> string temp = "index";
>>
>> for(int i = 0; i < 1000000; i++)
>> {
>> string index = temp + i.ToString();
>> Session[index] = "This is a Test";
>> }
>>
>> I notices that the aspnet_state.ex e's Mem Usage and VM Size barely
>> grew
> yet
>> my W3WP process grew to the point that I had to stop my app (yes my
>> own
>> fault iterating 1M times).
>>
>> I thought the State Server actually stored the session data itself, it > would
>> seem from my example that this is not the case and that the memory

space
>> used is that of the W3WP.
>>
>> Does the State Server only act as a marchalling services pointing
>> requests
>> for Session info to the correct memory location? If this is the

case how
>> does it persist when an ASP.NET app is recycled.
>>
>> Is that portion of memory allocated to storing the Session held back
>> while
>> the ASP.NET app is recycled?
>>
>> I've been trying to find information on how the State Server works
>> internally but as yet have found nothing.
>>
>> TIA
>>
>> MattC
>>
>>
>>
>>
>
>



Nov 19 '05 #5
No, you were more than helpful, sometimes having someone else backup your
suspicons is as valuable as an answer.

Thanks a lot.

MattC

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uS******** ********@TK2MSF TNGP14.phx.gbl. ..
Matt:
I can't say I can see anything. Is the LosFormatter really necessary?
Your
storing the viewstate in the session i wouldn't expect it to need to be
serlialized...u nless the state server can't automatically serialize it
itself...even if it doesn't, not sure LosFormatter is the quickest (though
it very well could be, I'd check both issues).

I noticed that you aren't properly disposing of your StringWriter... but I
doubt that's your problem...

Anyways, atleast I gave you a couple more things to look at :) sorry I
coudlnt' be more help.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"MattC" <m@m.com> wrote in message
news:OH******** ******@TK2MSFTN GP14.phx.gbl...
Karl,

Last night I tried runing with server side viewstate off, indeed the

server
was fine, the processor was much less under pressure, and the memory
usage
was constant. Which means there must be a leak in my viewstate

persistance
code (below).
My problem is that I have a timesheet data entry page for the
application.
Users can make entries for each day, selecting an activity, each activity
requires a different set of boxes, this requires a postback. So they may
have 50/60 postbacks per session. All being persisted to the session.

private string NewViewState
{
get{ return "VIEWSTATE_ "; }
}

private string ViewStateKey
{
get{ return "__VIEWSTATE_KE Y"; }
}

private string UniqueViewState Key
{
get{ return NewViewState + Request.UserHos tAddress + "_" +
Guid.NewGuid(). ToString(); }
}

protected override void SavePageStateTo PersistenceMedi um(object

viewState)
{
try
{
if(Conquest.Con figurationData. ViewStateStorag e ==
ViewStateStorag e.Session)//if we are implementing our on server viewstate
{
string str = this.UniqueView StateKey;
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.S erialize(oStrin gWriter, viewState);//serialize

viewstate
into string writer
oLosFormatter = null;

Session[str] = oStringWriter.T oString(); //store in state server
oStringWriter = null;

RegisterHiddenF ield(ViewStateK ey, str);
RegisterHiddenF ield("__VIEWSTA TE", String.Empty);
}
else
{
base.SavePageSt ateToPersistenc eMedium(viewSta te);
}
}
catch(Exception e)
{
throw new
ConquestExcepti on("Performance Page.SavePageSt ateToPersistenc eMedium

Failed",
null, e);
}
}

protected override object LoadPageStateFr omPersistenceMe dium()
{
try
{
if(Conquest.Con figurationData. ViewStateStorag e ==
ViewStateStorag e.Session)//if we are implementing our on server viewstate
{
object viewstate = null;//return viewstate
string str = Request.Form[ViewStateKey];
LosFormatter oLosFormatter = new LosFormatter();

if (!str.StartsWit h(NewViewState) ) //check the viewstate exists
{
Conquest.Events .WriteToLog("Fa iled to locate VIEWSTATE KEY: '" +
str
+"'");
ViewStatePersis tanceFailure(st r);//failure
}
else//view state does exist
{
try
{
string tmp = Session[str].ToString();//get the serialize viewstate
from session
viewstate = oLosFormatter.D eserialize(tmp) ;//deserialize into

object
oLosFormatter = null;
}
catch(Exception e)//catch all and handle gracefully
{
Conquest.Events .WriteToLog("Fa iled to Load ViewState from " +
Conquest.Config urationData.Vie wStateStorage.T oString() +
" " +

ConquestExcepti on.HandleConque stException(e), System.Diagnost ics.EventLogEnt r
yType.Informati on);

ViewStatePersis tanceFailure(st r);//Response.Redire ct to homepage
}
}
//return what we got from deserialized viewstate
return viewstate;
}
else //use standard viewstate
{
return base.LoadPageSt ateFromPersiste nceMedium();
}
}
catch(Exception e)
{
throw new
ConquestExcepti on("Performance Page.LoadPageSt ateFromPersiste nceMedium
failed", null, e);
}
}
TIA

MattC
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
> Hey Matt,
> Check out http://www.thecodeproject.com/aspnet...nInternals.asp > it's just a starter...and there's no "part 2" as the author promises.
> Most
> of my research came from digging into the .net code with Reflector and
> getting an understanding of the internals.
>
> My initial suspicion is still that the GC simply isn't running, but
> it's
> possible that you do ahve a memory leak (managed or not)...you can
> check
> out
> http://blogs.msdn.com/akhune/archive...11/153734.aspx as a starting > point for this.
>
> Also, I wouldn't/couldn't say that those are the reasons your CPU is
> maxing
> out (certainly if you are looping 1million times per page hit, that might > be
> worth investigating too ;) ). I've certainly seen HTTP Compression take > a
> chunk out of CPU cycles...so simply try turning it off and see if it's any > better? Similarly, simply try to turn off the server-side viewstate
> and
> observe the effect. Your box certainly is old and I would simply suspect > that it'll be able to handle a certain load and no more...if you are
> trying
> to run an application where you feel the need to simulate 1million session > entries, you likely need more hardware...
>
> If the basic stuff doen't work (although I'm hoping turning off
> HttpCompression for testing will ease the cpu a lot), get a profiler
> and
> take a spin in your code. Ant's profiler is my prefered tool, and
> comes
> with a full 14 day trial:
> http://www.red-gate.com/code_profiling.htm
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "MattC" <m@m.com> wrote in message
> news:O8******** ******@TK2MSFTN GP15.phx.gbl...
>> Karl,
>>
>> Excellent, thanks for your response.
>>
>> 1.) Could you post some of the links for the articles you found.
>>
>> 2.) I am having to persist my viewstate into the session, overloading the >> SavePageStateTo PersistenceMedi um and
>> LoadPageStateTo PersistenceMedi um methods. Even after many many requests > the
>> W3WP process doesnt seem to go down and similarly my aspnet_state.ex e
> doesnt
>> seem to rise.
>>
>> Is there any way I can call to have a particular session insertion
>> serialized immediately?
>>
>> I suspect that as my CPU is now working to its maximum due to the fact
> that
>> it is having to do HTTP compression and serialize/deserialize plus search >> for session data it is having trouble finding the time to a.)
>> Serialize
>> to
>> the state server, b.) Garbage collect the temporary memory allocated
>> in
> the
>> worker process.
>>
>> My server is an old PIII 730 w/256MB Ram, W2K3 Server, IIS6.
>>
>> Would this fit your theory?
>>
>> Finally, can I created a method that is wired to the requesthandlers
>> complete event?
>>
>> TIA
>>
>> MattC
>>
>>
>> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
>> net>
>> wrote in message news:OY******** *****@TK2MSFTNG P15.phx.gbl...
>> > Matt:
>> > Thanks for asking, I learnt a lot by trying to find the answer. I
>> > strongly
>> > suspected that objects didn't immediatly stream to the state server
>> > when
>> > added - but instead were held in memory and only streamed to the state >> > servrer at a certain point. After doing some digging, I found out this > is
>> > what's happening. Here's a breakdown:
>> >
>> > -Session state is managed by an HttpModule called SessionStateMod ule
>> > -Items are only truly added to their stores during the
> ReleaseRequestS tate
>> > event, which as per msdn "Occurs after ASP.NET finishes executing
>> > all
>> > request handlers. This event causes state modules to save the
>> > current
>> > state
>> > data"
>> > -Depending on which type of storage you use, different things
>> > happen.
> In
>> > the case of state server, the session information is serilized into
> memory
>> > (asp.net) and then some stuff taht confused me happened (presumably the >> > actual storage to the state server)
>> >
>> >
>> > So, basically all those objects are stored in memory than serialized
>> > (in
>> > memory) and sent to state server. As you can see, a lot is
>> > happening
>> > in
>> > the
>> > asp.net memory (w3wp.exe). However, you'd think that after the page is >> > done
>> > loading that memory consumption would go back down. But it probably
>> > doesn't. This is because the garbage collector hasn't passed yet.
>> > Remember, memory won't be reclaimed until its needed. So if you lower >> > your
>> > loop so that it can finish, you'll see the memory go up and stay up.
> The
>> > memory goes up because initially all the items are help in-memory,
>> > it
>> > stays
>> > up because the GC hasn't passed yet.
>> >
>> > If you change ur code to:
>> > for (int i = 0; i < 800000; i++)
>> > {
>> > string index = "index" + i.ToString();
>> > Session[index] = "This is a Test";
>> > }
>> > GC.Collect();
>> > GC.WaitForPendi ngFinalizers();
>> > GC.Collect();
>> > GC.WaitForPendi ngFinalizers();
>> > GC.Collect();
>> > GC.WaitForPendi ngFinalizers();
>> >
>> > you'll hopefully see better results (but even then it isn't
>> > guaranteed)...d on't do anything for a minute or so and you should
>> > see
>> > it
>> > go
>> > back down :)
>> >
>> > Also, don't use task manager..instea d load up perfmon and go to
>> > .Net
>> > Memory, select "# of bytes in heap" and select the w3wp.exe
> process...will
>> > give you a much better idea :)
>> >
>> > Hope that helped,
>> > Karl
>> > --
>> > MY ASP.Net tutorials
>> > http://www.openmymind.net/
>> >
>> >
>> > "MattC" <m@m.com> wrote in message
>> > news:ux******** ******@TK2MSFTN GP10.phx.gbl...
>> >> I noticed when storing large amounts of information in the StateServer >> >> Service that this does not increase in size, the worker process itself >> > seems
>> >> to grow.
>> >>
>> >> I set up a test case to try and prove this, I placed a button on a web >> > form
>> >> that ran the foloowing code.
>> >> string temp = "index";
>> >>
>> >> for(int i = 0; i < 1000000; i++)
>> >> {
>> >> string index = temp + i.ToString();
>> >> Session[index] = "This is a Test";
>> >> }
>> >>
>> >> I notices that the aspnet_state.ex e's Mem Usage and VM Size barely
>> >> grew
>> > yet
>> >> my W3WP process grew to the point that I had to stop my app (yes my
>> >> own
>> >> fault iterating 1M times).
>> >>
>> >> I thought the State Server actually stored the session data itself, it >> > would
>> >> seem from my example that this is not the case and that the memory
> space
>> >> used is that of the W3WP.
>> >>
>> >> Does the State Server only act as a marchalling services pointing
>> >> requests
>> >> for Session info to the correct memory location? If this is the case > how
>> >> does it persist when an ASP.NET app is recycled.
>> >>
>> >> Is that portion of memory allocated to storing the Session held
>> >> back
>> >> while
>> >> the ASP.NET app is recycled?
>> >>
>> >> I've been trying to find information on how the State Server works
>> >> internally but as yet have found nothing.
>> >>
>> >> TIA
>> >>
>> >> MattC
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 19 '05 #6
I've placed a GC.Collect() call when users log out (after Session.Abandon )
to flush any rubbish left over from session viewstate storage, we'll see how
that fairs.

MattC

"MattC" <m@m.com> wrote in message
news:ux******** ******@TK2MSFTN GP10.phx.gbl...
I noticed when storing large amounts of information in the StateServer
Service that this does not increase in size, the worker process itself
seems to grow.

I set up a test case to try and prove this, I placed a button on a web
form that ran the foloowing code.
string temp = "index";

for(int i = 0; i < 1000000; i++)
{
string index = temp + i.ToString();
Session[index] = "This is a Test";
}

I notices that the aspnet_state.ex e's Mem Usage and VM Size barely grew
yet my W3WP process grew to the point that I had to stop my app (yes my
own fault iterating 1M times).

I thought the State Server actually stored the session data itself, it
would seem from my example that this is not the case and that the memory
space used is that of the W3WP.

Does the State Server only act as a marchalling services pointing requests
for Session info to the correct memory location? If this is the case how
does it persist when an ASP.NET app is recycled.

Is that portion of memory allocated to storing the Session held back while
the ASP.NET app is recycled?

I've been trying to find information on how the State Server works
internally but as yet have found nothing.

TIA

MattC

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4828
by: | last post by:
I am receiving an error each time i attempt to start the aspnet_state.exe program. aspnet_state: exiting with error code 0x80070427. I have verified that the registry keys are present and that aspnet is registered properly. Any ideas? Thanks Tom
3
1432
by: Eric Barr | last post by:
I was looking at the aspnet_state.exe (sessionState mode = SessionState) option for caching. I understand its benefits and limitations of using a service that is in memory, can sit on a remote machine. What i was curious about is how ASP.NET communicates with the state server. Only thing i've found is its TCP port 42424 (by default). Does it use remoting ? SOAP calls ? Proprietary ? I was hoping to be able to write a widget that...
2
1692
by: atef shehata | last post by:
hi all, i have a serious problem in the production site. i'm using win2k advanced and iis 5. i'm using oop mode to store the session data(aspnet_state server). my problem is : Sometimes , the users connected to our web application suffering from losing their data (stored in session object).
0
972
by: MattC | last post by:
Is there a namespace that provides a means of interfacing with the aspnet_state service to retrieve information used in perfmon? TIA M@tC
1
1398
by: llevi | last post by:
Hi there, My aspnet_state.exe service is failing to start due to an invalid argument. Does anyone know what arguments are required/valid for this service. I am running XP pro, .NET Framework v 1.1.4322. Thanks
2
2379
by: Mehdi | last post by:
Hi, Since I've installed asp.net 2 or (Visual Web Developer express edition), I am getting aspnet_state.exe Application error Memory...., while shutting down XP Pro (sp2). There is nothing in the event log which I think maybe OS cannot write to log file during shut-down. Does anyone have cure for this?
0
1025
by: Andrew Morton | last post by:
I have a serializable class in VB.NET which stores user data for a session. When the data is stored by aspnet_state.exe, is the data stored in, say, blocks of 4KB (cf. disk block sizes), or is only exactly enough space used for the data? (ASP.NET 1.1 on WS2003) I would like to know because it may or may not be worth modifying the class to minimize the data stored.
0
968
by: Mr. Monk Goo | last post by:
Is anyone aware of any way to attach a custom SerializationBinder to the BinaryFormatter used in retrieving session data from the aspnet_state.exe process (mode="StateServer", in the web.config)? I can't seem to find any obvious properties, and a quick google search proves rather fruitless. Without being able to assign a custom binder, I don't see how I can provide type redirection for retrieving old versions of a type in a new release...
8
1983
by: Grizlyk | last post by:
Hello I want to understand the exception habdling in C++ more, because i think no one can apply anything free (free - without remembering large unclear list of rules and exceptions from rules and exceptions from exception from rules) if he does not understand "why" the thing have done excactly as is. I know, some people do not agree with me at the point of "why".
0
8249
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2613
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1797
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1493
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.