Just another serialization (not only) optimization

Posts   
 
    
lubo278
User
Posts: 32
Joined: 10-Apr-2007
# Posted on: 10-Apr-2007 11:36:11   

Just to be short, I would like to give You few (mostly general) tips on making using LLBL with serialization faster.

Problem: If you use LLBL in ASP.NET you may need to store some whole entity (even collection) in session state. If you make CPU/memory analysis, serialization of this data is probably very significant in Your project (of course if you need to use SessionState or SqlState server).

Solution 1: Do not store whole entity in session. Persist entity into database and store only ID to this entity. - this solution has obvious problems with dealing with temporary rows in database (deleting old records, database size, fragmentation, ...)

Avoiding solution 1: - when you first created your LLBL project, you probably enabled all entities, all relations (just to be sure to find them if you need them). Always try to keep your LLBL project as thin as possible. Hiding m:n relations (relations like SexCollectionViaUser) which are probably not used anyway alone could save you up to 30% of the serialized entity size. - hide not used fields. You could use some custom binary fields i.e. for data replication etc. Hide them if you don't need them in your code. LLBL always fetch whole data row.

PS: I hope LLBL 2.1 new Fast Serialization will speed up session state serialization even more. It is very easy to make own session state engine, which serialize data with custom serializer. Serializing with binary serializer to plain files is indeed faster then using asp.net session state server (though I need to check scalability). Custom session state has another advantage. You do not have to deserialize whole session state for one entity (as native asp session state server does). If I have 10 big entities in session, I choose only one I need in this postback.

Even if you do not need to serialize LLBL entities, keeping llbl project as small as possible will also lower memory consumption.

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 10-Apr-2007 14:42:10   

Hi,

thanks for the hints !

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39926
Joined: 17-Aug-2003
# Posted on: 17-Apr-2007 11:38:20   

storing data in the session object doesn't use serialization at all, it only uses serialization when you store data in the viewstate as asp.net then serializes/deserializes the data.

v2.1 indeed has fast serialization build in but only for adapter for now.

Frans Bouma | Lead developer LLBLGen Pro
lubo278
User
Posts: 32
Joined: 10-Apr-2007
# Posted on: 17-Apr-2007 12:08:59   

ASP.NET has 3 types of SessionState. InProc - stored in working process - does not use serialization, but has limit of aprox. 600 MB for stored data per working process (fast, little scalable). StateServer - uses special State server - uses serialization which could be really slow SqlServer - uses SQL Server - almost same as SessionState but slower.

If you have small app. you really can use InProc. But if you need to store big data (and/or have many users) 600 MB will be not enough in short time. The same problem is for web farms and sharing session among multiple servers (InProc session state wont not work).