Hi am trying to store very large data say 22 MB of data in a session variable, but I dont think it is being stored into the variable. Can I know how much data can we store in a session variable?
I this is something very large, can you please let me know how can I store such huge data?
Use when you are storing short-lived information that is specific to an individual session and security is an issue. Do not store large quantities of information in session state. Be aware that a session-state object will be
created and maintained for the lifetime of every session in your application. In applications hosting many users, this can occupy significant server resources and affect scalability.
It's important to realize that when you are storing something this large within the Session that it can affect the performance of your application. Session are created on at a user-level, so it could be possible if you had 20+ users each with 22MB of data
within their Sessions that your application might not be able to scale (or even handle such data). This can eventually bottleneck your application :
(Size of Session) * (Number of Users) < (Total Available Resources / Memory)
The Session should be used as little as possible and really shouldn't be used to store such large amounts of data. You should consider a more persistent form of storage such as a database if you really must store such large data.
Thanks for the reply! Is there any type of storage other than the database? I tried using the databse, even that is making the loading of data into kendo grid slow.
Are you sure that you actually need all of that data at once? I would recommend implementing some method of actually paging your data into more managable chucks so that the user can page back and forth through all of your data (instead of pulling it
all at once) within your Grid. Another important thing to consider would be to only grab the actual fields that you need and not your entire objects.
I'm not sure exactly what kind of data you are storing, but it's likely that you don't need all 22MB of it within a single request.
Basically this is a tradeoff and each session variable you'll add should "buy"a well identified advantage for the size you consume (ie it's best for small and very frequently used data, 22 Mb is really huge). To suggest another approach we would need to
understand how this data is used. Keep also in mind that session is scoped to each user session (ie if you have 100 users you would need to have 100 x 22 Mb ?). Is this an attempt to speed up db access or to keep changes somewhere before comitting them or
whatever ?
Yeah, I can do lazy loading or something like that...but do you know how can I implement that in kendo grid using vb.net. And the data type is of JSON objects, so I need to serialize then load on client side.
More likely this is not a db problem. Check the size of your HTML page. Time your code. You'll likely see that the issue is not the time needed to retrieve the data from the db but the time needed to transfer a huge HTML page to the browser and have it rendered...
Uusally in a web app you avoid to render too much rows in which the user would have anyway a hard time to find those he really needS. Instead you let him to tell which rows he wants and show him just those rows (you could start with drop down filters or
whatever).
According to the KendoUI documentation, you should be able to set the
serverPaging property on your Grid (or the DataSource that populates it) to "true" :
<script>
var dataSource = new kendo.data.DataSource({
transport: {
/* transport configuration */
},
serverPaging: true,
schema: {
total: "total" // total is returned in the "total" field of the response
}
});
</script>
This will pass several attributes back to your code-behind :
page - the page of data item to return (1 means the first page)
pageSize - the number of items to return
skip - how many data items to skip
take - the number of data items to return (the same as pageSize)
You can use these along with LINQ to properly page your data :
'Get the number of elements to skip'
Dim skip = TryCast(Request("skip"), Integer)
Dim take = TryCast(Request("take"), Integer)
'Get your values'
Dim pagedResult = dbContext.YourWidgets.Skip(skip).Take(take).ToList()
This is all a very basic example of how you might go about implementing paging within your Grid.
I did set the serverrPaging property to true on client side...but i didnot understand how to declare and pass the attributes like page, skip, take etc.
The Grid itself should automatically pass those up during the Request I believe (ie any PostBacks or AJAX calls that are made through the Grid) and you should be able to pull them out of the code-behind using the code I provided earlier :
'Get the number of elements to skip'Dim skip =TryCast(Request("skip"),Integer)Dim take =TryCast(Request("take"),Integer)
Thank you....I tried this...and it is a bit faster..but is there anyway that we can reproduce the skipped rows?? Because I have skipped lot of records...
Member
60 Points
172 Posts
capacity of a session variable
Apr 30, 2014 04:28 PM|aktzc|LINK
Hi am trying to store very large data say 22 MB of data in a session variable, but I dont think it is being stored into the variable. Can I know how much data can we store in a session variable?
I this is something very large, can you please let me know how can I store such huge data?
All-Star
114593 Points
18503 Posts
MVP
Re: capacity of a session variable
Apr 30, 2014 04:40 PM|Rion Williams|LINK
You are correct data can be stored in the Session, even large amounts of data, but it isn't recommend as per the ASP.NET State Management Recommendations :
Use when you are storing short-lived information that is specific to an individual session and security is an issue. Do not store large quantities of information in session state. Be aware that a session-state object will be created and maintained for the lifetime of every session in your application. In applications hosting many users, this can occupy significant server resources and affect scalability.
It's important to realize that when you are storing something this large within the Session that it can affect the performance of your application. Session are created on at a user-level, so it could be possible if you had 20+ users each with 22MB of data within their Sessions that your application might not be able to scale (or even handle such data). This can eventually bottleneck your application :
The Session should be used as little as possible and really shouldn't be used to store such large amounts of data. You should consider a more persistent form of storage such as a database if you really must store such large data.
Member
60 Points
172 Posts
Re: capacity of a session variable
Apr 30, 2014 04:44 PM|aktzc|LINK
Hi Rion,
Thanks for the reply! Is there any type of storage other than the database? I tried using the databse, even that is making the loading of data into kendo grid slow.
All-Star
114593 Points
18503 Posts
MVP
Re: capacity of a session variable
Apr 30, 2014 04:46 PM|Rion Williams|LINK
22MB is a lot of data.
Are you sure that you actually need all of that data at once? I would recommend implementing some method of actually paging your data into more managable chucks so that the user can page back and forth through all of your data (instead of pulling it all at once) within your Grid. Another important thing to consider would be to only grab the actual fields that you need and not your entire objects.
I'm not sure exactly what kind of data you are storing, but it's likely that you don't need all 22MB of it within a single request.
All-Star
48340 Points
18013 Posts
Re: capacity of a session variable
Apr 30, 2014 04:49 PM|PatriceSc|LINK
Hi,
Basically this is a tradeoff and each session variable you'll add should "buy"a well identified advantage for the size you consume (ie it's best for small and very frequently used data, 22 Mb is really huge). To suggest another approach we would need to understand how this data is used. Keep also in mind that session is scoped to each user session (ie if you have 100 users you would need to have 100 x 22 Mb ?). Is this an attempt to speed up db access or to keep changes somewhere before comitting them or whatever ?
Member
60 Points
172 Posts
Re: capacity of a session variable
Apr 30, 2014 04:49 PM|aktzc|LINK
Yeah, I can do lazy loading or something like that...but do you know how can I implement that in kendo grid using vb.net. And the data type is of JSON objects, so I need to serialize then load on client side.
All-Star
48340 Points
18013 Posts
Re: capacity of a session variable
Apr 30, 2014 04:59 PM|PatriceSc|LINK
More likely this is not a db problem. Check the size of your HTML page. Time your code. You'll likely see that the issue is not the time needed to retrieve the data from the db but the time needed to transfer a huge HTML page to the browser and have it rendered...
Uusally in a web app you avoid to render too much rows in which the user would have anyway a hard time to find those he really needS. Instead you let him to tell which rows he wants and show him just those rows (you could start with drop down filters or whatever).
All-Star
114593 Points
18503 Posts
MVP
Re: capacity of a session variable
Apr 30, 2014 05:08 PM|Rion Williams|LINK
According to the KendoUI documentation, you should be able to set the serverPaging property on your Grid (or the DataSource that populates it) to "true" :
This will pass several attributes back to your code-behind :
You can use these along with LINQ to properly page your data :
This is all a very basic example of how you might go about implementing paging within your Grid.
Member
60 Points
172 Posts
Re: capacity of a session variable
Apr 30, 2014 06:10 PM|aktzc|LINK
I did set the serverrPaging property to true on client side...but i didnot understand how to declare and pass the attributes like page, skip, take etc.
All-Star
114593 Points
18503 Posts
MVP
Re: capacity of a session variable
May 01, 2014 08:15 AM|Rion Williams|LINK
The Grid itself should automatically pass those up during the Request I believe (ie any PostBacks or AJAX calls that are made through the Grid) and you should be able to pull them out of the code-behind using the code I provided earlier :
Member
60 Points
172 Posts
Re: capacity of a session variable
May 01, 2014 10:11 AM|aktzc|LINK
Thank you....I tried this...and it is a bit faster..but is there anyway that we can reproduce the skipped rows?? Because I have skipped lot of records...