[Mono-dev] Improving memory usage in /System.Web.SessionState/SessionSQLServerHandler.cs

2006-11-27 Thread Hubert FONGARNAND
Hi,

When using Npgsql, if you try to send (INSERT or UPDATE) a bytea (blob)
element without using "Prepare" it will be sent as a Escaped string...
This string is 4x bigger than the real bytea...
So : The memory usage on the ASP.NET server is enormous when the blob is
more than 1MB... and the network traffic is enormous too!
(see
http://pgfoundry.org/tracker/index.php?func=detail&aid=1000458&group_id=1000140&atid=590)

If you want to avoid that you've to use Prepare before executing
ExecuteNonQuery, or ExecuteReader...
If you don't believe me use Ethereal (wireshark)

Here's a patch that add a cmd.Prepare allowing Npgsql sending data in
binary format!
This patch shouldn't change anything if you use other connector than
Npgsql.

Thanks to review it!

Hubert FONGARNAND




Index: mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs
===
--- mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs 
(révision 68495)
+++ mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs 
(copie de travail)
@@ -196,6 +196,7 @@
command.CommandText = selectCommand;
command.Parameters.Add (CreateParam (command, 
DbType.String, "SessionID", id));
command.Parameters.Add (CreateParam (command, 
DbType.DateTime, "Expires", DateTime.Now ));
+   command.Prepare();
return command.ExecuteReader ();
}
 
@@ -253,7 +254,7 @@
   
session.StaticObjects.ToByteArray ()));
param.Add (CreateParam (command, DbType.Binary, 
"SessionData",
   
session.SessionDictionary.ToByteArray ()));
-
+   command.Prepare();
command.ExecuteNonQuery ();
}
 
@@ -287,6 +288,7 @@
param.Add (CreateParam (command, DbType.Int32, 
"Timeout", timeout));
param.Add (CreateParam (command, DbType.Binary, 
"SessionData",

dict.ToByteArray ()));
+   command.Prepare();
 
command.ExecuteNonQuery ();
}



___
Ce message et les �ventuels documents joints peuvent contenir des informations 
confidentielles.
Au cas o� il ne vous serait pas destin�, nous vous remercions de bien vouloir 
le supprimer et en aviser imm�diatement l'exp�diteur. Toute utilisation de ce 
message non conforme � sa destination, toute diffusion ou publication, totale 
ou partielle et quel qu'en soit le moyen est formellement interdite.
Les communications sur internet n'�tant pas s�curis�es, l'int�grit� de ce 
message n'est pas assur�e et la soci�t� �mettrice ne peut �tre tenue pour 
responsable de son contenu.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Improving memory usage in /System.Web.SessionState/SessionSQLServerHandler.cs

2006-11-28 Thread Hubert FONGARNAND
Could someone commit this patch?
Thanks

Le lundi 27 novembre 2006 à 12:17 +0100, Hubert FONGARNAND a écrit :

> Hi,
> 
> When using Npgsql, if you try to send (INSERT or UPDATE) a bytea
> (blob) element without using "Prepare" it will be sent as a Escaped
> string... This string is 4x bigger than the real bytea...
> So : The memory usage on the ASP.NET server is enormous when the blob
> is more than 1MB... and the network traffic is enormous too!
> (see
> http://pgfoundry.org/tracker/index.php?func=detail&aid=1000458&group_id=1000140&atid=590)
> 
> If you want to avoid that you've to use Prepare before executing
> ExecuteNonQuery, or ExecuteReader...
> If you don't believe me use Ethereal (wireshark)
> 
> Here's a patch that add a cmd.Prepare allowing Npgsql sending data in
> binary format!
> This patch shouldn't change anything if you use other connector than
> Npgsql.
> 
> Thanks to review it!
> 
> Hubert FONGARNAND
> 
> 
> 
> 
> Index: mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs
> ===
> --- mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs   
>   (révision 68495)
> +++ mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs   
>   (copie de travail)
> @@ -196,6 +196,7 @@
> command.CommandText = selectCommand;
> command.Parameters.Add (CreateParam (command, 
> DbType.String, "SessionID", id));
> command.Parameters.Add (CreateParam (command, 
> DbType.DateTime, "Expires", DateTime.Now ));
> +   command.Prepare();
> return command.ExecuteReader ();
> }
>  
> @@ -253,7 +254,7 @@
>
> session.StaticObjects.ToByteArray ()));
> param.Add (CreateParam (command, DbType.Binary, 
> "SessionData",
>
> session.SessionDictionary.ToByteArray ()));
> -
> +   command.Prepare();
> command.ExecuteNonQuery ();
> }
>  
> @@ -287,6 +288,7 @@
> param.Add (CreateParam (command, DbType.Int32, 
> "Timeout", timeout));
> param.Add (CreateParam (command, DbType.Binary, 
> "SessionData",
> 
> dict.ToByteArray ()));
> +   command.Prepare();
>  
> command.ExecuteNonQuery ();
> }
> 
> 
> 
> ___
> Ce message et les ventuels documents joints peuvent contenir des
> informations confidentielles.
> Au cas o䵲 il ne vous serait pas destin, nous vous remercions de bien
> vouloir le supprimer et en aviser imm洸diatement l'expditeur. Toute
> utilisation de ce message non conforme ⭁ sa destination, toute
> diffusion ou publication, totale ou partielle et quel qu'en soit le
> moyen est formellement interdite.
> Les communications sur internet n'tant pas s牌curises, l'intߜgrit de
> ce message n'est pas assurŨe et la socit㵵 mettrice ne peut 攮tre
> tenue pour responsable de son contenu. 
> 
> ___
> Mono-devel-list mailing list
> Mono-devel-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
___
Ce message et les �ventuels documents joints peuvent contenir des informations 
confidentielles.
Au cas o� il ne vous serait pas destin�, nous vous remercions de bien vouloir 
le supprimer et en aviser imm�diatement l'exp�diteur. Toute utilisation de ce 
message non conforme � sa destination, toute diffusion ou publication, totale 
ou partielle et quel qu'en soit le moyen est formellement interdite.
Les communications sur internet n'�tant pas s�curis�es, l'int�grit� de ce 
message n'est pas assur�e et la soci�t� �mettrice ne peut �tre tenue pour 
responsable de son contenu.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Improving memory usage in /System.Web.SessionState/SessionSQLServerHandler.cs

2006-11-28 Thread Robert Jordan
Hi Hubert,

Hubert FONGARNAND wrote:
> Could someone commit this patch?

Let me check it first against another DB providers.

Robert

> Thanks
> 
> Le lundi 27 novembre 2006 à 12:17 +0100, Hubert FONGARNAND a écrit :
> 
>> Hi,
>>
>> When using Npgsql, if you try to send (INSERT or UPDATE) a bytea
>> (blob) element without using "Prepare" it will be sent as a Escaped
>> string... This string is 4x bigger than the real bytea...
>> So : The memory usage on the ASP.NET server is enormous when the blob
>> is more than 1MB... and the network traffic is enormous too!
>> (see
>> http://pgfoundry.org/tracker/index.php?func=detail&aid=1000458&group_id=1000140&atid=590)
>>
>> If you want to avoid that you've to use Prepare before executing
>> ExecuteNonQuery, or ExecuteReader...
>> If you don't believe me use Ethereal (wireshark)
>>
>> Here's a patch that add a cmd.Prepare allowing Npgsql sending data in
>> binary format!
>> This patch shouldn't change anything if you use other connector than
>> Npgsql.
>>
>> Thanks to review it!
>>
>> Hubert FONGARNAND
>>
>>
>>
>>
>> Index: 
>> mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs
>> ===
>> --- mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs  
>>(révision 68495)
>> +++ mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs  
>>(copie de travail)
>> @@ -196,6 +196,7 @@
>> command.CommandText = selectCommand;
>> command.Parameters.Add (CreateParam (command, 
>> DbType.String, "SessionID", id));
>> command.Parameters.Add (CreateParam (command, 
>> DbType.DateTime, "Expires", DateTime.Now ));
>> +   command.Prepare();
>> return command.ExecuteReader ();
>> }
>>  
>> @@ -253,7 +254,7 @@
>>
>> session.StaticObjects.ToByteArray ()));
>> param.Add (CreateParam (command, DbType.Binary, 
>> "SessionData",
>>
>> session.SessionDictionary.ToByteArray ()));
>> -
>> +   command.Prepare();
>> command.ExecuteNonQuery ();
>> }
>>  
>> @@ -287,6 +288,7 @@
>> param.Add (CreateParam (command, DbType.Int32, 
>> "Timeout", timeout));
>> param.Add (CreateParam (command, DbType.Binary, 
>> "SessionData",
>> 
>> dict.ToByteArray ()));
>> +   command.Prepare();
>>  
>> command.ExecuteNonQuery ();
>> }
>>
>>
>>
>> ___
>> Ce message et les ventuels documents joints peuvent contenir des
>> informations confidentielles.
>> Au cas o䵲 il ne vous serait pas destin, nous vous remercions de bien
>> vouloir le supprimer et en aviser imm洸diatement l'expditeur. Toute
>> utilisation de ce message non conforme ⭁ sa destination, toute
>> diffusion ou publication, totale ou partielle et quel qu'en soit le
>> moyen est formellement interdite.
>> Les communications sur internet n'tant pas s牌curises, l'intߜgrit de
>> ce message n'est pas assurŨe et la socit㵵 mettrice ne peut 攮tre
>> tenue pour responsable de son contenu. 
>>
>> ___
>> Mono-devel-list mailing list
>> Mono-devel-list@lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> ___
> Ce message et les �ventuels documents joints peuvent contenir des 
> informations confidentielles.
> Au cas o� il ne vous serait pas destin�, nous vous remercions de bien vouloir 
> le supprimer et en aviser imm�diatement l'exp�diteur. Toute utilisation de ce 
> message non conforme � sa destination, toute diffusion ou publication, totale 
> ou partielle et quel qu'en soit le moyen est formellement interdite.
> Les communications sur internet n'�tant pas s�curis�es, l'int�grit� de ce 
> message n'est pas assur�e et la soci�t� �mettrice ne peut �tre tenue pour 
> responsable de son contenu.
> 
> 
> 
> 
> 
> ___
> Mono-devel-list mailing list
> Mono-devel-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list