Skip to main content

NpgsqlCommand optimizations and usage tip


Hi, all!

Some days ago, I fixed a slow performance problem with Npgsql when calling functions. The problem was that Npgsql was doing a lot of expensive checks (in fact, 3) to verify parameter information and return type. The solution was to cache those checks so that new calls to the same function don't need to pass through the same checks again.

In order to not have problems with outdated caches and etc and after talking to Josh on gmail, I decided to make the cache local and it would be invalidated as soon as the command text is changed.

This semantics lead me to write this blog to share the idea that you can get a big performance improvement if you "cache" your NpgsqlCommands which will be used with function calls. This way, instead of creating and releasing the command object after its usage, you can create all your NpgsqlCommand objects associated to function calls and reuse them as needed. This way you pay for the costly checks only once.

I hope this tip can help people to get some performance gains from this fix. :)

Comments

Anonymous said…
wow gold | world of warcraft gold | wow power leveling | Cheap WoW Gold | Cheapest WoW Gold | Buy Cheap WoW Gold | cheapest wow gold | Buy WoW Gold | sell wow gold | WoW Accounts | wow accounts for sale | Buy WoW Power Leveling | Wow Honor Leveling | WoW profession leveling | WoW Reputation Leveling | WoW CD Key | WOW EU Gold | Cheap WoW Gold | wow gold for sale | Cheap WoW Power Leveling | WoW EU Accounts | world of warcraft accounts for sale | WoW EU CD Key | Lineage 2 Adena | Buy L2 Adena | Lineage 2 Adena for sale | Lineage 2 Accounts | Lineage 2 Power Leveling | Lineage 2 CD Key | Warhammer gold | Buy Warhammer Gold | Warhammer US Gold | Warhammer Power leveling | Warhammer CD Key | Warhammer Accounts | Warhammer EU Gold | Buy Cheap Warhammer Gold | WAR EU Gold | Buy Warhammer Power Leveling | Warhammer Online Accounts | Warhammer EU CD key | Aion gold | fast delivery Aion Gold | Aion Accounts | Aion Power Leveling | Aion CD Key | runes of magic gold | cheap runes of magic gold | runes of magic accounts | runes of magic power leveling | runes of magic cd key | runes of magic online gold | buy runes of magic eu gold | wow cheats | rom power leveling | runes of magic eu accounts for sale | cheap runes of magic cd key | FFXI Gil | Cheap FFXI Gil | Final Fantasy XI Gil | FFXI Power Leveling | FFXI CD Key | LoTRO Gold | Cheap Lotro Gold | LoTRO US Gold | LoTRO Accounts | Lotro accounts for sale | LoTRO Power Leveling | LoTRO CD Key | LoTRO EU Gold | Lord of the Rings Gold | LoTRO EU Accounts | Lotro Leveling | Lord of the Rings CD Key | Age of Conan gold | AoC US Gold | Cheap AoC Gold | Age of Conan Accounts | Age of Conan Power Leveling | Age of Conan Crafting Leveling | Age of Conan CD Key | Age of Conan EU Gold | Age of Conan Gold For Sale | Age of Conan Leveling | Age of Conan Accounts For Sale | AoC CD Key | The Chronicles of Spellborn Gold | Chronicles of Spellborn Gold | Chronicles of Spellborn Accounts | Chronicles of Spellborn Power Leveling | Chronicles of Spellborn CD key | atlantica gold | buy atlantica gold | atlantica power leveling | atlantica cd key | darkfall gold | buy darkfall gold | darkfall accounts | darkfall power leveling | darkfall cd key | silkroad gold | silkroad online gold | cheap silkroad gold | silkroad power leveling | Maple Story Mesos | Buy Maplestory Mesos | Maple Story Power Leveling | EVE ISK | EVE Online ISK | Cheap EVE ISK | EVE Power Leveling | EVE CD Key | EverQuest 2 Platinum | EverQuest 2 Gold | EQ2 Gold | EverQuest 2 Accounts | EverQuest 2 Power Leveling | EverQuest 2 CD Key
Anonymous said…
I did not know how to get strong, someone told me that you must have last chaos gold. He gave me some lastchaos gold, he said that I could buy last chaos gold, but I did not have money, then I played it all my spare time. From then on, I got some lastchaos money, if I did not continue to play it, I can sell cheap lastchaos gold to anyone who want.Once I played 4story, I did not know how to get strong, someone told me that you must have 4story Luna. He gave me some 4story Gold, he said that I could buy 4story Luna, but I did not have money, then I played it all my spare time. From then on, I got some 4story money, if I did not continue to play it, I can sell cheap 4story Luna to anyone who want.
Anonymous said…
Making Sho Online Mun is the old question : Honestly there is no fast way to make lots of Sho Mun . Sadly enough a lot of the people that all of a sudden come to with millions of Sho Online gold almost overnight probably duped . Although there are a lot of ways to make lots of Sho gold here I will tell you all of the ways that I know and what I do to buy Sho Online gold.

As a new player , you may need some game guides or information to enhance yourself.
angels gold is one of the hardest theme for every class at the beginning . You must have a good way to manage your angels online gold.If yor are a lucky guy ,you can earn so many buy angels goldby yourself.If you need , you cancheap angels online goldat our website . Go to the related page and check the detailed information . Once you have any question , you can connect our customer service at any time .
Ericwipe287 said…
I also have same slow performing problem Thanks for giving the solution. Keep it up!

dentists edinburgh

Popular posts from this blog

UUID datatype and COPY IN/OUT support added to cvs

Hi all! It was just added support to uuid datatype in cvs head. This type will be available in next Postgresql release 8.3. Thanks to David Bachmann for his patch! You can get more info about this patch in this mailing list post . Also was added support for copy in and copy out operations. Now, users can provide streams which can be copied directly to and from Postgresql tables! Thanks to Kalle Hallivuori for providing a patch! Thanks to Truviso for giving support to Kalle. More info about that including a demo and ready to use compiled Npgsql.dll versions can be found here . That's it! As soon as we get more features added, I will post info about them here. Stay tuned! :)

Npgsql Tips: Using " in (...)" queries with parameters list and "any" operator

Hi, all! We have received some users questions about how to send a list of values to be used in queries using the "in" operator. Something like: select foo, bar from table where foo in (blah1, blah2, blah3); Npgsql supports array-like parameter values and the first idea to have this working would try to use it directly: NpgsqlCommand command = new NpgsqlCommand("select * from tablee where field_serial in (:parameterlist)", conn); ArrayList l = new ArrayList(); l.Add(5); l.Add(6); command.Parameters.Add(new NpgsqlParameter("parameterlist", NpgsqlDbType.Array | NpgsqlDbType.Integer)); command.Parameters[0].Value = l.ToArray(); NpgsqlDataReader dr = command.ExecuteReader(); but unfortunately this won't work as expected. Npgsql will send a query like this: select * from tablee where field_serial in ((array[5,6])::int4[]) And Postgresql will complain with the followin

Stream seek error

Hi all! Since Npgsql RC1, we started to receive some error reports about problems when closing connections. The typical stack trace looked like this: System.NotSupportedException : This stream does not support seek operations. at System.Net.Sockets.NetworkStream.Seek(Int64 offset, SeekOrigin origin) at System.IO.BufferedStream.FlushRead() at System.IO.BufferedStream.WriteByte(Byte value) − at Npgsql.NpgsqlQuery.WriteToStream(Stream outputStream) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlQuery.cs:line 62 − at Npgsql.NpgsqlReadyState.QueryEnum(NpgsqlConnector context, NpgsqlCommand command) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlReadyState.cs:line 64 − at Npgsql.NpgsqlConnector.ReleasePlansPortals() in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlConnector.cs:line 373 − at Npgsql.NpgsqlConnectorPool.UngetPooledConnector(NpgsqlConnection Connection, NpgsqlConnector Connector) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlConnectorPool.cs:line 541 − at Npgsql.NpgsqlConnectorPool.ReleasePooledConnector(NpgsqlConn