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

Hubert FONGARNAND informatique.internet at fiducial.fr
Mon Nov 27 06:17:58 EST 2006


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061127/ab98fd98/attachment.html 


More information about the Mono-devel-list mailing list