If I am running 1 asp.net application on 1 computer server running IIS...... how many times does the application_start get fired?
does it get fired only the very first time a user starts the application? and then it does not get fired for every other users connecting to my aplication? (this is what I beleive)
or is it that it gets fired every time a user starts a connection to my app-lication?
in the first senario.... I think then the Session_start event would fire every time a new user connects to my application hence: start a new session,,, but not the application_start which only gets fired once on the very first conection from the very first
user connecting.
so here is the senario that I am viewing: I want to load one big object at the very start of the application (only once). that big object loads lots and lot of data from a data base into various Strongly typed collections. So I want that 1 instance of that
big object in memory all the time.
Is this feasable? Is there only going to be 1 instance of that big object in memory? in the application instance? the only one that would exist? Correct?
So, then I would want every user that connect to my application to get access to its very own instance of that big object so (a copy of it instead of a reference); I would implement inside the Session_start event a system where every time a new user connects
it fires the session_start event which creates a new big oject by copying the big object variable held in the application instance into a new instance held in either the Sesion or the profile for that user.
That way each user would have its own profile or session dedicated to them (as it is in asp.net) and this user's session or profile would hold "not a reference to" but its very own copy of the original big object (which is not so big after all) and each
user could work with its own version of the big object which would then be a different object for each user (obviously).
Now the big question is: Does anybody see anyproblem with this? I have read somewhere that asp.net implements some kind of locking mechanism when it accesses the application object or when in accesses what is stored in its dictionary. I also read that this
locking mechanism can affect the performances of you web application.
So I think that what is important is that I do not want my application to constantly make database requests to pull information and that is why I implement this load once mechanism in the application_start and hope it gets called only once.
***this is where I really need advice***** Then I dont think it would be too demanding for my app to access the information stored inside the application instance's dictionary and retreive the big object each and every time and only when a new user starts
a session.
You are right in you assumptions on how the events work and when they fire.
When creating your "big" object, consider
putting it in the cache instead of an application variable as it can then be disposed easier if your system gets low on memory. Does each user then really need a copy of this object? Will they be manipulating it?
As for storing data in the session (as opposed to retrieving it from the database) then it really depends on the application, the server and what you are storing in it. You may just have to try both methods to see which works best for your particular case.
About your suggestion of putting my big object in the cache.... you mean as oppose to the application object. Meaning as oposed to storing it in the application("bigoject") I would do the same but with the cache.
Is the cache accessible globally in the same way as the application object is? so that I could have only 1 instance of that original big object in the cahce and every user upon initiating a new sesion would copy (make a copy of) the big object instance to
then store it in their own session or profile. That would instantly take care of the locking mechanism problem involved in dealing with the application obkect or accessing what is being stored in its dictionary
as per your second answer (or question). yes each user needs its own copy of the big object to manipulate it.
so im thinking in the application_start having something like:
dim BigO as new bigobject
BigO.LoadAllMyData ''''this is where it loads all the data from the Database into the strongly typed collections
Cache("BigObject") = BigO
And every time a new user initiates a new session in the Session_start event i would have something like that:
dim MyOwnBigO as new BigObject
MyOwnBigO = cache("bigobject")
session("MyOwnBigObject") = MyOwnBigO
and the the user could manipulate his own version of the Big object by alling it in his own session
bcweed966
Member
261 Points
893 Posts
The application instance
Jun 18, 2007 06:04 PM|LINK
This is a very simple question:
If I am running 1 asp.net application on 1 computer server running IIS...... how many times does the application_start get fired?
does it get fired only the very first time a user starts the application? and then it does not get fired for every other users connecting to my aplication? (this is what I beleive)
or is it that it gets fired every time a user starts a connection to my app-lication?
in the first senario.... I think then the Session_start event would fire every time a new user connects to my application hence: start a new session,,, but not the application_start which only gets fired once on the very first conection from the very first user connecting.
so here is the senario that I am viewing: I want to load one big object at the very start of the application (only once). that big object loads lots and lot of data from a data base into various Strongly typed collections. So I want that 1 instance of that big object in memory all the time.
Is this feasable? Is there only going to be 1 instance of that big object in memory? in the application instance? the only one that would exist? Correct?
So, then I would want every user that connect to my application to get access to its very own instance of that big object so (a copy of it instead of a reference); I would implement inside the Session_start event a system where every time a new user connects it fires the session_start event which creates a new big oject by copying the big object variable held in the application instance into a new instance held in either the Sesion or the profile for that user.
That way each user would have its own profile or session dedicated to them (as it is in asp.net) and this user's session or profile would hold "not a reference to" but its very own copy of the original big object (which is not so big after all) and each user could work with its own version of the big object which would then be a different object for each user (obviously).
Now the big question is: Does anybody see anyproblem with this? I have read somewhere that asp.net implements some kind of locking mechanism when it accesses the application object or when in accesses what is stored in its dictionary. I also read that this locking mechanism can affect the performances of you web application.
So I think that what is important is that I do not want my application to constantly make database requests to pull information and that is why I implement this load once mechanism in the application_start and hope it gets called only once.
***this is where I really need advice***** Then I dont think it would be too demanding for my app to access the information stored inside the application instance's dictionary and retreive the big object each and every time and only when a new user starts a session.
thank you for your advice
Marc
ca8msm
Star
12439 Points
2153 Posts
Re: The application instance
Jun 18, 2007 08:41 PM|LINK
You are right in you assumptions on how the events work and when they fire.
When creating your "big" object, consider putting it in the cache instead of an application variable as it can then be disposed easier if your system gets low on memory. Does each user then really need a copy of this object? Will they be manipulating it?
As for storing data in the session (as opposed to retrieving it from the database) then it really depends on the application, the server and what you are storing in it. You may just have to try both methods to see which works best for your particular case.
Website Design Darlington - http://lessthandot.com -
http://aspnetlibrary.com
bcweed966
Member
261 Points
893 Posts
Re: The application instance
Jun 18, 2007 09:02 PM|LINK
About your suggestion of putting my big object in the cache.... you mean as oppose to the application object. Meaning as oposed to storing it in the application("bigoject") I would do the same but with the cache.
Is the cache accessible globally in the same way as the application object is? so that I could have only 1 instance of that original big object in the cahce and every user upon initiating a new sesion would copy (make a copy of) the big object instance to then store it in their own session or profile. That would instantly take care of the locking mechanism problem involved in dealing with the application obkect or accessing what is being stored in its dictionary
as per your second answer (or question). yes each user needs its own copy of the big object to manipulate it.
so im thinking in the application_start having something like:
dim BigO as new bigobject
BigO.LoadAllMyData ''''this is where it loads all the data from the Database into the strongly typed collections
Cache("BigObject") = BigO
And every time a new user initiates a new session in the Session_start event i would have something like that:
dim MyOwnBigO as new BigObject
MyOwnBigO = cache("bigobject")
session("MyOwnBigObject") = MyOwnBigO
and the the user could manipulate his own version of the Big object by alling it in his own session
MyOwnBigO = session("MyOwnBigObject")
Thanks
ca8msm
Star
12439 Points
2153 Posts
Re: The application instance
Jun 18, 2007 09:12 PM|LINK
Yes, you're correct in your assumptions about the cache and the rest looks fine to me.
Website Design Darlington - http://lessthandot.com -
http://aspnetlibrary.com